测试调优(Tune Guide)
100万连接测试所需的Linux内核参数,网络协议栈参数,Erlang虚拟机参数,emqttd消息服务器参数设置如下:
系统全局允许分配的最大文件句柄数:
允许当前会话/进程打开文件句柄数:
持久化’fs.file-max’设置到/etc/sysctl.conf文件:
fs.file-max = 1048576
* soft nofile 1048576
* hard nofile 1048576
并发连接backlog设置:
可用知名端口范围:
sysctl -w net.ipv4.ip_local_port_range='1000 65535'
TCP Socket读写Buffer设置:
sysctl -w net.core.rmem_default=262144
sysctl -w net.core.wmem_default=262144
sysctl -w net.core.rmem_max=16777216
sysctl -w net.core.wmem_max=16777216
sysctl -w net.core.optmem_max=16777216
#sysctl -w net.ipv4.tcp_mem='16777216 16777216 16777216'
sysctl -w net.ipv4.tcp_rmem='1024 4096 16777216'
sysctl -w net.ipv4.tcp_wmem='1024 4096 16777216'
TCP连接追踪设置:
sysctl -w net.nf_conntrack_max=1000000
sysctl -w net.netfilter.nf_conntrack_max=1000000
FIN-WAIT-2 Socket超时设置:
net.ipv4.tcp_fin_timeout = 15
优化设置Erlang虚拟机启动参数,配置文件emqttd/etc/vm.args file:
## max process numbers
+P 2097152
## Sets the maximum number of simultaneously existing ports for this system
+Q 1048576
## Increase number of concurrent ports/sockets, deprecated in R17
-env ERL_MAX_PORTS 1048576
-env ERTS_MAX_PORTS 1048576
-env ERL_MAX_ETS_TABLES 1024
-env ERL_FULLSWEEP_AFTER 1000
设置TCP监听器的Acceptor池大小,最大允许连接数。配置文件emqttd/etc/emqttd.config:
{mqtt, 1883, [
%% Size of acceptor pool
{acceptors, 64},
%% Maximum number of concurrent clients
{max_clients, 1000000},
%% Socket Access Control
{access, [{allow, all}]},
%% Connection Options
{connopts, [
%% Rate Limit. Format is 'burst, rate', Unit is KB/Sec
%% {rate_limit, "100,10"} %% 100K burst, 10K rate
...
测试客户端服务器在一个接口上,最多只能创建65000连接: