V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
NGINX
NGINX Trac
3rd Party Modules
Security Advisories
CHANGES
OpenResty
ngx_lua
Tengine
在线学习资源
NGINX 开发从入门到精通
NGINX Modules
ngx_echo
bantianys
V2EX  ›  NGINX

Upstream 配的 Server 多了吞吐量反而下降严重

  •  
  •   bantianys · 2021-04-11 18:19:44 +08:00 · 2340 次点击
    这是一个创建于 1108 天前的主题,其中的信息可能已经有所发展或是发生改变。

    6 台 Nginx,每台 Upstream 上配置了相同的 30 个服务。压测时发现压力分发到 30 个服务的集群衰减严重。 Upstream 只配置 2 台时,单个服务可以跑到 90%的 CPU,扩展后单个服务只有 20%的 CPU 占用。

    目前发现如果把这 6 台 Nginx 的 Upstream 下都配置成不同 IP 的 5 个服务,Nginx 集群依然是反向代理 30 个服务,整体吞吐量提升巨大。感觉上是 Upstream 的 Server 填多了会影响性能似的。负载均衡从轮询到最小链接都试过,没什么效果。感觉是其他的配置导致的。

    有没 Nginx 大神帮忙看下,最可能是哪里出了问题。

    第 1 条附言  ·  2021-04-11 19:55:23 +08:00
    Nginx 前面是 ELB,发往 ELB 的压力都是一样的。2 个场景的测试压力是相同,下面画个 Upstream 的配置示意图吧。

    性能差
    Nginx1 ==》 30Servers
    Nginx2 ==》 30Servers
    Nginx3==》 30Servers
    Nginx4==》 30Servers
    Nginx5 ==》 30Servers
    Nginx6 ==》 30Servers


    性能有较大幅度提升
    Nginx1 ==》 1-5Servers
    Nginx2 ==》 6-10Servers
    Nginx3==》 11-15Servers
    Nginx4==》 16-20Servers
    Nginx5 ==》 21-25Servers
    Nginx6 ==》 26-30Servers

    想知道场景 2 的整体性能提升是否说明 Nginx 的某些配置有问题,导致 Upstream 不能填太多 Server
    10 条回复    2021-04-13 10:05:32 +08:00
    mongodb
        1
    mongodb  
       2021-04-11 18:55:47 +08:00
    有点没看明白。

    如果是说 CPU 占用,那分的多了 CPU 下降不是正常?

    不是很明白你的意思。
    bantianys
        2
    bantianys  
    OP
       2021-04-11 19:32:13 +08:00
    忘记补充了一点。因为构造的测试压力是按 30 台估算后扩展的。所以理论上每台服务的 CPU 占用不应该太低。
    bantianys
        3
    bantianys  
    OP
       2021-04-11 19:37:46 +08:00
    Nginx 前面是 ELB,发往 ELB 的压力都是一样的。2 个场景的测试压力是相同,下面画个 Upstream 的配置示意图吧。

    性能差
    Nginx1 ==》 30Servers
    Nginx2 ==》 30Servers
    Nginx3==》 30Servers
    Nginx4==》 30Servers
    Nginx5 ==》 30Servers
    Nginx6 ==》 30Servers


    性能有较大幅度提升
    Nginx1 ==》 1-5Servers
    Nginx2 ==》 6-10Servers
    Nginx3==》 11-15Servers
    Nginx4==》 16-20Servers
    Nginx5 ==》 21-25Servers
    Nginx6 ==》 26-30Servers

    想知道场景 2 的整体性能提升是否说明 Nginx 的某些配置有问题,导致 Upstream 不能填太多 Server
    Morxi
        4
    Morxi  
       2021-04-11 19:57:38 +08:00
    @bantianys

    我猜你所有的 nginx 配所有节点的结果是:前几个后端 Server 在抗大部分流量

    来源: http://nginx.org/en/docs/http/ngx_http_upstream_module.html
    ...
    By default, requests are distributed between the servers using a weighted round-robin balancing method. In the above example, each 7 requests will be distributed as follows: 5 requests go to backend1.example.com and one request to each of the second and third servers. If an error occurs during communication with a server, the request will be passed to the next server, and so on until all of the functioning servers will be tried. If a successful response could not be obtained from any of the servers, the client will receive the result of the communication with the last server.
    ...

    翻译:
    默认情况下,使用加权循环平衡方法在服务器之间分配请求。在上面的示例中,每 7 个请求将如下分配:5 个请求转到 backend1.example.com 第二个和第三个服务器中的一个请求。如果在与服务器通信期间发生错误,该请求将被传递到下一个服务器,依此类推,直到尝试所有正常运行的服务器为止。如果无法从任何一台服务器获得成功的响应,则客户端将收到与最后一台服务器的通信结果。
    whileFalse
        5
    whileFalse  
       2021-04-11 21:12:47 +08:00
    你试试每个 Nginx 都填写 30 个 Upstream,并且每个 Nginx 的顺序不同:
    Nginx1 ==> 1-30
    Nginx2 ==> 6-30, 1-5
    Nginx3 11-30, 1-10

    依此类推
    bantianys
        6
    bantianys  
    OP
       2021-04-11 21:20:03 +08:00
    上周领导承诺要抗 30W QPS,结果一测战力只有 5 。。。折腾了好几天最终缩小范围到 Nginx 配置这块。

    感谢各位大佬,周一上班去试试。
    akira
        7
    akira  
       2021-04-11 21:47:28 +08:00
    用这样的配置顺序测试一下呢

    nginx1 => 1-30
    nginx2 => 6-30,1-5
    nginx3 => 11-30,1-10
    .....
    nginx6 => 26-30,1-25
    rahuahua
        8
    rahuahua  
       2021-04-12 14:02:03 +08:00
    好奇问下第二种配置提升了多少
    bantianys
        9
    bantianys  
    OP
       2021-04-12 21:25:07 +08:00
    @rahuahua 拆分成小集群后 QPS 由 1.2W 提升到接近 12W 。差不多 10 倍了。
    也不清楚原理是什么。
    rahuahua
        10
    rahuahua  
       2021-04-13 10:05:32 +08:00
    @bantianys 乖乖,有点突破认知了,期待后续总结~~~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1003 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 22:02 · PVG 06:02 · LAX 15:02 · JFK 18:02
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.