5.3.1 链接数的问题

问题描述

我想咨询个关于连接数的问题,我们用emqx建了一套服务,用ng做了负载,连3个MQTT节点。emqx.conf按照官网文档的指导配置,只加了3个节点的配置信息。目前来看,每个节点都只有1k左右的连接数,用eMQTT-Bench工具做测试,连接数只有2500左右。按照官网文档说明,连接数是不是应该有10万,是不是我们这边有什么配置配错了?

以下是Dash board的截图

emqx.conf 配置文件

NG配置如下

worker_processes 1;
events {
worker_connections 10240;
}
stream {
upstream mqtt_servers {
# down:表示当前的 server 暂时不参与负载
# max_fails:允许请求失败的次数;默认为 1
# fail_timeout:失败超时时间,默认 10s, max_fails 达到次数后暂停的请求时间
# backup:其它所有的非backup机器down或者忙的时候,请求backup机器
server x.x.x.x:12002;
server x.x.x.x:12002;
server x.x.x.x:12002;
}

# TCP mqtt

server {
listen 12002;
listen 12003;
proxy_pass mqtt_servers;

# 启用此项时,对应后端监听器也需要启用 proxy_protocol
#proxy_protocol on;
#proxy_connect_timeout 10s;   
# 默认心跳时间为 10 分钟
#proxy_timeout 1800s;
#proxy_buffer_size 3M;
#tcp_nodelay on;       

}
}

http {
upstream mqtt_websocket_servers {
server x.x.x.x:12004;
server x.x.x.x:12004;
server x.x.x.x:12004;
}

# ws mqtt

server {
listen 12004;
listen 12005;
server_name localhost;

location /mqtt {
  proxy_pass http://mqtt_websocket_servers;

  # websocket连接的Upgrade必须设置为WebSocket,表示在取得服务器响应之后,使用HTTP升级将HTTP协议转换(升级)为WebSocket协议
    proxy_set_header Upgrade $http_upgrade;
    # websocket 的Connection必须设置为Upgrade,表示客户端希望连接升级
    proxy_set_header Connection "Upgrade";
    # 保持连接活性,不发送连接关闭的信号
    proxy_set_header Connection '';
    #反向代理真实IP
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header REMOTE-HOST $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    # 设置代理的响应头部,保持传输编码为 chunked
    proxy_set_header X-Accel-Buffering no;
    proxy_http_version 1.1;
    # 设置跨域资源共享 (CORS),如果你的客户端和服务器不在同一个域上
    add_header 'Access-Control-Allow-Origin' '*' always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Origin,Authorization,Accept,X-Requested-With' always;
    if ($request_method = 'OPTIONS') {
        # 如果请求方法为 OPTIONS,则返回 204 (无内容)
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Origin,Authorization,Accept,X-Requested-With';
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 204;
    }
}

}
server {
listen 12000; # OSS地址访问
server_name localhost;

location ^~/public-resource/ {
    proxy_pass  http://cdgjbusp-ublic-info.oss-cn-chengdu-gj-d01-a.yunwei.cdgj.cn/; #注意/后缀
    proxy_hide_header Content-Disposition;
    proxy_set_header referer $host;
}
location ^~/driverPictureUrlPrefix/ {
    proxy_pass  http://10.30.155.62:8083/; #注意/后缀
    proxy_hide_header Content-Disposition;
    proxy_set_header referer $host;
    # 设置跨域资源共享 (CORS),如果你的客户端和服务器不在同一个域上
    add_header 'Access-Control-Allow-Origin' '*' always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Origin,Authorization,Accept,X-Requested-With' always;
    if ($request_method = 'OPTIONS') {
        # 如果请求方法为 OPTIONS,则返回 204 (无内容)
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Origin,Authorization,Accept,X-Requested-With';
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 204;
    }
}

}

server {
listen 12001; # push服务
server_name localhost;

location / {
    proxy_pass  http://10.30.148.101:38081; #注意/后缀
    proxy_hide_header Content-Disposition;
    proxy_set_header referer $host;
}
location ^~/driverPictureUrlPrefix/ {
    proxy_pass  http://10.30.155.62:8083/; #注意/后缀
    proxy_hide_header Content-Disposition;
    proxy_set_header referer $host;
    # 设置跨域资源共享 (CORS),如果你的客户端和服务器不在同一个域上
    add_header 'Access-Control-Allow-Origin' '*' always;
    add_header 'Access-Control-Allow-Credentials' 'true' always;
    add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS' always;
    add_header 'Access-Control-Allow-Headers' 'Origin,Authorization,Accept,X-Requested-With' always;
    if ($request_method = 'OPTIONS') {
        # 如果请求方法为 OPTIONS,则返回 204 (无内容)
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'Origin,Authorization,Accept,X-Requested-With';
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 204;
    }
}

}
}

只能到 1k 的话怀疑是 ulimit, 默认值就是 1024。系统调优文档里的内容都要做:

之前已经按照官方文档配置过一遍。连接数上不去的的配置参数如下

2571723629591_.pic