{"id":57337,"date":"2020-09-18T11:54:11","date_gmt":"2020-09-18T16:54:11","guid":{"rendered":"https:\/\/blog.cpanel.com\/?p=57337"},"modified":"2020-09-18T11:54:11","modified_gmt":"2020-09-18T16:54:11","slug":"troubleshooting-high-server-loads","status":"publish","type":"post","link":"https:\/\/devel.www.cpanel.net\/blog\/tips-and-tricks\/troubleshooting-high-server-loads\/","title":{"rendered":"Troubleshooting High Server Loads"},"content":{"rendered":"\n
One of the more ambiguous, but oft-seen, errors resulting in support tickets is related to high server loads. While high server load errors are virtually never caused by the cPanel software itself or the apps it installs, these errors can certainly carry a degree of frustration. Given that the range of causes are not specified within the error itself, a degree of investigation is required.<\/p>\n\n\n\n
Generally speaking, this investigation will need to be done by the server owner, their system administrator, or the server provider due to the necessary level of access that may be required.<\/p>\n\n\n\n
The vast majority of high server load errors are caused by an excessive or persistent utilization of one, or a combination, of the following system resources:<\/p>\n\n\n\n
All of these resources work concurrently to ensure the proper functioning of any computer; a web server is no exception. If any process running on the machine causes one of the aforementioned to exceed its normal parameters, or otherwise prevent it from returning to normal limits within an acceptable amount of time, the result is often a high server load error. <\/p>\n\n\n\n
Imagine putting the pedal to the metal in a car for too long, causing one of the systems within the engine to exceed its operational limits, but fortunately in this case we get an error instead of a fire. The principle is the same though: a machine has simply been pushed past its limit. <\/p>\n\n\n\n
Before proceeding, it is important to determine whether you want to go down the path of discovering the current resource usage or rather to review the historical usage from a specific date or time. The former would be necessary to resolve an issue occurring in real time, while the latter would be a forensic investigation as to what caused a prior issue. For the sake of checking every box, we will cover both scenarios below. <\/p>\n\n\n\n
Historical resource usage can be viewed using the \u201csar\u201d utility, which should exist by default on all cPanel servers from the sysstat package. Statistics are collected when sysstat runs via cron (\/etc\/cron.d\/sysstat). If crond is not running, sysstat will not be able to collect this historical data.<\/p>\n\n\n\n
To view resource usage with sar, you must provide the path to the file that corresponds to the date in question. For example, if you wanted to view the load averages for your server from the 23rd of the month, you would run this command:<\/p>\n\n\n\n
[user@host ~]$ sar -q -f \/var\/log\/sa\/sa23<\/code><\/pre>\n\n\n\nThe above command above ‘-q’ to obtain the load average information, and ‘-f’ to specify from which sar file to obtain the information. Keep in mind that sar may not have historical data going back more than a week or so.<\/p>\n\n\n\n
You do not need to specify the date when viewing the statistics for the current day. As such, this command would show the load average for today:<\/p>\n\n\n\n
[user@host ~]$ sar -q<\/code><\/pre>\n\n\n\nAs with any command with which you are unfamiliar, it is always advisable to read the documentation:<\/p>\n\n\n\n
[user@host ~]$ man sar<\/code><\/pre>\n\n\n\nCurrent CPU Usage<\/strong><\/p>\n\n\n\nThe real-time CPU usage can be viewed by running the \u201ctop\u201d command. On the line that says \u201cCpu(s),\u201d check the \u201c%id\u201d section to see the percentage at which your CPUs are idle; the higher the number, the better. A 99% idle CPU is doing almost nothing, whereas a 1% idle CPU is heavily tasked at that moment.<\/p>\n\n\n\n
[user@host ~]$ top c<\/code><\/pre>\n\n\n\nTip: hit “P” to sort by processes that are currently consuming the most CPU.<\/p>\n\n\n\n
Historical CPU Usage<\/strong><\/p>\n\n\n\nAs noted above, we will use the \u201csar\u201d command to view the historical statistics. The command is otherwise virtually the same, being sure to check the \u201c%idle\u201d column:<\/p>\n\n\n\n
[user@host ~]$ sar -p<\/code><\/pre>\n\n\n\nCurrent RAM Usage<\/strong><\/p>\n\n\n\nTo view how much memory the server currently has unutilized, or free, use the \u201cfree\u201d command:<\/p>\n\n\n\n
[user@host ~]$ free -m<\/code><\/pre>\n\n\n\nTip: run “top c” and hit “M” to see which processes are consuming the most memory.<\/p>\n\n\n\n
Historical RAM Usage<\/strong><\/p>\n\n\n\nOne thing to note when checking the historical memory usage is that the version of sar being used will determine the specific command. Older versions of sar used \u2018-r\u201d to show both %memused and %swpused (swap memory used), but more current versions of sar require the additional use of \u2018-S\u2019 to show %swpused:<\/p>\n\n\n\n
[user@host ~]$ sar -r<\/code><\/pre>\n\n\n\nOR:<\/p>\n\n\n\n
[user@host ~]$ sar -r\n[user@host ~]$ sar -S<\/code><\/pre>\n\n\n\n<\/p>\n\n\n\n
Current Disk I\/O Usage<\/strong><\/p>\n\n\n\nThe final resource to investigate when determining high server load errors is the overall read and write activity of the hard drive itself. The following command will display the disk usage statistics ten times each second. Note that the following commands will not work on OpenVZ\/Virtuozzo containers:<\/p>\n\n\n\n
[user@host ~]$ iostat -x 1 10<\/code><\/pre>\n\n\n\nHistorical Disk I\/O Usage<\/strong><\/p>\n\n\n\nAs with the the above examples, we use the sar command:<\/p>\n\n\n\n
[user@host ~]$ sar -d<\/code><\/pre>\n\n\n\nAn Ounce of Prevention<\/strong><\/h3>\n\n\n\nAt the end of the day, your best defense will always be a good offense. With that in mind, remember that good system administration includes keeping an eye on your server resources and being aware of any unusual increase in utilization before it actually becomes a problem.<\/p>\n\n\n\n