Re: limiting CPU usage
Re: limiting CPU usage
- Subject: Re: limiting CPU usage
- From: Alastair Houghton <email@hidden>
- Date: Fri, 30 Nov 2007 18:01:14 +0000
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:
This email sent to email@hidden