How We Manage Resources on Shared Hosting using CloudLinux

web resource usage

What is CloudLinux?

CloudLinux is a commercially supported Linux operating system interchangeable with CentOS. It includes kernel level technology called LVE that allows you to control CPU and memory on per tenant bases. It is a basis for application level virtualisation. CloudLinux delivers advanced resource management, better security and performance optimizations specifically targeted to multi-tenant hosting environment. This improved performance helps hosting service providers and datacenters provide better support to their customers, reduce churn and save money. More information on What is CloudLinux at http://www.cloudlinux.com/

How does CloudLinux assist us in managing server resource usage?

Hosting accounts that are overusing (a.k.a. abusing) server resources will find their service automatically suspended, which reduces the overall effects of resource abuse on customers. This is achieved through rate limiting, whereby a website approaching its individual usage limit will cause an impact to the speed of the site. When the total number of entry processes (apache/http requests) for the account reaches the limit, website visitors will experience an error message “503 Service Unavailable”, indicating that the account has exceeded its resource allocation.

When the website falls back beneath its limit, the site will resume function. With majority of resource abuse on cPanel coming from hacked or illegitimate websites, this update will prevent service availability problems for maintained legitimate customer websites.

Will this change cause limitations to legitimate websites?

It is possible that a legitimate website may experience the limitations due to the service being hacked. If you experience a “503 Service Unavailable” error, you should contact Hostking Support to see if your website has been hacked, and to discuss options around restoration and/or fix it.

Checking your current resource usage

Customers can determine their website resource status through monitoring of their cPanel logs. Under the “Logs” heading inside cPanel, you will find a “Resource Usage” icon. Clicking on this icon and reviewing the percentages of each resource used will give clear indication whether the website is abusing resources. In this same section cPanel will offer advice on what steps to take to correct potential issues causing the resource abuse. To access “Resource Usage” in cPanel:

  1. Login to the Client Area
  2. Click to Services then My Service and then View Details on the domain name in question
  3. Click Login to CPANEL
  4. Scroll down to Logs
  5. Click Resource Usage

For Resellers

  1. Login to the Client Area
  2. Click to Services then My Service and then View Details on the domain name in question
  3. Click Login to CPANEL then click WHM icon
  4. Go to “List Accounts” and find the domain name
  5. Open the domain’s cPanel by clicking the cPanel Icon
  6. Scroll down to Logs
  7. Click Resource Usage

How to setup FastCGI Settings for Shared Hosting

php-fastcgi-fpm-et-apache_reference

There are tons of articles on how to optimize FastCGI setup. Yet, all of them talk about settings for a single site. The situation is much different in shared web hosting, where there are hundreds of sites running. Understanding & optimizing mod_fcgid settings can make a difference between fast and stable PHP hosting and frequent 503 & 500 errors. Unlike suPHP that executes new PHP process for each request, FCGID starts a bunch of processes per customer, and re-uses them for each PHP request.

mod_fcgid is an option in majority of hosting control panels, yet most of the control panels don’t alter default settings. And the default settings in mod_fcgid are made for a single site. You can find more info on mod_fcgid settings here:
http://httpd.apache.org/mod_fcgid/mod/mod_fcgid.html

When setting up mod_fcgid, you should care about several configuration options:
FcgidMinProcessesPerClass — should always be 0
“PerClass” means per user in shared hosting, and 0 means that there might be no processes for a particular user, if that user is not active.
FcgidMaxProcessesPerClass — default 100, this means that a single customer can have 100 php requests served at the same time. Which in turn means there will be 100 PHP processes just for that user. This is way to high for shared hosting. I would recommend values anywhere from 8 to 20. Note: if more requests comes in at the same time, they will be queued, and not rejected.
FcgidMaxProcesses — this is the total number of processes FCGID will start, for all users. That is what will prevent OOM issues. The more RAM you have, the higher you can set the value.
If you set this value too low, you will get 500 errors, as FCGID will not be able to create new processes to serve requests. This value also depends on the size of PHP processes (which in turn depends on extensions that you have enabled for PHP) as the larger the process the faster you will him OOM. You can try playing with following numbers depending on your RAM: 8GB — about 150, 16GB – 300
Also, make sure you monitor apache error logs. If you see “can’t apply process slot for error” — it means you are hitting FcgidMaxProcesses
FcgidIdleTimeout — default 300, number of seconds process would stay idle until it gets killed. The higher the number, the lower CPU usage, and the higher the chance of hitting FcgidMaxProcesses limit (as processes live longer). I would recommend putting it at 60 at first
FcgidIdleScanInterval — this should be adjusted as well, to about a half of what FcgidIdleTimeout is set.
FcgidProcessLifeTime: default – 1 hour, should be — anywhere from 120 seconds to 300 seconds (double idle time). It is there to make sure that processes do get killed after some time, if they are not busy (even for short periods of time).
The shorter idle timeout/process life time, the less chance that you will hit FcgidMaxProcesses limit, but the more load you will put on the system.

Most values can be same from server to server, but you might want to change FcgidMaxProcesses depending on the amount of RAM you have.

Example FCGID settings for shared hosts:
FcgidMinProcessesPerClass 0
FcgidMaxProcessesPerClass 8
FcgidMaxProcesses 150
FcgidIdleTimeout 60
FcgidProcessLifeTime 120
FcgidIdleScanInterval 30

This article was written by CloudLinux. Please view their website at http://www.cloudlinux.com