Lakukan pengecekan beban memory yang dihasilkan oleh php-fpm dan apache/nginx
Server saya memiliki RAM 16GB dan 4 CPU 2,4GHz.
1. Menghitung Process Size
#cd ~
#wget https://raw.githubusercontent.com/pixelb/ps_mem/master/ps_mem.py
#chmod a+x ps_mem.py
#python ps_mem.py
Bisa dilihat bahwa apache2 menjalankan 30 process dan memakan memory 139MiB, jadi total per process nya itu 139/30 = 4.63 atau dibulatkan menjadi 5Mib RAM dan 7 Process php-fpm 352/7 = 51Mib RAM
2. Menghitung apache MaxRequestWorkers
untuk menghitung process lainnya yang digunakan untuk Linux 15% memory, untuk kasus ini saya ambil 2,4Gib dan Process Apache 5Mib
MaxRequestWorkers = (Total RAM - Memori yang digunakan untuk Linux, DB, dll.) / ukuran proses
MaxRequestWorkers = (16384MB - 2400MB) / 5MB = 2800
3. Menghitung php-fpm max-children
3. Menghitung php-fpm max-children
maxclients = (Total RAM - Memori yang digunakan untuk Linux, DB, dll.) / ukuran proses
maxclients = (16384MB - 2400MB) / 51MB = 274
4. Menghitung pm.start.server, pm.min.spare.servers, pm.max.spare.server
pm = dinamis
pm.start_servers (cpu cores * 4) = 16
pm.min_spare_servers (cpu cores * 2) = 8
4. Menghitung pm.start.server, pm.min.spare.servers, pm.max.spare.server
pm = dinamis
pm.start_servers (cpu cores * 4) = 16
pm.min_spare_servers (cpu cores * 2) = 8
pm.max_spare_servers (cpu cores * 4) = 16
pm.max_requests 1000
5. Setup mpm_worker.conf atau mpm_event.conf
edit file etc/apache2/mods-enabled/mpm_event.conf atau /etc/apache2/mods-enabled/mpm_worker.conf
5. Setup mpm_worker.conf atau mpm_event.conf
edit file etc/apache2/mods-enabled/mpm_event.conf atau /etc/apache2/mods-enabled/mpm_worker.conf
<IfModule mpm_*_module>
ServerLimit (Total RAM - Memory used for Linux, DB, etc.) / process size
StartServers (Number of Cores)
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers (Total RAM - Memory used for Linux, DB, etc.) / process size
MaxConnectionsPerChild 1000
</IfModule>
Jadi setingan terakhir nya seperti ini :
untuk apache
Jadi setingan terakhir nya seperti ini :
untuk apache
/etc/apache2/mods-available/mpm_event.conf
# Optimized settings for avg. apache process 15MB and AWS EC2 m4.xlarge Server
<IfModule mpm_event_module>
ServerLimit 2800
StartServers 4
MinSpareThreads 25
MaxSpareThreads 75
ThreadLimit 64
ThreadsPerChild 25
MaxRequestWorkers 2800
MaxConnectionsPerChild 1000
</IfModule>
Untuk php-fpm
/etc/php/5.6/fpm/pool.d/www.conf
Untuk php-fpm
/etc/php/5.6/fpm/pool.d/www.conf
; Optimized for php-fpm request size of 55MB on AWS EC2 m4.xlarge (4CPU cores, 16GB RAM)
pm = dynamic
pm.max_children = 274
pm.start_servers = 16
pm.min_spare_servers = 8
pm.max_spare_servers = 16
pm.max_requests = 1000
Terakhir Restart apache dan php-fpm nya
Terakhir Restart apache dan php-fpm nya
sudo service apache2 restart
0 Comments