Skills-Linux kernel parameter adjustment method

Skills

- Linux kernel parameter adjustment method



ulimit Set

ulimit -n to be adjusted to 100000 or even larger. Execute ulimit -n 100000 on the command line to modify. If it cannot be modified, you need to set /etc/security/limits.conf and add



* soft nofile 262140



* hard nofile 262140



root soft nofile 262140



root hard nofile 262140



* soft core unlimited



* hard core unlimited



root soft core unlimited



root hard core unlimited



kernel settings

net.unix.max_dgram_qlen = 100



swoole uses unix socket dgram for inter-process communication. If the request volume is large, this parameter needs to be adjusted. The system defaults to 10 and can be set to 100 or greater.

Or increase the number of worker processes and reduce the amount of requests allocated by a single worker process.



net.core.wmem_max



Modify this parameter to increase the memory size of the socket buffer



net.ipv4.tcp_mem = 379008 505344 758016



net.ipv4.tcp_wmem = 4096 16384



4194304 net.ipv4.tcp_rmem = 4096 87380



4194304 net.core.wmem_default = 8388608



net.core.rmem_default = 8388608



net.core.rmem_max = 16777216



net.core.wmem77_max =





4 Whether tcp_tw_reuse





is socket reuse, the function of this function is to quickly reuse the listening port when the server restarts. If this parameter is not set, it will cause the port to fail to be released in time when the server restarts.



Net.ipv4.tcp_tw_recycle





uses socket to quickly recycle, and the short-connection server needs to enable this parameter.



Message Queue Settings





When using message queue as the inter-process communication method, This kernel parameter needs to be adjusted



kernel.msgmnb = 4203520, the maximum number of bytes of the message queue



kernel.msgmni = 64, the maximum number of message queues allowed to be created



kernel.msgmax = 8192, the maximum length of a single message queue data



FreeBSD/MacOS

sysctl -w net.local.dgram.maxdgram=8192



sysctl -w net.local.dgram.recvspace=200000 Modify the size of the buffer area of ​​the Unix Socket



Open CoreDump





to set the kernel parameters



kernel.core_pattern = /data/core_files/core-%e-%p-%t





Use the ulimit -c command to view the current If the limit



ulimit -c of the coredump file





is 0, you need to modify /etc/security/limits.conf to set the limit.



After core-dump is turned on, once a program exception occurs, the process will be exported to a file. Great help for investigating program problems

Other important configurations, here is how Brother

Link www.lampbrother.net

demonstrates:

net.ipv4.tcp_syncookies=1



net.ipv4.tcp_max_syn_backlog=81920



net.ipv4.tcp_synack_retries=3



net.ipv4.tcp_syn_retries =3



net.ipv4.tcp_fin_timeout = 30



net.ipv4.tcp_keepalive_time = 300



net.ipv4.tcp_tw_reuse = 1



net.ipv4.tcp_tw_recycle = 1



net.ipv4.ip_local_port_range = 20000 65000



net.ipv4.tcp_max_tw_buckets = 200000



net.ipv4.route.max_size = 5242880



Check whether the configuration takes effect.





For example , after modifying net.unix.max_dgram_qlen = 100, run



cat /proc/sys/net/unix /max_dgram_qlen





Brothers

Linux Training

Tips : If the modification is successful, here is the newly set value.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326502619&siteId=291194637