FROM : Alastair Houghton
DATE : Fri Nov 30 19:01:14 2007
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
DATE : Fri Nov 30 19:01:14 2007
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
| Related mails | Author | Date |
|---|---|---|
| Alexander Cohen | Nov 30, 14:53 | |
| Thomas Davie | Nov 30, 15:41 | |
| Alexander Cohen | Nov 30, 17:36 | |
| Gammah Radiation | Nov 30, 18:00 | |
| Alastair Houghton | Nov 30, 19:01 | |
| Murat Konar | Nov 30, 21:05 | |
| Alexander Cohen | Nov 30, 21:19 | |
| Shawn Erickson | Nov 30, 21:30 | |
| Murat Konar | Nov 30, 22:07 |






Cocoa mail archive

