Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: limiting CPU usage



On 30 Nov 2007, at 16:36, Alexander Cohen wrote:

In that case, maybe you have an idea for me. I have a daemon that runs and indexes all the images on a system. For each image, it needs to open it up, get some info, close it and store that info. This is very CPU consuming and can pretty much bring the system to a halt after a while.

Are you sure it's the CPU usage that's the problem here? The kind of thing you're talking about sounds like it should be I/O limited, not CPU limited on modern machines. If it really is CPU limited, you may be using the wrong algorithm somewhere; try using Shark to find where the machine is spending its time.


Anyway, NSThread has -setThreadPriority:, which you can use. If you aren't using Cocoa (in which case what are you doing posting this question to cocoa-dev?), you can also use various UNIX APIs (nice(), getpriority()/setpriority(), pthread_getschedparam()/setschedparam()).

Whatever you choose, you should be running at a low priority if you're CPU-bound (and contrary to popular belief, this will not make your code run slower... it just means that if the user wants to do something else at the same time, it will work better; if they don't, your program will take the same amount of time to run that it would have done before).

Kind regards,

Alastair.

--
http://alastairs-place.net


_______________________________________________

Cocoa-dev mailing list (email@hidden)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/email@hidden

This email sent to email@hidden
References: 
 >limiting CPU usage (From: Alexander Cohen <email@hidden>)
 >Re: limiting CPU usage (From: Thomas Davie <email@hidden>)
 >Re: limiting CPU usage (From: Alexander Cohen <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.