站长网 Linux linux – 使用10GB内存的Haproxy和50k连接的100%CPU

linux – 使用10GB内存的Haproxy和50k连接的100%CPU

在Ubuntu 14.04 x64服??务器上,Haproxy使用3.3 GB内存和6.8 GB交换,同时处理52k连接.在大部分流量被重定向到另一个haproxy盒之前,CPU使用量也会持续增加到100%.流量主要是持久的TCP连接. pid = 3185 (process #1,nbproc = 1)uptime = 0d 6h14m21ssystem l

在Ubuntu 14.04 x64服??务器上,Haproxy使用3.3 GB内存和6.8 GB交换,同时处理52k连接.在大部分流量被重定向到另一个haproxy盒之前,CPU使用量也会持续增加到100%.流量主要是持久的TCP连接.

pid = 3185 (process #1,nbproc = 1)
uptime = 0d 6h14m21s
system limits: memmax = unlimited; ulimit-n = 524341
maxsock = 524341; maxconn = 262144; maxpipes = 0
current conns = 54303; current pipes = 0/0
Running tasks: 1/54336

人们注意到内存使用量大约在50k连接处大幅增加. ulimit -n设置为1048576.

问题:内存使用量是否异常高?我们怎样才能减少内存消耗?

我还从另一个问题中读到以下内容,是否相关?我应该如何检查TCP设置是否足够(对于持久性TCP连接),以免导致内存使用量的大幅增加?

At 54000 concurrent connections,you should be careful about your TCP settings. If running with default settings (87kB read buffer,16kB write buffer),you can end up eating 10 gigs of memory just for the sockets.

sysctl.conf的

net.core.wmem_max=12582912
net.core.rmem_max=12582912
net.ipv4.tcp_rmem= 10240 87380 12582912
net.ipv4.tcp_wmem= 10240 87380 12582912

haproxy.conf

global
    log /dev/log    local0
    log /dev/log    local1 notice
    maxconn 262144
    chroot /var/lib/haproxy
    user haproxy
    group haproxy
    daemon

defaults
    log global
    mode    tcp
    option  tcplog
    option  dontlognull
    option  redispatch
    retries 3
    maxconn 262144
    contimeout 180000
    clitimeout 180000
    srvtimeout 180000
    timeout contimeout  180000 
    timeout connect  180000
    timeout client  180000
    timeout server 180000

更新

重新启动(不重新加载)haproxy将CPU负载降低到30%.什么可能导致之前的高CPU负载?

解决方法

一旦耗尽源端口并尝试扫描可用端口,HAProxy上的CPU负载将达到100.通常这是30kish.你对sysctl net.ipv4.ip_local_port_range有什么看法?

因此,例如,如果您与后端中的单个服务器有30k连接,则可能会耗尽源端口并遇到CPU问题.

本文来自网络,不代表站长网立场,转载请注明出处:https://www.zwzz.com.cn/html/server/linux/2021/0524/5453.html

作者: dawei

【声明】:站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。
联系我们

联系我们

0577-28828765

在线咨询: QQ交谈

邮箱: xwei067@foxmail.com

工作时间:周一至周五,9:00-17:30,节假日休息

返回顶部