tune.rst 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. .. _tune:
  2. ============
  3. Tuning Guide
  4. ============
  5. Tuning the Linux Kernel, Networking, Erlang VM and the *EMQ* broker for one million concurrent MQTT connections.
  6. -------------------
  7. Linux Kernel Tuning
  8. -------------------
  9. The system-wide limit on max opened file handles::
  10. # 2 million system-wide
  11. sysctl -w fs.file-max=2097152
  12. sysctl -w fs.nr_open=2097152
  13. echo 2097152 > /proc/sys/fs/nr_open
  14. The limit on opened file handles for current session::
  15. ulimit -n 1048576
  16. /etc/sysctl.conf
  17. ----------------
  18. Add the 'fs.file-max' to /etc/sysctl.conf, make the changes permanent::
  19. fs.file-max = 1048576
  20. /etc/security/limits.conf
  21. -------------------------
  22. Persist the limits on opened file handles for users in /etc/security/limits.conf::
  23. * soft nofile 1048576
  24. * hard nofile 1048576
  25. --------------
  26. Network Tuning
  27. --------------
  28. Increase number of incoming connections backlog::
  29. sysctl -w net.core.somaxconn=32768
  30. sysctl -w net.ipv4.tcp_max_syn_backlog=16384
  31. sysctl -w net.core.netdev_max_backlog=16384
  32. Local Port Range::
  33. sysctl -w net.ipv4.ip_local_port_range="1000 65535"
  34. Read/Write Buffer for TCP connections::
  35. sysctl -w net.core.rmem_default=262144
  36. sysctl -w net.core.wmem_default=262144
  37. sysctl -w net.core.rmem_max=16777216
  38. sysctl -w net.core.wmem_max=16777216
  39. sysctl -w net.core.optmem_max=16777216
  40. #sysctl -w net.ipv4.tcp_mem='16777216 16777216 16777216'
  41. sysctl -w net.ipv4.tcp_rmem='1024 4096 16777216'
  42. sysctl -w net.ipv4.tcp_wmem='1024 4096 16777216'
  43. Connection Tracking::
  44. sysctl -w net.nf_conntrack_max=1000000
  45. sysctl -w net.netfilter.nf_conntrack_max=1000000
  46. sysctl -w net.netfilter.nf_conntrack_tcp_timeout_time_wait=30
  47. The TIME-WAIT Buckets Pool, Recycling and Reuse::
  48. net.ipv4.tcp_max_tw_buckets=1048576
  49. # Enable fast recycling of TIME_WAIT sockets. Enabling this
  50. # option is not recommended for devices communicating with the
  51. # general Internet or using NAT (Network Address Translation).
  52. # Since some NAT gateways pass through IP timestamp values, one
  53. # IP can appear to have non-increasing timestamps.
  54. # net.ipv4.tcp_tw_recycle = 1
  55. # net.ipv4.tcp_tw_reuse = 1
  56. Timeout for FIN-WAIT-2 sockets::
  57. net.ipv4.tcp_fin_timeout = 15
  58. ----------------
  59. Erlang VM Tuning
  60. ----------------
  61. Tuning and optimize the Erlang VM in etc/emq.conf file:
  62. .. code-block:: properties
  63. ## Erlang Process Limit
  64. node.process_limit = 2097152
  65. ## Sets the maximum number of simultaneously existing ports for this system
  66. node.max_ports = 1048576
  67. --------------
  68. The EMQ Broker
  69. --------------
  70. Tune the acceptor pool, max_clients limit and sockopts for TCP listener in etc/emqttd.config:
  71. .. code-block:: properties
  72. ## TCP Listener
  73. mqtt.listener.tcp = 1883
  74. mqtt.listener.tcp.acceptors = 64
  75. mqtt.listener.tcp.max_clients = 1000000
  76. --------------
  77. Client Machine
  78. --------------
  79. Tune the client machine to benchmark emqttd broker:
  80. .. code-block:: bash
  81. sysctl -w net.ipv4.ip_local_port_range="500 65535"
  82. sysctl -w fs.file-max=1000000
  83. echo 1000000 > /proc/sys/fs/nr_open
  84. ulimit -n 100000
  85. ---------------
  86. emqtt_benchmark
  87. ---------------
  88. Test tool for concurrent connections: http://github.com/emqtt/emqtt_benchmark