limiting cpu usage on individual apps

goynang

Some guy
Watching iTunes eat up large chunks of my CPU usage when playing (often 25-30%) I got to wondering if it was possible to limit CPU usage on an app by app basis.

Then I thought, hmmm - this smells like something some obscure UNIX command can probably do.

I guess in the case of iTunes it might affect playback but it would be interesting to have a go.

There's probably other stuff I have going on in the background too that would be good if kept in check.

So......

Anyone got any ideas?
 
Priority control, the mechanism through which certain processes are given more or less opportunity to use CPU cycles, was broken in Mac OS X 10.0.x. This problem has been fixed in Mac OS X 10.1. The commands you want are nice and renice. You can find out more information about them by reading the man pages:
man nice
man renice


You can read more about setting the priority of iTunes here (as there are some caveats about mucking with its priority level):
http://arstechnica.com/reviews/01q4/macosx-10.1/macosx-10.1-8.html

***

It seems strange that iTunes is consuming that much of your CPU. On my G4 Dual 1GHz, it takes between 4-7% of the CPU time on average (as shown by top -u from the Terminal). On a 667MHz PowerBook G4, it takes between 11 and 17% of the CPU on average.

I think there is a problem with your installation. You may want to download iTunes 3 from Apple (which was released today) and see if that fixes the CPU consumption issue for you.
 
Originally posted by testuser
Renice should have a significant effect when you have many, many apps running at the same time.

Yes, but only to increase priority of CPU hog. Due to the fact that BSD (and most probably OS X inherited this, but I am not certain) uses decaying priority for processes who consume their complete quantums, CPU hogs tend to end up with minimum dynamic priority, which cannot be further decreased by nice.

iTunes is not a CPU hog (it needs about 10 to 15 percent of CPU on this TiBook 500; which means that it fills the audio buffers and waits until they drain). Increasing its priority accomplishes nothing (it has nothing to do more than 85 percent of the time), unless the machine load is very close to 1 (or greater).
 
Thanks for your responses guys.

I did have a play with nice/renice as I recalled it existed after posting my message (and indeed did have a peek at the man pages.)

Didn't have a great deal of effect but then I didn't really open up a load of apps/tasks to test it out fully. It perhaps did lower the cpu usage a bit but I did also get a few skips in the music too.

I have got iTunes 3 and I think this hogs the CPU a bit more than v2 did - hard to say though, I haven't taken specific readings.

I was wondering more if you can actually limit the CPU percentage to a specific figure rather than just lowering priorty. I guess that there's no point really - it might as well use idle cpu time if it can.

Oh, and my 25-30% figure is on my trusty old 300mhz G3. It sometimes hits nearer 50% for small periods.

I often have a load of stuff going on (iTunes, tomcat, project builder java compiles, apache, postgres, BBedit, browsers, etc) and my poor old machine struggles to cope.

Ah well, better get a new G5 I guess - oh wait they're not out yet. D'oh!
 
Back
Top