关于SignalR并发量测试

由于业务需要,需要做一个强制下线的功能(类似QQ、钉钉这种在相同平台上登录多个账号,下线之前已登录的账号)。

经过一些列的调研,发现SignalR这个框架实现起来比较简单

由于我们的客户是零散的终端用户,并发量是首先需要考虑的,写个测试案例进行连接实例测试。

创建了一台虚拟机Centos7版本,开始连接,每次连接不到1024个,就无法建立连接了

这里主要有2个原因,

第1个是linux的文件访问数量被限制,可以通过命令ulimit -n 查看1024

第2个是nginx的默认最大连接数也是1024.

需要进行如下调整,为了测试并发量,下面的并发数量统一设置为102400左右进行验证

**增加系统资源限制

编辑 /etc/sysctl.conf,添加或修改以下内容:
fs.file-max =102400
net.core.somaxconn = 65535
net.ipv4.ip_local_port_range = 1024 65535
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_fin_timeout = 15

编辑 /etc/security/limits.conf 文件,添加以下内容:
* soft nofile 102400
* hard nofile 102400

/etc/systemd/system.conf 文件中添加或修改以下行:
DefaultLimitNOFILE=102400
DefaultLimitNPROC=102400  #这行可以先不加

/etc/systemd/user.conf 文件中添加或修改以下行
DefaultLimitNOFILE=102400
DefaultLimitNPROC=102400  #这行可以先不加

 

调整 Nginx 配置
worker_processes auto;
worker_rlimit_nofile 102400;
events {
    worker_connections 102400;
    multi_accept on;
}

http {
    include       mime.types;
    default_type  application/octet-stream;

    sendfile        on;
    tcp_nopush      on;
    tcp_nodelay     on;
    keepalive_timeout  65;
    types_hash_max_size 2048;
    server_tokens off;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;

  #server 这部分可以单独配置在
/etc/nginx/conf.d/*.conf;
    server {
        listen 80;
        server_name 192.168.208.131;

        location / {
            proxy_pass http://localhost:5000;
            proxy_http_version 1.1;
            proxy_set_header Upgrade $http_upgrade;
            proxy_set_header Connection "upgrade";
            proxy_set_header Host $host;
            proxy_cache_bypass $http_upgrade;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header X-Forwarded-Proto $scheme;
        }
    }
}

 

经过上面的一些列设置后,本机可以连接过万,部署到云端服务器,同时拥有7台终端进行连接,测试并发量到1.7万连接没有问题,由于终端数量有限,无法测试更多的连接。理论上应该是支持更多的连接。

 

posted @ 2024-06-27 18:12  取经路上  阅读(7)  评论(0编辑  收藏  举报