Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have an apache server that runs some binary CGI programs. Those programs behave nicely most of the time, but on rare occasions they gult up all the RAM, or run for a very long time, taking 100% cpu.

When that happens, it becomes very hard to SSH to that machine (it's CentOS, BTW) and manually fix things.

Is there a way to have apache execute the CGI binraries with "nice" priority ? I don't want to limit the RAM usage or the CPU resources.

It's my understanding the having a "nice" priority will allow me to SSH to the machine (since sshd will have higher priority), and also, if RAM becomes an issue, the OOM killer will kill the CGI binary first.

Any ideas ?

Thanks!

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

For each cgi script, you could write a wrapper script that adjusts its own niceness and then execs the cgi script.

#!/bin/sh
renice -n 10 -p $$
exec /path/to/cgi/binary

However, I'm not sure how much effect this would have. Linus Torvalds himself calls nice broken. A better solution would be to set up cgroups to limit the share of the CPU or amount of memory Apache and its child processes can use. David Collier-Brown has written up some examples of this. I think you will need a newer kernel than the one that's included in CentOS 5. CentOS 6 will support cgroups; here is the documentation from Red Hat.

share|improve this answer
    
That Linus/LWN link is a great read, thanks. –  cagenut Mar 1 '11 at 21:22
    
Don't agree with Linus. Nice does (though not aggressively enough) limit CPU where appropriate. That's great he's worried about compilation on his local machine, but we need a user-level hint to the scheduler on over-committed server machines. –  Xepoch Apr 11 '12 at 15:40
add comment

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.