linux_kernel_tuning.rst 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. Linux Kernel Tuning for C1000K concurrent connections::
  2. # system-wide limit on max opened files for all processes
  3. # sysctl -n fs.nr_open
  4. # 1M
  5. sysctl -w fs.file-max=1048576
  6. sysctl -w fs.nr_open=1048576
  7. ulimit -n 1048576
  8. # Increase number of incoming connections
  9. net.core.somaxconn = 65536
  10. sysctl -w net.ipv4.tcp_mem='10000000 10000000 10000000'
  11. sysctl -w net.ipv4.tcp_rmem='1024 4096 16384'
  12. sysctl -w net.ipv4.tcp_wmem='1024 4096 16384'
  13. sysctl -w net.core.rmem_max=16384
  14. sysctl -w net.core.wmem_max=16384
  15. net.core.rmem_max = 16777216
  16. net.core.wmem_max = 16777216
  17. net.core.rmem_default = 16777216
  18. net.core.wmem_default = 16777216
  19. net.core.optmem_max = 2048000
  20. net.core.netdev_max_backlog = 50000
  21. net.ipv4.tcp_rmem = 4096 4096 16777216
  22. net.ipv4.tcp_wmem = 4096 4096 16777216
  23. net.ipv4.tcp_max_syn_backlog = 30000
  24. net.ipv4.tcp_max_tw_buckets = 2000000
  25. net.ipv4.tcp_tw_reuse = 1
  26. net.ipv4.tcp_fin_timeout = 10
  27. net.ipv4.conf.all.send_redirects = 0
  28. net.ipv4.conf.all.accept_redirects = 0
  29. net.ipv4.conf.all.accept_source_route = 0
  30. net.ipv4.tcp_slow_start_after_idle = 0
  31. net.ipv4.ip_local_port_range = 8000 65535
  32. net.netfilter.nf_conntrack_max = 1000000
  33. net.netfilter.nf_conntrack_tcp_timeout_time_wait = 30
  34. vm.min_free_kbytes = 65536
  35. vm.swappiness = 0
  36. vm.overcommit_memory = 1
  37. /etc/sysctl.conf
  38. ----------------
  39. ::
  40. fs.file-max = 1048576
  41. /etc/security/limits.conf
  42. -------------------------
  43. ::
  44. * soft nofile 1048576
  45. * hard nofile 1048576
  46. ## Kernel/Network Tunings from @galvezlj
  47. Server side:
  48. ```
  49. fs.file-max = 1000000
  50. net.core.somaxconn = 65536
  51. net.ipv4.ip_local_port_range = 500 65535
  52. net.nf_conntrack_max = 1000000
  53. net.netfilter.nf_conntrack_max = 1000000
  54. net.ipv4.tcp_rmem = 4096 4096 16777216
  55. net.ipv4.tcp_wmem = 4096 4096 16777216
  56. ```
  57. Client side:
  58. ```
  59. sysctl -w net.ipv4.ip_local_port_range="500 65535"
  60. echo 1000000 > /proc/sys/fs/nr_open
  61. ```
  62. ## Kernel/Network Tunings from my benchmark server
  63. ```
  64. fs.file-max = 1000000
  65. net.core.somaxconn = 65536
  66. net.core.wmem_max = 124928
  67. net.core.rmem_max = 124928
  68. net.core.wmem_default = 124928
  69. net.core.rmem_default = 124928
  70. net.core.dev_weight = 64
  71. net.core.netdev_max_backlog = 1000
  72. net.core.message_cost = 5
  73. net.core.message_burst = 10
  74. net.core.optmem_max = 20480
  75. net.core.busy_poll = 0
  76. net.core.busy_read = 0
  77. net.core.netdev_budget = 300
  78. net.ipv4.tcp_timestamps = 1
  79. net.ipv4.tcp_window_scaling = 1
  80. net.ipv4.tcp_sack = 1
  81. net.ipv4.tcp_retrans_collapse = 1
  82. net.ipv4.ip_default_ttl = 64
  83. net.ipv4.tcp_syn_retries = 5
  84. net.ipv4.tcp_synack_retries = 5
  85. net.ipv4.tcp_max_orphans = 262144
  86. net.ipv4.tcp_max_tw_buckets = 262144
  87. net.ipv4.ip_dynaddr = 0
  88. net.ipv4.tcp_keepalive_time = 7200
  89. net.ipv4.tcp_keepalive_probes = 9
  90. net.ipv4.tcp_keepalive_intvl = 75
  91. net.ipv4.tcp_retries1 = 3
  92. net.ipv4.tcp_retries2 = 15
  93. net.ipv4.tcp_fin_timeout = 60
  94. net.ipv4.tcp_syncookies = 1
  95. net.ipv4.tcp_tw_recycle = 0
  96. net.ipv4.tcp_abort_on_overflow = 0
  97. net.ipv4.tcp_max_syn_backlog = 2048
  98. net.ipv4.ip_local_port_range = 32768 61000
  99. net.ipv4.inet_peer_threshold = 65664
  100. net.ipv4.inet_peer_minttl = 120
  101. net.ipv4.inet_peer_maxttl = 600
  102. net.ipv4.inet_peer_gc_mintime = 10
  103. net.ipv4.inet_peer_gc_maxtime = 120
  104. net.ipv4.tcp_mem = 3080640 4107520 6161280
  105. net.ipv4.tcp_wmem = 4096 16384 4194304
  106. net.ipv4.tcp_rmem = 4096 87380 4194304
  107. net.ipv4.tcp_app_win = 31
  108. net.ipv4.tcp_adv_win_scale = 2
  109. net.ipv4.tcp_tw_reuse = 0
  110. net.ipv4.tcp_frto = 2
  111. net.ipv4.tcp_frto_response = 0
  112. net.ipv4.tcp_low_latency = 0
  113. net.ipv4.tcp_no_metrics_save = 0
  114. net.ipv4.tcp_moderate_rcvbuf = 1
  115. net.ipv4.tcp_tso_win_divisor = 3
  116. net.ipv4.tcp_congestion_control = cubic
  117. net.ipv4.tcp_abc = 0
  118. net.ipv4.tcp_mtu_probing = 0
  119. net.ipv4.tcp_base_mss = 512
  120. net.ipv4.tcp_workaround_signed_windows = 0
  121. net.ipv4.tcp_challenge_ack_limit = 100
  122. net.ipv4.tcp_limit_output_bytes = 131072
  123. net.ipv4.tcp_dma_copybreak = 4096
  124. net.ipv4.tcp_slow_start_after_idle = 1
  125. net.ipv4.tcp_available_congestion_control = cubic reno
  126. net.ipv4.tcp_allowed_congestion_control = cubic reno
  127. net.ipv4.tcp_max_ssthresh = 0
  128. net.ipv4.tcp_thin_linear_timeouts = 0
  129. net.ipv4.tcp_thin_dupack = 0
  130. net.ipv4.tcp_min_tso_segs = 2
  131. net.ipv4.udp_mem = 3080640 4107520 6161280
  132. net.ipv4.udp_rmem_min = 4096
  133. net.ipv4.udp_wmem_min = 4096
  134. net.ipv4.conf.all.forwarding = 0
  135. net.ipv4.conf.all.mc_forwarding = 0
  136. net.ipv4.conf.all.accept_redirects = 1
  137. net.ipv4.conf.all.secure_redirects = 1
  138. net.ipv4.conf.all.shared_media = 1
  139. net.ipv4.conf.all.rp_filter = 0
  140. net.ipv4.conf.all.send_redirects = 1
  141. net.ipv4.conf.all.src_valid_mark = 0
  142. net.ipv4.conf.all.medium_id = 0
  143. net.ipv4.conf.all.bootp_relay = 0
  144. net.ipv4.conf.all.log_martians = 0
  145. net.ipv4.conf.all.tag = 0
  146. vm.min_free_kbytes = 67584
  147. vm.swappiness = 60
  148. vm.overcommit_memory = 0
  149. ```