Introduction
Default Linux kernel settings are conservative and designed for general use. For high-traffic web servers, tuning sysctl parameters can significantly improve performance.
Network Stack Tuning
Add to /etc/sysctl.d/99-web-performance.conf:
# Increase connection backlog
net.core.somaxconn = 65535
net.core.netdev_max_backlog = 65535
# TCP buffer sizes (min, default, max in bytes)
net.core.rmem_max = 16777216
net.core.wmem_max = 16777216
net.ipv4.tcp_rmem = 4096 87380 16777216
net.ipv4.tcp_wmem = 4096 65536 16777216
# Enable TCP Fast Open
net.ipv4.tcp_fastopen = 3
# Reuse TIME_WAIT connections
net.ipv4.tcp_tw_reuse = 1
# Increase local port range
net.ipv4.ip_local_port_range = 1024 65535
# Max connection tracking
net.netfilter.nf_conntrack_max = 262144File Descriptor Limits
Add to /etc/security/limits.conf:
* soft nofile 65535
* hard nofile 65535Memory Tuning
# Reduce swap tendency (0-100, lower = less swapping)
vm.swappiness = 10
# Increase inotify limits (for file watchers)
fs.inotify.max_user_watches = 524288Apply Changes
sudo sysctl -p /etc/sysctl.d/99-web-performance.confVerify
sysctl net.core.somaxconn
sysctl vm.swappiness