WEB server parameter optimization configuration template

WEB server parameter optimization configuration template

WEB server parameter optimization configuration template

The heroine's declaration:

Frozen three feet is not a day's cold, experience depends on the usual continuous accumulation. From fault case resolution to performance parameter tuning, the HULK operation and maintenance team has accumulated a lot of experience in supporting the company’s multiple lifeline businesses. Today I will share with you an article from the HULK addops team "WEB server system performance parameters" Optimize the summary template", I hope to help everyone!
PS: Rich first-line technology and diversified forms of expression are all in the "HULK first-line technology talk", please pay attention!

Background introduction

In daily operation and maintenance work, some performance bottlenecks caused by large traffic are often encountered. For example, when the number of connections reaches a certain value, the load on the server begins to increase, log errors begin to increase, and applications begin to time out. The load capacity of each system will have a critical value, and if the system is tuned in a scientific way, the throughput of the system performance will be maximized, and the system resources will be fully utilized to increase this critical value.

After a long accumulation of experience, the team has summed up a standard configuration template and has stably supported multiple important business lines within the company. Selflessly, we decided to share this template with everyone, and talk to everyone about these things about parameter optimization!

System parameter optimization

Kernel parameter optimization:


vi /etc/sysctl.conf 
net.ipv4.tcp_keepalive_time = 300
net.ipv4.tcp_keepalive_intvl = 10
net.ipv4.tcp_keepalive_probes = 5
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_timestamps = 1
net.ipv4.tcp_ecn = 0
net.ipv4.tcp_sack = 1
net.ipv4.tcp_dsack = 0
net.ipv4.tcp_fin_timeout = 3
net.ipv4.tcp_rmem = 4096 2097152 16777216
net.ipv4.tcp_wmem = 4096 2097152 16777216
net.ipv4.tcp_max_orphans = 3276800
net.ipv4.tcp_max_tw_buckets = 18000
net.ipv4.tcp_no_metrics_save = 1
net.ipv4.tcp_max_syn_backlog = 262144
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 2
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_mem = 196608 2097152 3145728
net.ipv4.ip_local_port_range = 1024 65000
net.core.rmem_default = 16777216
net.core.wmem_default = 16777216
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.core.somaxconn = 262144
net.core.netdev_max_backlog = 300000
fs.file-max = 1280000
net.unix.max_dgram_qlen = 10000

Execute sysctl -p to make it effective.

Details:

TCP has a behavior that can cache the latest timestamp of each connection. If the timestamp is less than the cached timestamp in subsequent requests, it is considered invalid and the corresponding data packet will be discarded.
Recommended setting:
net.ipv4.tcp_tw_reuse = 1
net.ipv4.tcp_tw_recycle = 0
net.ipv4.tcp_timestamps = 1

File handle restrictions:

vi /etc/security/limits.d/def.conf

  • soft nofile 65535
  • hard nofile 65535
  • soft nproc 65535
  • hard nproc 65535

After saving and exiting, it will take effect.

Web program parameter optimization

Nginx:


server {
 listen 80 backlog=2048;      
}

PHP:


pm = static;
pm.max_children = 1024;
pm.max_requests = 1000;
emergency_restart_threshold = 1;
emergency_restart_interval = 1m;

Restart to take effect after modifying the Nginx+PHP configuration file.

Details:

The value of pm.max_children must not be greater than the limit of the number of "*soft nproc" file handles, otherwise an error will be reported.

to sum up

Every web server in the team will be configured according to this template during the initialization process. Of course, if there are special circumstances, specific problems should be analyzed in detail. The explanation of each parameter can be checked by Google, so I won’t explain it here. If you have any questions about the configuration of a parameter, or if you want to communicate, just follow us and leave a message! o(∩_∩)o~

Guess you like

Origin blog.51cto.com/15127564/2668205
Recommended