Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From time to time I have strange problem. My VPS overloads and doesn't request. I have to reboot server by hands, and only after it server works well again. But sometimes several hours pass until I find out that it overload, and all this time my sites are down. Is there any way to make Linux to reload if CPU usage is more than 50%? It would help me a lot.

alt text

share|improve this question

migrated from May 18 '10 at 15:14

This question came from our site for professional and enthusiast programmers.

This should probably be moved to ServerFault. – Bradley Mountford May 18 '10 at 14:15

nanny scripts like the one you are after are very dangerous and can cause more issues than it solves, i would agree with kaerast on needing to track down the root cause of the issues, looking at the screen shot you have produced looks like the issue could be more with memory than than CPU.

is there any obvious errors in your apache error logs or in /var/log/messages or /var/log/syslog

share|improve this answer

Your console clearly shows apache2 OOM'ing.

In your Apache config, try tuning MaxRequests (which will cycle a httpd process after a # of requests, helpfull if your web app is leaking memory) and/or MaxClients (which will limit the maximum number of simultaneous connections your server can handle)

A 'somewhat' reasonable approach to calculating MaxClients is to apply this equation:

(Physical RAM present) / (Average Size of Process) * 1.25 (to account for memory-sharing effects)

the 1.25 is a tuneable 'fudge factor', which you can adjust up and down. the higher you make it, the more you risk OOM'ing your server.

share|improve this answer

Monit would be a good simple solution for this. But you might want to look into the root cause and work out what's causing the high cpu usage and then either optimise your code or get a faster server.

share|improve this answer

So what does your Apache config look like? What are your current settings for these parameters:

  • MinSpareServers
  • MaxSpareServers
  • ServerLimit
  • MaxClients

There's a good chance that your default Apache config is setting these parameters too high for the memory available on your VPS. Spawning too many Apache processes (which are rather memory hungry to begin with) could easily get you into the same OOM memory situation seen in the logs.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.