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 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问题.

相关文章

Linux中的ARP防火墙主要用于防御ARP欺骗攻击,其效果取决于多...
insmod和modprobe加-f参数导致Invalid module format错误 这...
将ArchLinux安装到U盘 几个月前入门Arch的时候上网搜了不少安...
1、安装Apache。 1)执行如下命令,安装Apache服务及其扩展包...
一、先说一下用ansible批量采集机器信息的实现办法: 1、先把...
安装配置 1. 安装vsftpd 检查是否安装了vsftpd # rpm -qa | ...