One of the limits InfinityFree enforces is the CPU limit. This article explains what the CPU limit means and how you can control it.
In the computer you’re reading this on (regardless of whether that’s a PC, laptop, tablet, phone or something else), there is a processor. This processor, or CPU, does all the calculations for all the programs running on your computer. If these programs use too much processor power, your computer will slow down, possibly to the point of being unusable.
The servers hosting your website also have a processor (most of them have multiple). These processors perform many tasks, but they spend most of the time running the programs that execute website (PHP) code. And like with the processor in your own computer, if the programs running on the server use too much processor power, the server will slow down to the point of being unusable.
We want websites to be fast, so we don’t want to have our servers slow down because the processor in them is overloaded.
To prevent this from happening, every hosting account has a limit on how much CPU power it can use. If this limit is hit, the hosting account will first be throttled. And if it still uses too much CPU power, the account is suspended for 24 hours to prevent it from using more CPU power (and prevent further slowdowns to the server).
The method on how CPU usage is calculated, and the values that go into the limit, are classified for multiple reasons:
- The calculations are hard to understand and reason about. Even if you know the CPU limits, you can’t use it to optimize your website or compare hosting providers.
- We want people to not overload the servers. The CPU limit is one of the ways we ensure this, but it’s a means to an end. We don’t want cheaters to try to skirt the limits and use an unfair amount of processing power, and providing exact numbers might help them do that.
That said, the limit works sort-of like “CPU seconds”.
Every time a program executes, it uses a certain percentage of a CPU core for a certain amount of time. If you have five requests which use half a CPU core for three seconds, that’s 5 * 0.5 * 3 = 7.5 CPU seconds. If you increase the number of requests, increase the amount of CPU power each request consumes, or increase the duration during which this power is consumed, then the number of CPU seconds for your account increases.
Every account has a certain limit on CPU seconds per day. If an account uses more CPU seconds than this within a day, it will be suspended for 24 hours.
Additionally, there is a limit on how much CPU power your account can use at a single time. This is done to prevent a short burst of traffic from overloading the servers. The number of times you hit this limit may also be factored into the daily CPU limit.
The exact amount of CPU power an account can use is secret. The reasons for this, as well as an analogy, can be found in the “How is the CPU usage calculated” section above.
It’s impossible to distill a number of visitors from a CPU limit. The CPU limit can limit the number of visitors your website can receive. But there is no way to specify a maximum number of visitors you can receive within a certain CPU allocation. Some of the variables which affect this are:
- The number of pages viewed by the visitor.
- The exact pages being viewed by the visitor.
- The CPU power the server needs to serve the pages being viewed (i.e. website software and configuration).
You may be able to draw conclusions about visitor limits yourself from your CPU usage graphs and your website analytics. But even then, you may find you have very different usage on different days, because your website or your visitors’ behavior has changed.
There is no limit on the number of scripts and plugins you can install based on the CPU limit.
Generally speaking: more scripts and plugins means more code, and more code means more CPU usage. But it depends on many factors, like:
- The traffic to your website. A heavy website with little to no traffic may stay within the limit, but will hit the limit when more pages are being viewed (and more code is executed to render those pages).
- The function and quality of the software. Some software uses a lot of CPU power to work, some software uses very little CPU power to work, and some software may even reduce your over all CPU usage (e.g. caching plugins). Two light weight plugins may consume much less power than one big one.
The short answer is: you probably can’t.
CPU usage is only tracked for the account as a whole. There are no detailed statistics to help narrow down when the usage occurred or which domain, website, software, module or file generates this usage.
The CPU usage metrics on premium hosting are more detailed, and do break down CPU usage by time and process. This information, combined with the server access logging, can be used to narrow down the possible causes for high CPU usage.
But even those additional details can’t clearly tell you which piece of code is responsible for what usage.
A good comparison for the detail in the CPU usage metrics is to open Windows Task Manager (or a similar program available on your computer). In Task Manager, you’ll see a list of programs running on your computer, and the amount of CPU power they use. But you can’t see why the program uses the CPU. If you, for example, see a web browser is using a lot of CPU power, Task Manager can’t see which tab, website or script is responsible. Similarly, we can see that a web process is using a lot of CPU power, but we can’t see which domain, website or script is responsible.
Skilled programmers can use tools like profilers, tracing, Application Performance Monitoring (APM) and other third party tools to dig into the internals of their code and see what it’s doing. But using these tools and interpreting their results is complicated.
There are roughly two major factors which control how much CPU usage your account usage:
- Code complexity: The more code is being executed and the more complicated tasks it needs to perform, the more CPU power is used.
- Website traffic: The more hits your website gets, the more PHP code that needs to be executed to render their pages, which means more CPU power is used.
To make a guess about how much each of these things affects your usage, you should also look at the Daily Hits and Entry Process usage of your account. Are those usages high too? Then it’s probably caused by website traffic. Are these usages low? Then code complexity is the main factor.
Keeping these two aspects in mind, there are a couple of things you can do to reduce your CPU usage.
- Remove unnecessary scripts and plugins. The less code that needs to be executed, the less CPU usage you will need.
- Use caching in your website. Data caching in your website can reduce code execution by reusing the results of other requests.
- Splitting scripts and website to other accounts. If you have multiple domains on the same account, you could move those domains to separate accounts to spread the server load.
The CPU allocation on free hosting cannot be increased upon request. We treat all accounts equally, and will not give people unfair benefits just because they ask for it.
If your CPU usage is still too high after following the recommendations here (or you are having trouble applying the tips to your website), please consider upgrading your account to premium hosting.
With premium hosting, the CPU usage limits are far higher than with free hosting, so your website can continue to grow. Add to that the other great features of premium hosting, like free SSL certificates, Cloudflare RailGun and an award winning cloud hosting platform, and you can be sure your website will stay fast and reliable.
Are you using Cloudflare on your website? If so, you should check the Analytics tab in Cloudflare’s website. When people say they have “no traffic” and they are using Cloudflare, they may have received a wave of bot traffic which caused a lot of CPU usage. Cloudflare’s Analytics system should show this traffic. Website analytics systems, like Google Analytics, probably do not show this traffic, so you should mainly look at Cloudflare’s analytics.
The reason for this is that while Cloudflare implements a security system, it’s not perfect and doesn’t block access to all bots (unlike our own system).
If you are using Cloudflare and urgently need to block such bot traffic, you can enable “I’m under attack” mode which will completely stop such traffic.
Remember that CPU usage is caused by both traffic and code complexity.
Building a website, like installing scripts, importing content and installing plugins and themes are all complex tasks, which require quite a bit of processing power to perform. If you’re doing many changes like that, you can easily generate a lot of CPU usage.
One way to work around that is to do some of your testing on your own computer. By running software like XAMPP or WampServer, you can also run your website on your own computer and try and test everything there. When you’re satisfied with your setup, you can migrate or replicate it on your hosting account.