This post originated from an RSS feed registered with Ruby Buzz
by Daniel Berger.
Original Post: Preventing massive CPU suckage
Feed Title: Testing 1,2,3...
Feed URL: http://djberg96.livejournal.com/data/rss
Feed Description: A blog on Ruby and other stuff.
While trying to find a way to simulate getrlimit and setrlimit on MS Windows I realized you could do this on most Unix platforms as a way to prevent your process from sucking massive CPU cycles:
trap('XCPU'){
puts "CPU time exceeded!"
# Insert diagnostic code here
exit!
}
Process.setrlimit(Process::RLIMIT_CPU, 1) # Or whatever max value you want
while true
puts "This should exit in a few seconds..."
end
What I'm not sure of is what a good value is for the maximum CPU time. Then again, maybe limiting RLIMIT_VMEM would be better. Or perhaps both?
I've never done this in practice, btw, but it might be a good way to deal with spiking processes. Just a thought.