Linux Performance Tuning Guide

Optimize your Linux server for peak performance

1. System Monitoring

Before optimizing, it's crucial to understand your system's current performance. Use these tools to monitor various aspects of your Linux server:

Tip: Use these tools regularly to establish baseline performance metrics and identify bottlenecks.

2. CPU Optimization

2.1 CPU Governor

The 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

2.2 Process Niceness

Adjust process priority using the nice command. Lower values indicate higher priority:

nice -n -20 ./high_priority_process nice -n 19 ./low_priority_process

3. Memory Management

3.1 Swappiness

Reduce swappiness to minimize swap usage:

echo 10 | sudo tee /proc/sys/vm/swappiness

3.2 Transparent Huge Pages

Disable Transparent Huge Pages for database workloads:

echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled

3.3 Virtual Memory Overcommit

Adjust VM overcommit settings:

echo 0 | sudo tee /proc/sys/vm/overcommit_memory

4. Disk I/O Optimization

4.1 I/O Scheduler

Choose an appropriate I/O scheduler. For SSDs, use 'noop' or 'deadline':

echo noop | sudo tee /sys/block/sda/queue/scheduler

4.2 Readahead

Adjust readahead settings:

sudo blockdev --setra 256 /dev/sda

4.3 Noatime Mount Option

Use the 'noatime' mount option in /etc/fstab to reduce disk writes.

5. Network Tuning

5.1 TCP Settings

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
  

5.2 Network Interface

Increase network interface buffers:

sudo ethtool -G eth0 rx 4096 tx 4096

6. File System Optimization

6.1 Journaling

For ext4, consider disabling journaling for high-write scenarios:

sudo tune2fs -O ^has_journal /dev/sda1

6.2 TRIM (for SSDs)

Enable TRIM for SSDs:

sudo systemctl enable fstrim.timer

7. Application-Specific Tuning

Application Tuning Tips
Web Server (Nginx/Apache)
  • Increase worker processes/threads
  • Enable caching
  • Optimize keepalive settings
Database (MySQL/PostgreSQL)
  • Adjust buffer pool size
  • Optimize query cache
  • Tune innodb_flush_method
Java Applications
  • Optimize JVM heap size
  • Choose appropriate garbage collector
  • Use JIT compiler optimizations

Additional Resources

Important: Always test performance changes in a non-production environment first.
Performance tuning is an iterative process and may require adjustments based on your specific workload and hardware.





Scroll to Top