测试调优(Tune Guide)

    100万连接测试所需的Linux内核参数,网络协议栈参数,Erlang虚拟机参数,emqttd消息服务器参数设置如下:

    系统全局允许分配的最大文件句柄数:

    允许当前会话/进程打开文件句柄数:

    持久化’fs.file-max’设置到/etc/sysctl.conf文件:

    1. fs.file-max = 1048576
    1. * soft nofile 1048576
    2. * hard nofile 1048576

    并发连接backlog设置:

    可用知名端口范围:

    1. sysctl -w net.ipv4.ip_local_port_range='1000 65535'

    TCP Socket读写Buffer设置:

    1. sysctl -w net.core.rmem_default=262144
    2. sysctl -w net.core.wmem_default=262144
    3. sysctl -w net.core.rmem_max=16777216
    4. sysctl -w net.core.wmem_max=16777216
    5. sysctl -w net.core.optmem_max=16777216
    6. #sysctl -w net.ipv4.tcp_mem='16777216 16777216 16777216'
    7. sysctl -w net.ipv4.tcp_rmem='1024 4096 16777216'
    8. sysctl -w net.ipv4.tcp_wmem='1024 4096 16777216'

    TCP连接追踪设置:

    1. sysctl -w net.nf_conntrack_max=1000000
    2. sysctl -w net.netfilter.nf_conntrack_max=1000000

    FIN-WAIT-2 Socket超时设置:

    1. net.ipv4.tcp_fin_timeout = 15

    优化设置Erlang虚拟机启动参数,配置文件emqttd/etc/vm.args file:

    1. ## max process numbers
    2. +P 2097152
    3. ## Sets the maximum number of simultaneously existing ports for this system
    4. +Q 1048576
    5. ## Increase number of concurrent ports/sockets, deprecated in R17
    6. -env ERL_MAX_PORTS 1048576
    7. -env ERTS_MAX_PORTS 1048576
    8. -env ERL_MAX_ETS_TABLES 1024
    9. -env ERL_FULLSWEEP_AFTER 1000

    设置TCP监听器的Acceptor池大小,最大允许连接数。配置文件emqttd/etc/emqttd.config:

    1. {mqtt, 1883, [
    2. %% Size of acceptor pool
    3. {acceptors, 64},
    4. %% Maximum number of concurrent clients
    5. {max_clients, 1000000},
    6. %% Socket Access Control
    7. {access, [{allow, all}]},
    8. %% Connection Options
    9. {connopts, [
    10. %% Rate Limit. Format is 'burst, rate', Unit is KB/Sec
    11. %% {rate_limit, "100,10"} %% 100K burst, 10K rate
    12. ...

    测试客户端服务器在一个接口上,最多只能创建65000连接: