How many CPU cores do I need for my VPS?

“How can I improve speed of my WordPress site and will adding more CPU cores help?”

question I am being frequently asked

Quick answer is “yes” and “no”.

Just as many other things, especially in IT – correct answer depends on your needs and workload. But you should understand the following concept, which is the core for the right decision.

PHP is single threaded. One request processing uses one CPU core for PHP code processing. Database engine, external cache and webrequest handling are not included into term “PHP code processing”.

From the statement above I would say – that for a successful start with least delay on CPU level – you want to have 2 core CPU for your server. More than that you might need if you are receiving extensive amount of simultaneous requests, you are hosting many different projects, that are being accessed simultaneously and your average CPU usage is above 50-60%. But even then – I would generally suggest to check speed of your CPU – the single core speed.

Why does single core speed matters? Because, as I stated above – PHP is using one CPU core for single request processing. Faster CPU is done with one request – faster it can do job for the next one. Increasing number of CPU cores won’t necessary increase speed of all subsystems – but switching to faster CPU (and keeping same number of CPU cores) – in most cases will increase overall speed by a lot!

If you have a lot of requests – more cores will help.
If you change to faster CPU – it will help with any amount of traffic.

Let’s do some benchmarking!

Numbers do no lie, right? And we all love visual graphs – therefore let’s do some testing.

I ordered simple VPS, installed Debian, Apache, PHP8.2 (FPM), MariaDB 10.11 and tested it with sysbench, wordpress benchmark plugin and apache benchmark tool. Tests were repeated on different VPS configuration – my provider supports VPS rescaling, so I was able to run same benchmarks on one-core Intel CPU, two-core CPU (Intel and AMD) and four-core CPU (also Intel and AMD). Let’s look at results and make some conclusions.

VPS with Intel CPU

First graph shows, that the more threads we run (you can translate this into – the more different applications you run) – the more we benefit from higher number of cores. That is totally predictable. Server, that has just 1 CPU core and 4 running threads – still can only do as much work as with single running thread.

Second graph is more interesting and it shows average response time of the WordPress site. I have tested it with 1, 3 and 5 simultaneous connections. As you can clearly see – the more simultaneous connections you have – the more you benefit from higher number of CPU cores. VPS with just one CPU core became quite slow with high number of simultaneous connections, while 4 core CPU still was as fast, as with just 1 simultaneous connection.

Finally third graph is about total number of requests (within 5 minut interval). This graphs shows us, that with more cores and more simultaneous connections our VPS server was able to handle more requests. It might be hard to see on this image, but in fact 5 simultaneous connections for a single-core VPS actually decreased total request number. Overloaded server becomes slower, because CPU has to switch between different intense and waiting tasks.

WordPress Benchmark plugin results

CPU benchmark test results

Second core shows biggest impact – one core runs the PHP script, while other server tasks run on the second core and let the first one just for executing PHP and that’s why we see this improvement.

Filesystem benchmark test results

Also filesystem tests perform better with more CPU cores. Although benchmark itself is not CPU intense, this has to do with how linux handles filesystem related IO-calls.

Database benchmark test results
Object cache (using REDIS as backend) test results

Both MySQL and object cache test results show similar results, I would say in some cases unexpectedly performing slower.. I can not give any explanation, but please bear in mind, that I completed these tests just once and without specific tuning and service optimizations.

What about other CPU then? Let’s try AMD VPS!

I mentioned in the first paragraph, that in most cases I would suggest looking for better, faster CPU, rather than increasing number of CPU cores. To prove this point of view, I have switched my VPS to AMD architecture and run same benchmark tests. Unfortunately my provider does not offer AMD-based VPS with just one CPU core.

Quite predictable results – more CPU cores give us better results. WPBenchmark plugin results again show similar results, as for Intel – more cores – better speed.

Main question has not been answered yet!

But wait – you’ve come here for a different question. Should you add more cores or should you switch to better CPU? Right! Now let’s put all our results together and decide.

Sysbench and Apache benchmark results

You can clearly see, that AMD (green and orange) outperforms similar INTEL CPUs. You get better results in sysbench and better results with apache benchmark tool. 2 core AMD outperforms 2 core Intel CPU and 4 core AMD clearly outperforms 4 core Intel. Definitely speed of these CPUs is different. My VPS provider do not expose name of CPU model, therefore these tests is the only source of information.

WordPress Benchmark results for different VPS configurations

First, most significant benchmark – CPU speed. Do you see the gap between 4 core Intel and 2 core AMD? That is what I wanted to show you. Gap between speed between different CPUs and on the next graphs you will see this gap again and again. That is what makes the difference, that is what will make you feel difference in website speed, especially working in the backed, especially working with complex plugins and large sites.

wpbenchmark – filesystem benchmark results
wpbenchmark – database benchmark results
wpbenchmark – object cache benchmark results

You see, how CPU with better sysbench score performs better, right? That CPU is better, that CPUs single-core speed is better – and that’s why it performs better. Adding more CPU cores makes it even better, but the biggest difference is seen between Intel and AMD platforms – read – different CPU models.

This is not Intel vs AMD battle, so please treat these results as battle between different CPU models, not CPU manufacturers. Switching between AMD and Intel for VPS was the easiest way to make sure, that we get different CPU models, check which of them was better/faster and how this might affect performance of WordPress and PHP scripts.

Conclusion and final argument

You can clearly see, that different CPU models provide different performance. With the fast CPU – the 2-core server was able to outperform 4-core server running slower CPU model. And as a final and very important argument I will bring in the price-factor. Usually, when you have a VPS server – you pay, among other parameters (like memory, disk size) – for the amount of CPU cores. And quite often, if not always – number of CPU cores is the most price-affecting factor.

In my case, for a great surprise, the faster AMD CPU was also significantly cheaper.


Monthly prices for VPS servers, that I used in my benchmark
Monthly prices for VPS servers, that I used in my benchmark

This article’s main purpose is to encourage you look for better CPU model. With other provider it might come with better price and in overall – it will always provide you with a better performance.

Conclusions

My opinion: Always look for CPU with better single core performance and then choose number of CPU cores wisely, based on number of active processes and your project workload. Servers, that are used for development will be fine with a single core server, anything with two cores will truly be fast.

Always happy to discuss, answer questions, provide help!


Appendix A. Links to wpbenchmark.io results

Leave a Reply

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