1.5.2, threading and sockets

knotwell at my-dejanews.com knotwell at my-dejanews.com
Fri Apr 16 13:19:21 EDT 1999


Hello all--

I'm looking at the 1.5.2 version of python.  I've noticed that
sockets and threads seem to work together much more slowly than in
1.5.1.

I've done a good number of timings using the following snippet of
code (or something quite similar to rule out urllib as the problem):
import urllib
import threading
def traffic_gen(url):
        for i in range(0,10):
                z = urllib.URLopener()
                s = z.open(url)
                s.read()
                s.close()

        print 'done'
        return

map(lambda x: x.start(), \  map(lambda x:
threading.Thread(target=traffic_gen,kwargs={'url':'http://
www.myurl.here'}),range(0,5)))

The problem is that this code was between 2-7 times (1.5.2) slower
in my tests (the range appears to depend on the number of threads
as well as network latency).  The call order was also much more "jerky."

It appeared to me that the socket/threading routines (standing alone)
were slightly faster in 1.5.2.  I can only guess there is some kind
of a resource issue for threads using the socket module.

I've only tried this on machines running Redhat5.2 (Linux2.0.36
and Linux2.2.5) so I don't know if this a Redhat problem.

The only thing I see that looks suspicious is the hocus-pocus with
gethostbyname (v. gethostbyname_r) in socketmodule.c.  However, I
tried compiling with -DHAVE_GETHOSTYBNAME_R_6_ARG and
-DUSE_GETHOSTBYNAME_LOCK.  Neither option made it any speedier or
smoother.
Does anyone have any idea what I should do about this?

Thanks.

--Brad

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    




More information about the Python-list mailing list