在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负载?