0

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 http://xmages.net/upload/72a39111.png

4 Answers4

2

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

Paul
  • 593
  • 2
  • 6
1

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.

Jason
  • 1,885
  • 1
  • 13
  • 12
0

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.

WheresAlice
  • 5,530
  • 2
  • 24
  • 20
0

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.