• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: limiting CPU usage
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


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>)

  • Prev by Date: Re: Type select in NSTableView, NSBrowser
  • Next by Date: Re: Creating subviews programmatically ?
  • Previous by thread: Re: limiting CPU usage
  • Next by thread: Re: limiting CPU usage
  • Index(es):
    • Date
    • Thread