Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gevent urllib is slow

Tags:

python

gevent

I've created a set of demos of a TCP server however my gevent examples are noticely slower. I'm really not testing performance but at the moment something is making the gevent version 5 times slower.

I'm sure must be how I compiled gevent but can't work out the problem. I'm using OSX leopard using fink compiled python 2.6 and 2.7. I've tried both the stable gevent and gevent 1.0b1 and it acts the same. The echo takes 5 seconds to respond, where the other examples take <1sec. If I remove the urllib call then the problem goes away.

I put all the code in https://github.com/djay/geventechodemo

To run the examples I'm using zc.buildout so to build

$ python2.7 bootstrap.py
$ bin/buildout

To run the gevent example:

$ bin/py geventecho3.py &
[1] 80790
waiting for connection...
$ telnet localhost 8080
Trying 127.0.0.1...
...connected from: ('127.0.0.1', 56588)
Connected to localhost.
Escape character is '^]'.
hello
echo: avast

This will take 3-4 seconds to respond on my system.

However the threaded example

$ bin/py threadecho2.py

or the twisted example

$ bin/py twistedecho2.py

Is less than 1s. Any idea what I'm doing wrong?

like image 769
djay Avatar asked Apr 04 '12 05:04

djay


1 Answers

The answer was change the default DNS resolver being used as outlined in this conversation.

https://groups.google.com/forum/#!topic/gevent/5uNfkdgzWVc

setting GEVENT_RESOLVER=thread made it work as the expected speed

like image 90
djay Avatar answered Oct 16 '22 05:10

djay