Php – Apache high CPU usage, setting a overload limit

apache-2.2cpu-usageperformance-tuningPHP

On a ubuntu server, I run a LAMP environment with APC, and fast-cgi as php mod, to host 2 wordpress sites, and both sites have WordPress Total Cache (W3TC) plugin configured.

The server's specs are: 2gb ram and 1 cpu (cpu MHz: 2100.076, cache size: 2048 KB).

One of the sites, generates a pretty heavy load on the server and oftenly the server stops to respond because of the high load.

  • I've deactivated unused Apache modules
  • I have set that all the caching from W3TC to be done in memory with APC
  • I did some apache tweaking

But none of that actually helps me with the brutal CPU usage, from php-cgi.

While I implement varnish and try to have a replica on another server I have so I can also do some load balancing, I'm wondering how can I set some kind of load limit on php-cgi or apache its self, and show a custom message like: Sorry, the server is under heavy load, please try again later

Have to mention that I also use, cloudflare.

Any other tips, are very welcome as well.

Best Answer

What are the typical request rates for PHP generated and static content? Have you checked the hit rate in APC for caching and for opcode? What version of PHP?

show a custom message

The sensible place to do this would be on a reverse proxy - but you say you've not go this in place yet. Another approach would be to run a minimal webserver and load balancer on the current box (in addition to the main content) and redirect that way - but that's even more work than getting Varnish set up.

Similarly wrapping the front end in a proxy script would have the desired effect - but again, the effort is more than implementing Varnish.