使用haproxy socket.io限制4000个并发用户

时间:2016-11-03 15:17:16

标签: node.js amazon-web-services websocket socket.io haproxy

我正在尝试将100.000个并发用户连接到我的应用程序,但是当我连接超过4000个用户时,所有的websockets都被断开连接。

应用程序的体系结构是一个带有HAProxy,API应用程序的单一体系结构,websockets系统是运行10个节点的应用程序,MySql和Redis。

我已经实施了多个解决方案,但有些方法无效:

我已将硬件和软件nofile限制更新为1M,并且可能已打开文件的硬件和NAT ip连接跟踪表的大小。

客户

我有一个客户端的另一个实例。为了测试porpouses,我运行一个拥有1K用户的客户端,并且所有用户都已连接。我在一个新的shell中重复这个过程。有4000个客户端都可以工作,但是如果我运行另一个有1K或100个用户的客户端,所有用户都会断开连接并开始重新连接。

问题出在哪里?

配置

服务器

AWS EC2 m3.xlarge实例4核和15GB Ram。

服务器堆栈

HA-Proxy版本1.5.8 Socket.io 1.3.7 Debian 8

Haproxy配置文件haproxy.cfg

global
log /dev/log    local0
log /dev/log    local1 notice
chroot /var/lib/haproxy
stats socket /run/haproxy/admin.sock mode 660 level admin
stats timeout 30s
user haproxy
group haproxy
maxconn  100000
daemon

# Default SSL material locations
ca-base /etc/ssl/certs
crt-base /etc/ssl/private

# Default ciphers to use on SSL-enabled listening sockets.
# For more information, see ciphers(1SSL). This list is from:
#  https://hynek.me/articles/hardening-your-web-servers-ssl-ciphers/

ssl-default-bind-ciphers ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AESGCM:RSA+AES:RSA+3DES:!aNULL:!MD5:!DSS
ssl-default-bind-options no-sslv3


defaults
    log     global
    mode    http
    option  httplog
    option  dontlognull
    maxconn  100000
    timeout connect 5000
    timeout client  50000
    timeout server  50000
    errorfile 400 /etc/haproxy/errors/400.http
    errorfile 403 /etc/haproxy/errors/403.http
    errorfile 408 /etc/haproxy/errors/408.http
    errorfile 500 /etc/haproxy/errors/500.http
    errorfile 502 /etc/haproxy/errors/502.http
    errorfile 503 /etc/haproxy/errors/503.http
    errorfile 504 /etc/haproxy/errors/504.http


frontend http-in
  bind *:80


    # Define hosts
  acl is_api_domain hdr(host) -i api.xxxx.com
  acl is_rtp_domain hdr(host) -i rtp.xxxx.com

  # Backends
  use_backend server_api if is_api_domain
  use_backend server_rtp if is_rtp_domain

  default_backend server_api

backend server_api
  mode http
  option forwardfor
  option http-server-close
  option tcplog

  server  apiApp 127.0.0.1:3002

backend server_rtp
  balance   roundrobin
  server  rtpApp0 127.0.0.1:8500
  server  rtpApp1 127.0.0.1:8501
  server  rtpApp2 127.0.0.1:8502
  server  rtpApp3 127.0.0.1:8503
  server  rtpApp4 127.0.0.1:8504
  server  rtpApp5 127.0.0.1:8505
  server  rtpApp6 127.0.0.1:8506
  server  rtpApp7 127.0.0.1:8507
  server  rtpApp8 127.0.0.1:8508
  server  rtpApp9 127.0.0.1:8509

$ ulimit -a

core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 60221
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 1000000
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 8192
cpu time               (seconds, -t) unlimited
max user processes              (-u) 60221
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited

/etc/sysctl.conf中

fs.file-max = 1000000
fs.nr_open = 1000000    
net.ipv4.netfilter.ip_conntrack_max = 1048576
net.nf_conntrack_max = 1048576

0 个答案:

没有答案