[Pythonmac-SIG] socket.getaddrinfo problems

Dudley Carr dudley at cs.stanford.edu
Sun Apr 18 15:20:42 EDT 2004


brad.allen at omsdal.com wrote:


> However, from the thread I'm reading up here, you guys are implying 
> there is no DNS cache by default, since you are discussing how to turn 
> it on. Sorry if this is a bit off topic, but I'd be very interesting in 
> learning how to understand this better. Thanks!

Brad,

First off, I'm new to OS X so I can't say for certain whether or not OS X has 
built-in DNS caching. The best way to resolve this is to get a copy of ethereal 
running, and see what's on the network. I'm having some trouble getting ethereal 
to run, so I'll share my performance numbers with you.

def queryTimer(host, numAttempts):
     timings = []
     for i in range(numAttempts):
         start = time.time()
         socket.queryaddrinfo(host, 80)
         end = time.time()
         timings.append(end - start)
      return timings

# With Bind DNS caching turned off
 >>> r = queryTimer('yahoo.com', 50)

# My network is abnormal so I'm going to eliminate the
# occasional query that takes longer than 1 second
 >>> r = [ timing for timing in r if timing <= 1 ]

# The average query time when BIND DNS caching is turned off
 >>> sum(r) / len(r)
0.1006

# With BIND DNS caching turned *on*
 >>> x = queryTimer('yahoo.com', 50)

# The average query time when BIND DNS caching is turned *on*
 >>> sum(x) / len(x)
0.0081

To me this is a pretty good sign that there isn't any DNS caching by default. I 
also took the average query time for the timings submitted by Steven Palm ( 
0.024 seconds if you eliminate the very first query ) and Craig Amundsen ( 0.88 
seconds ).

Steven's timings are the best out of his, and Craig's, and mine. However, my 
BIND DNS caching timing is 3x better than Steven's timings.

Regards,
Dudley



More information about the Pythonmac-SIG mailing list