Scaling Apache/PHP – Beyond Maximizing CPU Cores

Apache2central-processing-unitmulti-coremulti-threadingPHP

I have an Linux/Debian server with Intel i7 CPU with 4 cores and 8 threads. When I run my heavy duty Apache/PHP job it uses 1 thread, and when I run concurrent Apache/PHP jobs they each use their own thread.

So, if I want to be prepared for high traffic, is it simply a matter of maximizing the number of cores (by choosing other CPUs) to be able to handle more concurrent jobs, provided it has enough memory and that the database/filesystem doesn't pose extra challenges?

I have tried running 8 and 10 jobs concurrently and it used all threads and CPU utilization was mostly 100% (but ran flawlessly), so it seems like the theory is not completely off – but is there something else that could bust this linear thinking?

Alternatively I could go with a load balanced system with multiple servers but I wonder how far I can get with a single server.

PS. Apache/PHP is using mod_php with thread safety disabled, therefore it uses Prefork MPM. Not sure I dare use Worker MPM as I'm uncertain about thread safety…

PSS. Also, I'm not necessarily looking for better performance, mainly just be able to handle higher traffic/more concurrent jobs.

Best Answer

From what you describe (100% CPU utilization), your application seems CPU bound. So adding more CPU cores or moving to a machine with faster cores will likely improve your performance.

Many cloud providers charge you only a few cents each hour to rent powerful virtual machines with many CPU cores and lots of RAM. Just go ahead and test on 16 or 32 cores to find out, how your performance scales with number of CPUs/cores.

And yes, I recommend increasing the number of cores in your system, first, before you increase the number of systems.

Related Topic