Load Investigation

This guide is for CentOS 7 using cPanel. The principles may apply to other set ups. 

curl -O
chmod +x

Things to look at:
Disk IO

- MYSQL queries
- PHP scripts

- PHP setting own memory limits

Disk IO:
Usually OOM issues, when server is using swap as RAM.

1. Searching for information:

- Basic info
echo -e "\nHostname: $(hostname)"; echo "vCPU Count: $(nproc)"; echo; w; echo; echo "Disk space:"; df -h; echo; echo "Memory consumption:"; echo; free -mht

- Uptime:
[root@mramirez ~]# uptime
 23:14:36 up 15 days,  7:26,  1 user,  load average: 0.02, 0.02, 0.05

[root@mramirez ~]# nproc

- Past loads, in this example load for day 22 of the month:
[root@mramirez ~]# sar -q -f /var/log/sa/sa22>output

- Current loads:
[root@mramirez ~]# sar -q>output

-Glance Visual representation of the load:
[root@mramirez ~]# yum install glances
[root@mramirez ~]# glances

- Swap memory used (under 40% is usually OK): Not much of a problem, because system caches a lot of things for better performance.
[root@mramirez ~]# sar -S| awk '{ print $1"    " $4 }'
First 3 lines and last 50
[root@mramirez ~]# sar -S -f /var/log/sa/sa22|( head -n 3 && tail -n 50)|awk '{ print $1"    " $4 }'>output

-Disk I/O usage. Device  saturation occurs when this value is close to 100%. We can determine a MYSQL issue here.
[root@mramirez ~]# sar -d| awk '{ print $1"    " $2"    "$10 }'
First 3 lines and last 50
[root@mramirez ~]# sar -d -f /var/log/sa/sa22|( head -n 3 && tail -n 50)|awk '{ print $1"    " $2"    "$10 }' > output 

- Memory limit x MaxRequestWorkers should not exceed server's memory.
[root@mramirez ~]# cat /etc/apache2/conf/httpd.conf|grep -ai "MaxRequestWorkers"
MaxRequestWorkers 100
[root@mramirez ~]# cat /opt/cpanel/ea-php74/root/etc/php.ini|grep -ia "memory_limit" (/opt/remi/php56/root/etc)
memory_limit = 16M
Max memory PHP can allocate: 100 x 16 = 1600M = 1.6G | server's memory should be higher than this value + some space for other processes. Memory limit should be set as low as possible for the sites to work. Once we have a good value for the global memory_limit we can go through and increase it for individual scripts, entire folders, or entire accounts as needed.

Mem/RAM usage
[root@mramirez ~]# ps faux | grep -i ^mysql
Disk I/O wait. If you are not seeing high IO WAIT or swap usage, then DISK IO is more than likely not an issue.
[root@mramirez ~]# sar -s

-Total Index Sizes by Engine
Set innodb_buffer_pool_size based on the sum of 'ibd' and 'ibdata1', and set key_buffer_size based on the total listed for 'MYI'.

[root@mramirez ~]# mysql -Bse 'show variables like 
"datadir";'|awk '{print $2}'|xargs -I{} find {} -type f -printf "%s %f\n"|awk -F'[ ,.]' '{print $1, $NF}'|awk '{array[$2]+=$1} END {for (i in array) {printf("%-15s %s\n", sprintf("%.3f MB", array[i]/1048576), i)}}' | egrep '(MYI|ibd)'
0.143 MB        MYI
37.375 MB       ibd
76.000 MB       ibdata1
A good value for key_buffer_size would be 4MB and for 
innodb_buffer_pool_size 128MB. For better values: -MYISAM mysql -e "show global status like '%key_read%';" A sign of excellent key_buffer performance will be a ratio of 1:100 for key_reads:key_read_requests. If you find this ration lower than 1:100, this is an indicator that MySQL performance could be increased by raising the value of the key_buffer setting. RATIO: a:b - a/a:b/a (to get ratio relative to 100). -INNODB mysql -e "show global status like '%innodb_buffer_pool_read%';" An indicator or good innodb_buffer_pool performance is a ration of
RATIO: a:b - a/a:b/a (to get ratio relative to 100).

- Mysql memory limit:
cat /etc/my.cnf|grep -ai "max_allowed_packet"|cut -d "=" -f 2
- PHP memory limit
- Swap Size
- Activate piped log
grep Graceful /usr/local/apache/logs/error_log
In WHM > apache config

Use mr radar to see patterns in the load spikes.

ps faux


That’s all folks, see you  later!

Leave a Reply

Your email address will not be published. Required fields are marked *