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 want to limit the amount of processor power my sheduled jobs (Resque for a Rails application) use and I found this upstart that seems promising and might do what I want:

http://upstart.ubuntu.com/wiki/Stanzas#limit

But I am not so sure how to use it, say I want the process to use a maximum 50% of one of my two CPUs, what should I write in my upstart file?

Also, what will happen when the process reaches the limit?

share|improve this question
    
I would go with 25 which is 50% of half the CPUs. If you reach the limit, the process is excluded from CPU scheduling. Nothing special though as it is the same as it would be if both CPUs reach 100%. –  mailq Jan 2 '12 at 23:22
    
mailq, thats a pretty good answer, why not put it in as an answer so you get credit and he can accept it? –  SpamapS Jan 17 '12 at 0:19
    
"limit cpu" stanza does not limit cpu to a certain percent usage, but will limit total time process is allowed to run on cpu. It will certainly take 100% of the cpu until time is up. –  Tuminoid Feb 29 '12 at 9:07
add comment

1 Answer

up vote 0 down vote accepted

There is no such stanza in Upstart. "limit cpu" stanza will limit the maximum time (in seconds) process is allowed to be executed on CPU. During this allowance, it can take 100% of the CPU.

See man setrlimit(2): http://linux.die.net/man/2/setrlimit

RLIMIT_CPU CPU time limit in seconds. When the process reaches the soft limit, it is sent a SIGXCPU signal. The default action for this signal is to terminate the process. However, the signal can be caught, and the handler can return control to the main program. If the process continues to consume CPU time, it will be sent SIGXCPU once per second until the hard limit is reached, at which time it is sent SIGKILL. (This latter point describes Linux behavior. Implementations vary in how they treat processes which continue to consume CPU time after reaching the soft limit. Portable applications that need to catch this signal should perform an orderly termination upon first receipt of SIGXCPU.)

share|improve this answer
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.