Performance Tuning with sysctl
Advanced15 min
Tune kernel parameters using sysctl to optimize network performance, file descriptor limits, and memory management.
Prerequisites
- -Linux shell access
- -Root or sudo access
Steps
1
View current kernel parameters
List all sysctl parameters and their current values.
$ sysctl -a 2>/dev/null | grep -E 'net.core.somaxconn|vm.swappiness|fs.file-max|net.ipv4.tcp_max_syn_backlog'
2
Check current file descriptor limits
View the maximum number of open file descriptors.
$ sysctl fs.file-max && ulimit -n
fs.file-max is the system-wide limit. ulimit -n is the per-process limit.
3
Optimize TCP settings for high-traffic servers
Increase TCP connection backlog and enable TCP optimizations.
$ sudo sysctl -w net.core.somaxconn=65535 && sudo sysctl -w net.ipv4.tcp_max_syn_backlog=65535
These changes are temporary and lost on reboot. Add them to /etc/sysctl.d/ to persist.
4
Adjust swappiness for server workloads
Reduce swappiness to prefer keeping application memory in RAM.
$ sudo sysctl -w vm.swappiness=10
Default is 60. For database servers, 10 is common. For desktops, 60 is fine.
5
Persist sysctl changes across reboots
Save tuning parameters to a config file so they survive reboots.
$ echo 'net.core.somaxconn=65535
vm.swappiness=10
fs.file-max=2097152' | sudo tee /etc/sysctl.d/99-performance.conf && sudo sysctl --system
Full Script
FAQ
Discussion
Loading comments...