Performance Tuning & Optimization

⚡⚙️ Bab 21 – SOP Performance Tuning & Optimization di Ubuntu Server

Bab ini akan membuat servermu lebih gesit, efisien, dan hemat resource, sehingga bisa melayani lebih banyak pengguna tanpa harus upgrade hardware terlalu cepat.

๐ŸŽฏ Tujuan

  • Mengoptimalkan performa sistem dan service.
  • Mengurangi penggunaan resource berlebihan.
  • Meningkatkan kecepatan respon server.

๐Ÿ”ง Lingkup

  • Sistem operasi: Ubuntu Server
  • Fokus: CPU, RAM, disk, network, web server (Apache/Nginx), database (MySQL/MariaDB)

3. Langkah Kerja

๐Ÿ”ง 3.1 Optimasi Sistem Dasar

  • Matikan service tidak perlu:
    sudo systemctl disable nama_service
              
  • Gunakan swap dengan bijak:
    sudo swapon --show
              

    Tambahkan swap jika RAM kecil.

  • Optimasi kernel parameter (sysctl):
    Edit /etc/sysctl.conf:
    net.ipv4.tcp_fin_timeout = 15
    net.ipv4.tcp_tw_reuse = 1

    Terapkan:

    sudo sysctl -p
              

๐Ÿ’พ 3.2 Optimasi Disk & File System

  • Gunakan noatime untuk mengurangi penulisan disk:
    Edit /etc/fstab:
    UUID=xxxx / ext4 defaults,noatime 0 1
  • Gunakan tmpfs untuk file sementara:
    tmpfs /tmp tmpfs defaults,noatime,mode=1777 0 0

๐ŸŒ 3.3 Optimasi Web Server

Apache
  • Aktifkan mod_deflate untuk kompresi:
    sudo a2enmod deflate
    sudo systemctl restart apache2
                
  • Aktifkan mod_expires untuk caching:
    sudo a2enmod expires
    sudo systemctl restart apache2
                
  • Atur KeepAlive di /etc/apache2/apache2.conf:
    KeepAlive On
    MaxKeepAliveRequests 100
    KeepAliveTimeout 5
Nginx
  • Aktifkan gzip:
    Edit /etc/nginx/nginx.conf:
    gzip on;
    gzip_types text/plain text/css application/json application/javascript;
  • Atur worker process:
    worker_processes auto;
    worker_connections 1024;

๐Ÿ—„️ 3.4 Optimasi Database (MySQL/MariaDB)

  • Edit /etc/mysql/my.cnf:
    [mysqld]
    innodb_buffer_pool_size = 512M
    query_cache_size = 64M
    max_connections = 200
  • Gunakan mysqltuner untuk rekomendasi optimasi:
    sudo apt install mysqltuner -y
    mysqltuner
              

๐ŸŒ 3.5 Optimasi Network

  • Gunakan iptables atau ufw untuk memblokir trafik tidak perlu.
  • Aktifkan caching DNS lokal:
    sudo apt install dnsmasq -y
              

๐Ÿ“Š 3.6 Monitoring Performa

  • Gunakan htop untuk CPU/RAM.
  • Gunakan iotop untuk disk I/O:
    sudo apt install iotop -y
    sudo iotop
              
  • Gunakan iftop untuk network traffic:
    sudo apt install iftop -y
    sudo iftop
              

4. Command Ringkas

Fungsi Command
Disable service sudo systemctl disable nama_service
Terapkan sysctl sudo sysctl -p
Aktifkan mod_deflate sudo a2enmod deflate
Aktifkan mod_expires sudo a2enmod expires
Restart Apache sudo systemctl restart apache2
Restart Nginx sudo systemctl restart nginx
Install mysqltuner sudo apt install mysqltuner -y
Jalankan mysqltuner mysqltuner
Monitor CPU/RAM htop
Monitor disk I/O sudo iotop
Monitor network sudo iftop

5. Catatan Penting

  • ⚖️
    Optimasi harus sesuai kapasitas hardware, jangan terlalu agresif.
  • ๐Ÿ“Š
    Gunakan monitoring untuk melihat efek optimasi.
  • ๐Ÿงช
    Lakukan uji beban (stress test) sebelum production.
  • ๐Ÿ“
    Simpan dokumentasi perubahan agar mudah rollback jika ada masalah.
๐Ÿ‘‰ Dengan bab ini, servermu sudah bisa berjalan lebih cepat, efisien, dan stabil.

Komentar

Postingan populer dari blog ini

Automation dengan Ansible

Logging & Observability Modern (ELK Stack)

Docker & Container