CloudLinux allocates a shared resource quota (LVE) to every hosting account. Everything associated with the account runs within this quota: the website’s PHP requests, cron jobs, commands run via SSH or the cPanel terminal, as well as Node.js and Python applications. You can find the limits applicable to your plan in the article detailing the resource limits for hosting plans.
What does this mean in practice?
Cron jobs and SSH sessions use the same resources as the website:
- CPU, memory, I/O: if a cron job (such as an import, image resizing or backup) uses up the account’s entire CPU or disk quota, the website will respond more slowly in the meantime.
- Concurrent connections (EP): every running cron job and SSH session takes up one slot in the concurrent connections quota. If many cron jobs are running at the same time, there is less capacity left for visitors, and a 508 error may occur.
- Number of processes (NPROC): processes running as cron jobs and programs launched via SSH are also counted towards the account’s process limit.
Processes started using the nice or ionice commands also remain within the account; these commands do not allocate any additional resources.
Common issues
- Overlapping cron jobs: if a job scheduled to run every minute takes longer than one minute to complete, the next instance starts before the previous one has finished. Within a few minutes, dozens of instances are running simultaneously, and the account reaches its limits.
- Demanding tasks at peak times: a large import or backup running during the day slows down the website just when it has the most visitors.
- WordPress’s built-in cron job –
wp-cron.php– runs during page views, so background tasks run alongside visitors’ requests.
Best practices
- Schedule resource-intensive tasks for the night, during off-peak hours. The process of setting up cron jobs is described in the article on creating cron jobs in cPanel, whilst the timing format is explained in the article on crontab syntax.
- Do not run tasks unnecessarily frequently. If running them once an hour is sufficient, do not set them to run every minute.
-
Prevent overlapping. The
flockcommand ensures that only one instance of a task runs at a time. If the previous instance is still running, the new instance will not even start:flock -n $HOME/.cron-import.lock php $HOME/scripts/import.php - Replace WordPress’s cron job with a genuine cron job; see: How do I replace WordPress’s built-in cron job with cPanel scheduled tasks?
- Close any unused SSH sessions and do not leave any programs running in the background.
- Break large tasks down into smaller parts. Importing a file containing several thousand items in smaller batches, one after the other, puts less strain on the account.
You can check whether a cron job is causing the limits to be reached on the cPanel Resource Usage page. If the errors always occur at the same time, or if the cron job command is visible on the Snapshot tab, then the job is to blame. See: What do the fault counters mean on the Resource Usage page?