Operations 5 min read

Boost Web Server Performance: Proven Kernel and Application Tuning Guide

This article shares a practical template for optimizing web service performance, covering kernel sysctl tweaks, file‑handle limits, and Nginx/PHP‑FPM configuration adjustments to eliminate bottlenecks and maximize throughput under high traffic conditions.

360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
360 Zhihui Cloud Developer
Boost Web Server Performance: Proven Kernel and Application Tuning Guide

Background

In daily operations, high traffic often creates performance bottlenecks such as increased load, rising error logs, and request timeouts once connection counts hit certain thresholds. By applying systematic tuning, the service’s critical load point can be raised, fully utilizing system resources.

Kernel Parameter Optimization

<code>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</code>

Apply the changes with sysctl -p .

Detail: Enabling net.ipv4.tcp_tw_reuse and net.ipv4.tcp_timestamps helps reuse TIME_WAIT sockets and maintain accurate timestamps, reducing unnecessary packet drops.

File Descriptor Limits

<code>vi /etc/security/limits.d/def.conf
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535</code>

Save and exit to make the limits effective.

Web Application Parameter Optimization

Nginx

<code>server {
    listen 80 backlog=2048;
}</code>

PHP‑FPM

<code>pm = static;
pm.max_children = 1024;
pm.max_requests = 1000;
emergency_restart_threshold = 1;
emergency_restart_interval = 1m;</code>

Restart Nginx and PHP‑FPM after editing the configuration files.

Detail: pm.max_children must not exceed the soft nproc limit defined in the file‑handle settings, otherwise the service will fail to start.

Conclusion

Every new web server in the team follows this template for initialization; special cases should still be analyzed individually. For any parameter questions, feel free to comment and discuss.

operationssystem optimizationnginxPHP-FPMkernel-tuning
360 Zhihui Cloud Developer
Written by

360 Zhihui Cloud Developer

360 Zhihui Cloud is an enterprise open service platform that aims to "aggregate data value and empower an intelligent future," leveraging 360's extensive product and technology resources to deliver platform services to customers.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.