• 请不要在回答技术问题时复制粘贴 AI 生成的内容
changeTheGame
V2EX  ›  程序员

怎么加快推送数据的速度

  •  
  •   changeTheGame ·
    starsky1 · Dec 23, 2020 · 2382 views
    This topic created in 1970 days ago, the information mentioned may be changed or developed.

    大佬们,下午好。问个问题,我有 20 万数据要推送,现在每条数据推送需要 0.1 秒,一个小时只能推送 3 万 6 千条。有没有什么好办法能加快速度啊,现在这个速度,推送 20 万条,需要 6 个小时。

    接收方接口是用 webservice 写的,没法改了。我只能在自己的客户端进行修改,目前尝试过使用线程池创建 10 个线程推送,但是也只能一个小时推送 6 万条。

    10 replies    2020-12-23 16:48:47 +08:00
    shoaly
        1
    shoaly  
       Dec 23, 2020
    这个乘法好计算啊, 10 个 接着变成 100 个线程, 还不够就填 10 台机器, 变成 1000 个线程.
    通常这个时候上游该崩了
    unixeno
        2
    unixeno  
       Dec 23, 2020 via Android
    那就开 1000 个线程
    wysnylc
        3
    wysnylc  
       Dec 23, 2020
    无他,加机器加线程
    changeTheGame
        4
    changeTheGame  
    OP
       Dec 23, 2020
    我只有一台服务器。开 100 个线程,会不会把内存撑爆?我每推一次,会创建 10 个线程,然后关闭。频繁的创建 100 个线程,不好吧?
    iceneet
        5
    iceneet  
       Dec 23, 2020
    感觉只能加线程了 (前提上游接口没崩
    nimonew
        6
    nimonew  
       Dec 23, 2020
    @changeTheGame 线程池
    securityCoding
        7
    securityCoding  
       Dec 23, 2020
    1. 首先你需要跟业务方沟通,拿到业务方的 qps 上限,没有指标的优化没有任何意义 (指标)
    2. 压测你的代码,找出性能瓶颈优化掉 ,单线程不够改多线程,这时候你知道你的服务单点性能上限了,当然数据是压测出来的 (纵向拓展)
    3. 单点性能不够就多点 (横向拓展)
    4. 多点部署还不够就解耦,剥离消息生产跟消费(推送) (缓存 , 异步)

    总体思路就是: 纵向 /横向拓展 , 缓存 , 异步
    limuyan44
        8
    limuyan44  
       Dec 23, 2020
    你为什么推一次创建 10 个线程呢,是创建 10 个线程一直推。100 个 线程而已,只要对面抗住个人电脑都随便抗。
    changeTheGame
        9
    changeTheGame  
    OP
       Dec 23, 2020
    @securityCoding 谢谢大佬指导
    changeTheGame
        10
    changeTheGame  
    OP
       Dec 23, 2020
    @limuyan44 我是分页推送的,从第一页到 100 页,顺序遍历,每页数据推送时创建一个线程池开 10 个线程,推完之后,关闭线程池
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   895 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 41ms · UTC 20:39 · PVG 04:39 · LAX 13:39 · JFK 16:39
    ♥ Do have faith in what you're doing.