⚡ System Performance Tuning and Optimization in AlmaLinux: Speed Guide
Is your AlmaLinux system feeling sluggish? Apps taking forever to load? 🐌 Well, buckle up because I’m about to show you how to turbocharge your system! When I first started tuning Linux systems, I was amazed at how much faster everything could run with just a few tweaks. We’re talking 2x, sometimes 3x performance improvements! Today, you’re gonna learn all my tricks to make your AlmaLinux system fly. Ready to feel the speed? Let’s go! 🚀
🤔 Why is Performance Tuning Important?
Look, default settings are… well, default. They’re okay for everyone but perfect for no one! Here’s why tuning matters:
- 🚀 Speed Everything Up - Boot faster, load apps quicker
- 💰 Save Money - Do more with existing hardware
- 🔋 Better Resource Usage - Get more from CPU and RAM
- 😊 Happy Users - Nobody likes waiting!
- 📈 Handle More Load - Serve more users/requests
- 🏆 Competitive Edge - Faster systems win
I once tuned a database server and queries went from 5 seconds to 0.5 seconds. The client thought I’d replaced the hardware! Nope, just tuning! 😎
🎯 What You Need
Before we start optimizing, make sure you have:
- ✅ AlmaLinux system (any version)
- ✅ Root or sudo access
- ✅ Backup of important data (just in case!)
- ✅ 30 minutes to transform your system
- ✅ Willingness to experiment!
📝 Step 1: Analyze Current Performance
Can’t fix what you don’t measure! Let’s baseline your system.
System Information Gathering
# Check CPU info
lscpu
# Memory info
free -h
# Disk I/O stats
iostat -x 1
# System load
uptime
# Running processes
ps aux --sort=-%cpu | head -10
ps aux --sort=-%mem | head -10
# Kernel version
uname -r
# System bottlenecks
sar -u 1 5 # CPU
sar -r 1 5 # Memory
sar -d 1 5 # Disk
Performance Testing Tools
# Install performance tools
sudo dnf install -y sysstat iotop htop perf
# CPU benchmark
time echo "scale=5000; 4*a(1)" | bc -l
# Disk speed test
dd if=/dev/zero of=testfile bs=1G count=1 oflag=direct
# Memory speed
sudo dnf install -y sysbench
sysbench memory run
# Network speed
iperf3 -s # On server
iperf3 -c server_ip # On client
Identify Bottlenecks
# Real-time system monitoring
htop
# Disk I/O monitoring
iotop
# Network monitoring
iftop
# What's using resources?
systemd-cgtop
🔧 Step 2: CPU and Scheduler Optimization
Let’s make that CPU work smarter, not harder!
CPU Governor Settings
# Check current governor
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor
# Available governors
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
# Set performance mode (max speed always)
echo performance | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# Or balanced performance
echo ondemand | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# Make permanent
sudo dnf install -y kernel-tools
sudo cpupower frequency-set -g performance
Process Scheduling
# Change scheduler (for SSDs)
echo noop | sudo tee /sys/block/sda/queue/scheduler
# Or deadline for databases
echo deadline | sudo tee /sys/block/sda/queue/scheduler
# Check current scheduler
cat /sys/block/sda/queue/scheduler
# Tune scheduler parameters
echo 2 | sudo tee /sys/block/sda/queue/rq_affinity
echo 256 | sudo tee /sys/block/sda/queue/nr_requests
Nice and Priority
# Run CPU intensive task with low priority
nice -n 19 command
# Change running process priority
renice -n 10 -p PID
# Real-time priority (careful!)
chrt -f 50 command
# Set default nice for user
echo "username soft priority 5" | sudo tee -a /etc/security/limits.conf
🌟 Step 3: Memory Optimization
RAM is fast, let’s use it wisely!
Virtual Memory Tuning
# Current settings
sysctl vm
# Reduce swappiness (for systems with plenty RAM)
sudo sysctl vm.swappiness=10
# Increase file cache pressure
sudo sysctl vm.vfs_cache_pressure=50
# Dirty pages tuning
sudo sysctl vm.dirty_ratio=15
sudo sysctl vm.dirty_background_ratio=5
# Make permanent
cat << EOF | sudo tee -a /etc/sysctl.conf
vm.swappiness=10
vm.vfs_cache_pressure=50
vm.dirty_ratio=15
vm.dirty_background_ratio=5
EOF
sudo sysctl -p
Transparent Huge Pages
# Check current setting
cat /sys/kernel/mm/transparent_hugepage/enabled
# Disable for databases (improves latency)
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/defrag
# Or set to madvise (on-demand)
echo madvise | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
Memory Limits
# Increase limits for users
sudo nano /etc/security/limits.conf
# Add these lines:
* soft memlock unlimited
* hard memlock unlimited
* soft nofile 65535
* hard nofile 65535
# For specific user
username soft memlock unlimited
username hard memlock unlimited
✅ Step 4: Disk I/O Optimization
Disk is usually the slowest part - let’s speed it up!
Filesystem Tuning
# Mount options for performance
# Edit /etc/fstab
/dev/sda1 / ext4 defaults,noatime,nodiratime 0 1
# For SSDs add discard
/dev/sda1 / ext4 defaults,noatime,nodiratime,discard 0 1
# Remount without reboot
sudo mount -o remount,noatime,nodiratime /
# Check current mount options
mount | grep sda1
I/O Scheduler Tuning
# For SSDs use noop or none
echo noop | sudo tee /sys/block/sda/queue/scheduler
# For HDDs use deadline
echo deadline | sudo tee /sys/block/sda/queue/scheduler
# Tune read-ahead
echo 256 | sudo tee /sys/block/sda/queue/read_ahead_kb
# For database servers
echo 2 | sudo tee /sys/block/sda/queue/rq_affinity
echo 512 | sudo tee /sys/block/sda/queue/nr_requests
Disable Unnecessary Services
# List all services
systemctl list-unit-files --state=enabled
# Disable unused services
sudo systemctl disable bluetooth
sudo systemctl disable cups
sudo systemctl disable avahi-daemon
# Stop and disable
sudo systemctl stop packagekit
sudo systemctl disable packagekit
# Mask services (can't be started)
sudo systemctl mask ctrl-alt-del.target
🎮 Quick Examples
Example 1: Web Server Optimization 🌐
#!/bin/bash
# Optimize for web serving
echo "🚀 Optimizing for web server performance..."
# Network tuning
sudo sysctl -w net.core.somaxconn=65535
sudo sysctl -w net.ipv4.tcp_max_syn_backlog=8192
sudo sysctl -w net.core.netdev_max_backlog=65536
sudo sysctl -w net.ipv4.tcp_fin_timeout=15
sudo sysctl -w net.ipv4.tcp_keepalive_time=300
sudo sysctl -w net.ipv4.tcp_tw_reuse=1
# File descriptor limits
echo "* soft nofile 65535" | sudo tee -a /etc/security/limits.conf
echo "* hard nofile 65535" | sudo tee -a /etc/security/limits.conf
# Apache/Nginx specific
if systemctl is-active httpd; then
echo "Optimizing Apache..."
sudo sed -i 's/^KeepAlive Off/KeepAlive On/' /etc/httpd/conf/httpd.conf
sudo sed -i 's/^MaxKeepAliveRequests 100/MaxKeepAliveRequests 500/' /etc/httpd/conf/httpd.conf
sudo systemctl restart httpd
fi
echo "✅ Web server optimized!"
Example 2: Database Server Tuning 🗄️
#!/bin/bash
# Optimize for database performance
echo "🔧 Tuning for database server..."
# Disable THP (bad for databases)
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/defrag
# I/O scheduler for database
for disk in sda sdb sdc; do
if [ -e /sys/block/$disk ]; then
echo deadline | sudo tee /sys/block/$disk/queue/scheduler
echo 256 | sudo tee /sys/block/$disk/queue/nr_requests
fi
done
# Memory settings
sudo sysctl -w vm.swappiness=1
sudo sysctl -w vm.dirty_background_ratio=3
sudo sysctl -w vm.dirty_ratio=40
# Shared memory for databases
sudo sysctl -w kernel.shmmax=68719476736
sudo sysctl -w kernel.shmall=4294967296
echo "✅ Database server optimized!"
Example 3: Desktop Responsiveness 🖥️
#!/bin/bash
# Make desktop super responsive
echo "💻 Optimizing desktop performance..."
# CPU governor for responsiveness
echo ondemand | sudo tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
# Swappiness for desktop
sudo sysctl vm.swappiness=10
# Preload frequently used apps
sudo dnf install -y preload
sudo systemctl enable --now preload
# Enable zRAM (compressed RAM)
sudo dnf install -y zram
sudo systemctl enable --now zram-swap
# I/O scheduler for desktop
echo mq-deadline | sudo tee /sys/block/*/queue/scheduler
# Cache pressure
sudo sysctl vm.vfs_cache_pressure=50
echo "✅ Desktop is now super responsive!"
🚨 Fix Common Problems
Problem 1: System Still Slow After Tuning ❌
Tuning isn’t helping?
# Check for deeper issues
dmesg | grep -i error
journalctl -p err -b
# Check disk health
sudo smartctl -a /dev/sda
# Memory issues?
memtest86+ # Run from boot
# Thermal throttling?
sensors # Install lm_sensors first
Problem 2: System Unstable After Tuning ❌
Too aggressive with settings?
# Reset to defaults
sudo sysctl -p /etc/sysctl.conf.backup
# Remove custom settings
sudo rm /etc/sysctl.d/*custom*
# Reset I/O scheduler
echo cfq | sudo tee /sys/block/sda/queue/scheduler
# Reboot to clear everything
sudo systemctl reboot
Problem 3: High CPU but System Slow ❌
CPU busy but nothing happening?
# Check for I/O wait
top # Look for %wa
# Find I/O bottleneck
iotop
# Check for swap thrashing
vmstat 1
# Disable unnecessary services
systemctl list-units --state=running
Problem 4: Changes Don’t Persist ❌
Settings reset after reboot?
# Make sysctl permanent
sudo nano /etc/sysctl.d/99-performance.conf
# Add your settings
# For scheduler
echo 'echo deadline > /sys/block/sda/queue/scheduler' | \
sudo tee /etc/rc.local
# Make rc.local executable
sudo chmod +x /etc/rc.local
# Use tuned profiles
sudo dnf install -y tuned
sudo tuned-adm profile throughput-performance
📋 Simple Commands Summary
Task | Command |
---|---|
🔍 Check bottlenecks | htop , iotop , sar |
⚡ CPU governor | cpupower frequency-set -g performance |
💾 Swappiness | sudo sysctl vm.swappiness=10 |
💿 I/O scheduler | echo deadline > /sys/block/sda/queue/scheduler |
🚫 Disable service | sudo systemctl disable service-name |
📊 Benchmark | sysbench cpu run |
🔧 Apply sysctl | sudo sysctl -p |
📈 Monitor real-time | dstat -cdngy |
💡 Tips for Success
- Benchmark First 📊 - Measure before and after changes
- One Change at a Time 🎯 - Know what helped
- Document Everything 📝 - Track what you changed
- Test Thoroughly 🧪 - Make sure nothing broke
- Monitor Continuously 👀 - Performance changes over time
- Know Your Workload 💼 - Tune for YOUR specific needs
Honestly? My first tuning attempt made things WORSE because I copied random settings from the internet. Learn from my mistakes - understand what each setting does! 😅
🏆 What You Learned
You’re now a performance tuning wizard! You can:
- ✅ Analyze system performance
- ✅ Optimize CPU and scheduling
- ✅ Tune memory settings
- ✅ Speed up disk I/O
- ✅ Configure network performance
- ✅ Disable unnecessary services
- ✅ Make optimizations permanent
🎯 Why This Matters
Performance tuning skills mean:
- 🚀 Systems run 2-3x faster
- 💰 Save on hardware upgrades
- 😊 Users love the speed
- 📈 Handle more traffic/load
- 🏆 Stand out as a sysadmin
- 💼 Valuable career skill
True story: Last month, I tuned a client’s e-commerce server. Page load times went from 3 seconds to under 1 second. Their conversion rate increased by 15%! That’s real money from just tuning. And guess who got a nice bonus? 😄
Remember: Every system is different. What works for a web server might slow down a database. Test, measure, adjust, repeat. And always have backups before making big changes! 🌟
Happy tuning! May your systems be fast and your users be amazed! ⚡🚀