I have an Intel server. The CPUs are power managed between 800MHz and 3GHz, using the p_state driver. Obviously it's drawing less power and making less noise when it's down at 800Mhz.

Most of the things that are running on the server are on-demand and should execute as fast as possible (and they do) but I have one daemon that is thoroughly unimportant. It takes about 20% CPU at peak but this can last for a few hours while it processes files.

My problem is whenever this process does anything, the power state in the CPU ramps up. It uses more power and makes more noise. I want this one daemon to run at 800MHz all the time (unless anything else needs the CPU).

I could stick the whole server in powersave but I need other applications to be able to scale the CPU. Is there a sensible way I can tell whatever manages the CPU to disregard load from a particular application?


I found cpulimit.

$ sudo apt-get install cpulimit  # for installing cpulimit
$ pgrep process_to_limit         # getting the pid

$ cpulimit -p 1234 -l 30         # -p pid -l percentage_of_cpu_to_use

But it looks like cpulimit only uses the pid of a running process or executes a program. That means you need to find a way (bash script) to execute cpulimit when the daemon is running.

Here's a short shell script that reads the pid, executes cpulimit and sleeps for 60min.

# This example uses firefox, replace the variable PROG

PID=`pgrep $PROG`

if [ $PID ]                # if $PID not equals 0 (zero)
   cpulimit -p $PID -l 30  # limit the cpu time to 30%
   sleep 60m               # wait 60 minutes
   sleep 60m

Save it as e.g. run_cpulimit.sh, grant permission chmod u+x run_cpulimit.sh and start it.

| improve this answer | |
  • 1
    "Since you have a reputation of 151k I will not include installation instructions." You should always include the install instruction, yes oli is the highest rep user on the site but your answers should be for anyone that reads this, not just the OP, what about new users who look for this information???. – Mark Kirby Jan 19 '16 at 12:24
  • Okay you are right, I just wanted to be lazy, maybe it was the wrong time :D – Kev Inski Jan 19 '16 at 12:41
  • 3
    Good edit, but be careful, laziness will get you downvoted because of lack of detail. – Mark Kirby Jan 19 '16 at 12:45
  • I do not understand the "limit the cpu speed to 30%, makes 900MHz" statement in the context of the intel_pstate driver in powersave mode. Typically 30% load will result in a higher CPU frequency (depending on the processor). It is also somewhat a function of if the load is increasing or decreasing. I'm suggesting a lower number might be needed. – Doug Smythies Jan 19 '16 at 16:15
  • 1
    No. Consider a cpu time wasting type program (no I/O wait and minimal system calls) that prints elapsed time every so often. Unrestricted, mine prints every 5.55 seconds and is running at 3.8 GHz (it is noisy). At a cpulimit of 20% it prints every 43 seconds and is running at about 2.1 GHz.. 5.55 * 3.8 / 2.1 * 100 / 20 = 50 seconds. A straight scaling would have been 27.5 seconds. – Doug Smythies Jan 25 '16 at 15:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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