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连接.
  1. pid = 3185 (process #1,nbproc = 1)
  2. uptime = 0d 6h14m21s
  3. system limits: memmax = unlimited; ulimit-n = 524341
  4. maxsock = 524341; maxconn = 262144; maxpipes = 0
  5. current conns = 54303; current pipes = 0/0
  6. Running tasks: 1/54336

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

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

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

  1. 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的

  1. net.core.wmem_max=12582912
  2. net.core.rmem_max=12582912
  3. net.ipv4.tcp_rmem= 10240 87380 12582912
  4. net.ipv4.tcp_wmem= 10240 87380 12582912

haproxy.conf

  1. global
  2. log /dev/log local0
  3. log /dev/log local1 notice
  4. maxconn 262144
  5. chroot /var/lib/haproxy
  6. user haproxy
  7. group haproxy
  8. daemon
  9.  
  10. defaults
  11. log global
  12. mode tcp
  13. option tcplog
  14. option dontlognull
  15. option redispatch
  16. retries 3
  17. maxconn 262144
  18. contimeout 180000
  19. clitimeout 180000
  20. srvtimeout 180000
  21. timeout contimeout 180000
  22. timeout connect 180000
  23. timeout client 180000
  24. timeout server 180000

更新

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

解决方法

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

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

猜你在找的Linux相关文章