Optimize your Linux server for peak performance
Before optimizing, it's crucial to understand your system's current performance. Use these tools to monitor various aspects of your Linux server:
top or htop : Monitor real-time system statisticsvmstat : Report virtual memory statisticsiostat : Report CPU and I/O statisticsnetstat : Monitor network connections and statisticssar : Collect, report, and save system activity informationThe CPU governor controls the CPU frequency scaling. To view current governor:
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
To set the performance governor:
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
Adjust process priority using the nice command. Lower values indicate higher priority:
nice -n -20 ./high_priority_process
nice -n 19 ./low_priority_process
Reduce swappiness to minimize swap usage:
echo 10 | sudo tee /proc/sys/vm/swappiness
Disable Transparent Huge Pages for database workloads:
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
Adjust VM overcommit settings:
echo 0 | sudo tee /proc/sys/vm/overcommit_memory
Choose an appropriate I/O scheduler. For SSDs, use 'noop' or 'deadline':
echo noop | sudo tee /sys/block/sda/queue/scheduler
Adjust readahead settings:
sudo blockdev --setra 256 /dev/sda
Use the 'noatime' mount option in /etc/fstab to reduce disk writes.
Optimize TCP settings in /etc/sysctl.conf :
net.ipv4.tcp_fin_timeout = 30 net.ipv4.tcp_keepalive_time = 1200 net.ipv4.tcp_max_syn_backlog = 8192 net.ipv4.tcp_tw_reuse = 1
Increase network interface buffers:
sudo ethtool -G eth0 rx 4096 tx 4096
For ext4, consider disabling journaling for high-write scenarios:
sudo tune2fs -O ^has_journal /dev/sda1
Enable TRIM for SSDs:
sudo systemctl enable fstrim.timer
| Application | Tuning Tips |
|---|---|
| Web Server (Nginx/Apache) |
|
| Database (MySQL/PostgreSQL) |
|
| Java Applications |
|