Tujuan Pembelajaran
Setelah menyelesaikan praktikum ini, mahasiswa mampu:
- Menganalisis bottleneck kinerja sistem Linux
- Mengoptimasi penggunaan CPU, memory, disk I/O, dan network
- Mengkonfigurasi kernel parameters untuk performa optimal
- Mengimplementasikan filesystem dan storage optimization
- Melakukan tuning pada layanan sistem untuk performa maksimal
Teori Pendukung
CPU Optimization
Process scheduling, CPU frequency scaling, affinity settings
Memory Optimization
Swappiness, cache management, hugepages, transparent hugepages
Disk I/O Optimization
Filesystem tuning, I/O schedulers, RAID optimization
Network Optimization
TCP/IP stack tuning, buffer sizes, interface settings
1. Identify Bottleneck
Monitoring melalui tools dan identifikasi sumber masalah
2. Analyze Root Cause
Analisis mendalam penyebab bottleneck
3. Implement Optimization
Penerapan teknik optimasi yang tepat
4. Validate Improvement
Benchmarking dan verifikasi peningkatan performa
5. Monitor Changes
Pemantauan berkelanjutan setelah optimasi
Performance Bottleneck Identification
| Symptom |
Possible Bottleneck |
Diagnosis Tools |
| High CPU load, slow response |
CPU saturation, inefficient code |
top, perf, strace |
| High memory usage, swapping |
Memory leak, insufficient RAM |
free, vmstat, valgrind |
| Slow disk operations |
I/O bottleneck, disk contention |
iostat, iotop, fio |
| Network latency, packet loss |
Network congestion, misconfiguration |
ping, traceroute, netstat |
Persiapan Environment dan Benchmark Baseline
1. Install Tools Optimasi dan Benchmarking
sudo apt update && sudo apt upgrade -y
sudo apt install sysctlutils tuned hdparm iotop ionice stress-ng fio iperf3 -y
sudo apt install linux-tools-common linux-tools-generic cpufrequtils -y
sudo mkdir -p /optimization/{benchmarks,logs,scripts}
sudo chmod 755 /optimization
2. Catat Konfigurasi Sistem Awal
sudo hostnamectl > /optimization/logs/system_info.txt
sudo lscpu >> /optimization/logs/system_info.txt
sudo free -h >> /optimization/logs/system_info.txt
sudo df -h >> /optimization/logs/system_info.txt
sudo sysctl -a | grep -E "(vm|net|kernel)" > /optimization/logs/kernel_params_before.txt
3. Baseline Performance Benchmark
sysbench cpu --cpu-max-prime=20000 run > /optimization/benchmarks/cpu_before.txt
sysbench memory --memory-total-size=2G run > /optimization/benchmarks/memory_before.txt
fio --name=baseline --rw=randrw --bs=4k --size=1G --numjobs=4 --runtime=60s --output=/optimization/benchmarks/disk_before.txt
CPU Performance Optimization
1. Analisis Konfigurasi CPU Saat Ini
lscpu
cat /proc/cpuinfo | grep -E "processor|model name|cache|MHz"
cpupower frequency-info
cat /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors
2. Optimasi CPU Frequency Governor
sudo cpupower frequency-set -g performance
sudo cpupower frequency-set -g conservative
sudo cpupower frequency-set -d 1.0GHz -u 3.0GHz
watch -n 1 'cat /proc/cpuinfo | grep "MHz"'
3. Process Scheduling Optimization
cat /sys/block/sda/queue/scheduler
echo deadline | sudo tee /sys/block/sda/queue/scheduler
echo noop | sudo tee /sys/block/sda/queue/scheduler
echo noop | sudo tee /sys/block/nvme0n1/queue/scheduler
4. CPU Affinity untuk Critical Processes
taskset -cp 0,1 $(pgrep nginx)
taskset -c 0,1 stress-ng --cpu 2 --timeout 30s
taskset -cp $(pgrep nginx)
echo 2 | sudo tee /proc/irq/24/smp_affinity
5. CPU Governor Comparison
| Governor |
Performance |
Power Usage |
Use Case |
| performance |
Maximum |
High |
Servers, high-performance computing |
| ondemand |
Good |
Medium |
Desktop, balanced systems |
| conservative |
Medium |
Low |
Battery-powered devices |
| powersave |
Minimum |
Very Low |
Mobile devices, energy saving |
Memory Optimization
1. Analisis Memory Usage Pattern
cat /proc/meminfo
sudo slabtop -o
ps aux --sort=-%mem | head -10
cat /proc/buddyinfo
cat /proc/pagetypeinfo
2. Optimasi Swappiness
cat /proc/sys/vm/swappiness
echo 10 | sudo tee /proc/sys/vm/swappiness
echo 60 | sudo tee /proc/sys/vm/swappiness
echo 'vm.swappiness=10' | sudo tee -a /etc/sysctl.conf
3. Transparent HugePages Optimization
cat /sys/kernel/mm/transparent_hugepage/enabled
echo never | sudo tee /sys/kernel/mm/transparent_hugepage/enabled
sudo nano /etc/default/grub
# Tambah: transparent_hugepage=never
sudo update-grub
4. Memory Overcommit Settings
cat /proc/sys/vm/overcommit_ratio
cat /proc/sys/vm/overcommit_memory
echo 80 | sudo tee /proc/sys/vm/overcommit_ratio
echo 0 | sudo tee /proc/sys/vm/overcommit_memory
echo 2 | sudo tee /proc/sys/vm/overcommit_memory
5. Memory Management Parameters
| Parameter |
Default |
Optimized |
Description |
| vm.swappiness |
60 |
10 |
Tendency to swap (0-100) |
| vm.dirty_ratio |
20 |
10 |
% memory for dirty pages |
| vm.dirty_background_ratio |
10 |
5 |
% memory for background writes |
| vm.vfs_cache_pressure |
100 |
50 |
Tendency to reclaim cache |
Disk I/O Optimization
1. Filesystem Benchmarking
fio --name=random-write --ioengine=posixaio --rw=randwrite --bs=4k --size=1g --numjobs=1 \
--iodepth=1 --runtime=60 --time_based --end_fsync=1 > /optimization/benchmarks/fio_randwrite.txt
fio --name=sequential-read --ioengine=posixaio --rw=read --bs=1M --size=1g --numjobs=1 \
--iodepth=16 --runtime=60 --time_based > /optimization/benchmarks/fio_seqread.txt
sudo hdparm -Tt /dev/sda
sudo smartctl -a /dev/sda
2. I/O Scheduler Tuning
cat /sys/block/sda/queue/scheduler
echo noop | sudo tee /sys/block/sda/queue/scheduler
echo deadline | sudo tee /sys/block/sda/queue/scheduler
echo 256 | sudo tee /sys/block/sda/queue/nr_requests
sudo nano /etc/udev/rules.d/60-ioschedulers.rules
# ACTION=="add|change", KERNEL=="sd*", ATTR{queue/scheduler}="noop"
3. Filesystem Mounting Options
sudo nano /etc/fstab
# UUID=xxx / ext4 noatime,nodiratime,discard,errors=remount-ro 0 1
# UUID=xxx / ext4 noatime,nodiratime,errors=remount-ro 0 1
# UUID=xxx /var/lib/mysql ext4 noatime,nodiratime,data=writeback 0 2
sudo mount -o remount /
4. RAID Optimization
cat /proc/mdstat
echo 16384 | sudo tee /sys/block/md0/queue/read_ahead_kb
sudo mdadm --detail /dev/md0 | grep "Chunk Size"
sudo /opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -Direct -LAll -a0
sudo /opt/MegaRAID/MegaCli/MegaCli64 -LDSetProp -Cached -LAll -a0
5. I/O Scheduler Comparison
| Scheduler |
Best For |
Advantages |
Disadvantages |
| CFQ |
HDD, Desktop |
Fair queuing, good for multiple processes |
Higher CPU overhead |
| Deadline |
Database, Server |
Guaranteed latency, good for mixed workloads |
Complex implementation |
| NOOP |
SSD, Virtual |
Minimal overhead, simple FIFO |
No prioritization |
| Kyber |
NVMe, Fast SSD |
Modern, latency-based |
New, less tested |
Network Optimization
1. TCP/IP Stack Tuning
sysctl -a | grep tcp
echo 'net.core.rmem_max = 16777216' | sudo tee -a /etc/sysctl.conf
echo 'net.core.wmem_max = 16777216' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_rmem = 4096 87380 16777216' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_wmem = 4096 16384 16777216' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
2. Network Buffer Optimization
echo 'net.core.netdev_max_backlog = 30000' | sudo tee -a /etc/sysctl.conf
echo 'net.core.somaxconn = 1024' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_max_syn_backlog = 2048' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_congestion_control = cubic' | sudo tee -a /etc/sysctl.conf
# Untuk high-speed networks: BBR
echo 'net.ipv4.tcp_congestion_control = bbr' | sudo tee -a /etc/sysctl.conf
3. Network Interface Tuning
ethtool ens33
sudo ip link set ens33 mtu 9000
sudo ethtool -C ens33 rx-usecs 100 tx-usecs 100
sudo ethtool -K ens33 tso on gso on
sudo ethtool -G ens33 rx 4096 tx 4096
4. Network Stack Parameters
| Parameter |
Default |
Optimized |
Description |
| net.core.rmem_max |
212992 |
16777216 |
Max receive buffer size |
| net.core.wmem_max |
212992 |
16777216 |
Max send buffer size |
| net.core.somaxconn |
128 |
1024 |
Max pending connections |
| net.ipv4.tcp_fin_timeout |
60 |
30 |
TCP FIN timeout |
| net.ipv4.tcp_tw_reuse |
0 |
1 |
Reuse TIME_WAIT sockets |
Kernel Parameter Tuning
1. System-wide Kernel Optimization
sudo nano /etc/sysctl.conf
echo '# Performance Optimization' | sudo tee -a /etc/sysctl.conf
echo 'vm.dirty_ratio = 10' | sudo tee -a /etc/sysctl.conf
echo 'vm.dirty_background_ratio = 5' | sudo tee -a /etc/sysctl.conf
echo 'vm.vfs_cache_pressure = 50' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_slow_start_after_idle = 0' | sudo tee -a /etc/sysctl.conf
echo 'net.ipv4.tcp_tw_reuse = 1' | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
2. File Descriptor Limits
ulimit -n
cat /proc/sys/fs/file-max
echo 'fs.file-max = 1000000' | sudo tee -a /etc/sysctl.conf
echo '* soft nofile 1000000' | sudo tee -a /etc/security/limits.conf
echo '* hard nofile 1000000' | sudo tee -a /etc/security/limits.conf
echo 'nginx soft nofile 65536' | sudo tee -a /etc/security/limits.conf
echo 'nginx hard nofile 65536' | sudo tee -a /etc/security/limits.conf
3. Kernel Module Parameters
echo 'elevator=deadline' | sudo tee -a /etc/modprobe.d/i-o.conf
echo 'options tcp_bbr enabled=1' | sudo tee -a /etc/modprobe.d/tcp_bbr.conf
sudo update-initramfs -u
Service-specific Optimization
1. Web Server Optimization (Nginx)
sudo nano /etc/nginx/nginx.conf
worker_processes auto;
events {
worker_connections 1024;
multi_accept on;
use epoll;
}
client_body_buffer_size 10K;
client_header_buffer_size 1k;
client_max_body_size 8m;
large_client_header_buffers 2 1k;
gzip on;
gzip_types text/plain text/css application/json application/javascript;
2. Database Optimization (MySQL)
sudo nano /etc/mysql/my.cnf
innodb_buffer_pool_size = 2G
innodb_log_file_size = 256M
innodb_flush_log_at_trx_commit = 2
query_cache_size = 64M
max_connections = 200
key_buffer_size = 256M
myisam_sort_buffer_size = 64M
3. Application-specific Tuning
sudo nano /etc/php/7.4/fpm/pool.d/www.conf
pm = dynamic
pm.max_children = 50
pm.start_servers = 10
pm.min_spare_servers = 5
pm.max_spare_servers = 15
php_admin_value[memory_limit] = 256M
Automated Tuning dengan Tuned
1. Install dan Konfigurasi Tuned
sudo apt install tuned -y
sudo systemctl enable tuned
sudo systemctl start tuned
2. Pilih Profile yang Sesuai
sudo tuned-adm list
sudo tuned-adm profile throughput-performance
sudo tuned-adm profile latency-performance
sudo tuned-adm profile virtual-guest
sudo tuned-adm profile desktop
3. Custom Tuned Profile
sudo mkdir /etc/tuned/my-custom-profile
sudo nano /etc/tuned/my-custom-profile/tuned.conf
summary=Custom Optimized Profile
governor=performance
energy_perf_bias=performance
transparent_hugepages=never
dirty_ratio=10
dirty_background_ratio=5
elevator=deadline
sudo tuned-adm profile my-custom-profile
Performance Benchmarking dan Validation
1. Comprehensive System Benchmark
stress-ng --cpu 0 --cpu-method matrixprod --metrics-brief --timeout 30s
stress-ng --vm 1 --vm-bytes 1G --timeout 30s --metrics-brief
fio --name=benchmark --rw=randrw --bs=4k --size=1G --numjobs=4 --time_based --runtime=60s
iperf3 -c target_host -t 30 -P 4
2. Before/After Comparison Script
cat > /optimization/scripts/benchmark_compare.sh << 'EOF'
echo "=== BEFORE OPTIMIZATION ===" > /optimization/benchmarks/comparison.txt
sysbench cpu run >> /optimization/benchmarks/comparison.txt
echo "" >> /optimization/benchmarks/comparison.txt
echo "=== AFTER OPTIMIZATION ===" >> /optimization/benchmarks/comparison.txt
sysbench cpu run >> /optimization/benchmarks/comparison.txt
EOF
chmod +x /optimization/scripts/benchmark_compare.sh
Monitoring Post-Optimization
1. Real-time Performance Monitoring
cat > /optimization/scripts/monitor_perf.sh << 'EOF'
while true; do
echo "=== $(date) ==="
echo "CPU: $(top -bn1 | grep "Cpu(s)" | awk '{print $2}')%"
echo "Memory: $(free -h | grep Mem | awk '{print $3"/"$2}')"
echo "Load: $(cat /proc/loadavg | awk '{print $1,$2,$3}')"
echo "I/O: $(iostat -d 1 1 | grep sda | awk '{print $3"kB/s read",$4"kB/s write"}')"
echo "---"
sleep 5
done
EOF
chmod +x /optimization/scripts/monitor_perf.sh
2. Long-term Performance Tracking
sudo sed -i 's/ENABLED="false"/ENABLED="true"/' /etc/default/sysstat
sudo systemctl enable sysstat
sudo systemctl start sysstat
echo "0 6 * * * root /usr/bin/sar -A -o /var/log/sa/sa`date +%d`" | sudo tee -a /etc/crontab
Tugas dan Evaluasi
- Apa perbedaan antara CPU governor "performance" dan "powersave"? Kapan masing-masing sebaiknya digunakan?
- Bagaimana cara menentukan nilai optimal untuk swappiness pada server database vs web server?
- Apa keuntungan menggunakan I/O scheduler "noop" untuk SSD dibandingkan "cfq"?
- Bagaimana cara mengidentifikasi bottleneck antara CPU, memory, disk I/O, dan network?
- Buat skenario: Server database mengalami kinerja lambat. Tulis langkah-langkah optimasi sistematis yang akan dilakukan!
Case Study: E-commerce Server Optimization
echo "Starting e-commerce server optimization..."
cpupower frequency-set -g performance
echo "performance" | tee /sys/devices/system/cpu/cpu*/cpufreq/scaling_governor
echo 10 > /proc/sys/vm/swappiness
echo "never" > /sys/kernel/mm/transparent_hugepage/enabled
echo "noop" > /sys/block/sda/queue/scheduler
echo 256 > /sys/block/sda/queue/nr_requests
echo 'net.core.somaxconn = 2048' >> /etc/sysctl.conf
echo 'net.ipv4.tcp_tw_reuse = 1' >> /etc/sysctl.conf
echo 'net.core.rmem_max = 16777216' >> /etc/sysctl.conf
sysctl -p
echo "Optimization completed. Please reboot for full effect."