• 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: [[NSHost currentHost] name] blocking on 10.6 ?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [[NSHost currentHost] name] blocking on 10.6 ?


  • Subject: Re: [[NSHost currentHost] name] blocking on 10.6 ?
  • From: Marc Krochmal <email@hidden>
  • Date: Tue, 08 Sep 2009 22:41:37 -0700

Hi Jayson,

On Sep 8, 2009, at 4:51 PM, Jayson Adams wrote:


On Sep 8, 2009, at 3:31 PM, Marc Krochmal wrote:

Hi Brent,

I may have been one of those appalled Apple engineers. In general, [NSHost currentHost] is the worst API on the system and people should avoid it like the plague.

Hi Marc,

Can you tell why this is so?

[NSHost currentHost] as currently written, iterates over all available IP addresses on the system and does reverse DNS lookups on each address. It actually does this twice for each address. This includes loopback and link-local addresses, IPv4 and IPv6. This results in packets hitting the network. If DNS servers are slow to respond, this call will block and your application will SPOD. If DNS happens to be down or temporarily misconfigured, each individual query will take 30 seconds to timeout. All the queries are performed serially so the timeouts start to add up.


If you're just looking for the mDNS Local Hostname, it's MUCH more efficient to use SCDynamicStoreCopyLocalHostName, which is just a Mach message over to configd running on the local machine. No network delays.

If you just want to know the list of IP addresses, instead of doing [[NSHost currentHost] addresses], it's much more efficient to use getifaddrs, which doesn't require any DNS queries.

So in general people should avoid calling this API, or make sure to call it async, either on a separate thread or on a concurrent GCD queue.

Of course, given that we're aware of the performance issues, don't be surprised if [NSHost currentHost] performs better in future releases.

-Marc








Best,


__jayson

Circus Ponies NoteBook - Organization for a Creative Mind
www.circusponies.com




_______________________________________________

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: 
 >[[NSHost currentHost] name] blocking on 10.6 ? (From: "email@hidden" <email@hidden>)
 >Re: [[NSHost currentHost] name] blocking on 10.6 ? (From: Brent Gulanowski <email@hidden>)
 >Re: [[NSHost currentHost] name] blocking on 10.6 ? (From: Marc Krochmal <email@hidden>)
 >Re: [[NSHost currentHost] name] blocking on 10.6 ? (From: Jayson Adams <email@hidden>)

  • Prev by Date: Re: NSArray EXEC_BAD_ACCESS when initalized with strings
  • Next by Date: Re: Core Data fetch with to-many relationship
  • Previous by thread: Re: [[NSHost currentHost] name] blocking on 10.6 ?
  • Next by thread: scaleUnitSquareToSize strange behavior Scaling a UI
  • Index(es):
    • Date
    • Thread