[Chicago] gevent question

Daniel Griffin dgriff1 at gmail.com
Tue Jul 28 16:00:42 CEST 2015


First thing you should do is take out the multiprocessing and see what your
single threaded performance looks like.

On Mon, Jul 27, 2015 at 11:14 PM, Osman Siddique <osiddique at gmail.com>
wrote:

> hi best users group ever,
>
> any help would be greatly appreciated. i'm trying to write something that
> sends out a bunch of messages at once. i have one solution that works, but
> i feel like it's slow b/c it takes ~4 seconds to send 3000 http post
> requests on my 2012 my macbook air. admittedly, i'm new to the exciting
> world of http so maybe this is normal.
>
> here's the solution that doesn't work.
>
> import requests, json, multiprocessing, gevent
> from gevent import monkey
>
> monkey.patch_socket()
>
> def send(s, data):
>     s.post("http://127.0.0.1:8080", data)
>     print data
>
> def worker(id):
>     s = requests.session()
>     for i in range(1, 1000):
>         data = json.dumps({'a':True,'b':123.0,'c':i,'d':id})
>         gevent.spawn(send, s, data)
>     data = json.dumps({'a':True,'b':123.0,'d':id})
>     send(s, data)
>
> if __name__ == '__main__':
>     p = multiprocessing.Pool(5)
>     p.map(worker, [1, 2, 3])
>
> my server running on the other side only seems to see a few of the first
> requests from the for loop. after that, the next thing it sees are the
> requests outside of the loop. basically wondering why i don't see that
> 'print data' command in the send func being executed.
>
> thanks,
> osman
>
> _______________________________________________
> Chicago mailing list
> Chicago at python.org
> https://mail.python.org/mailman/listinfo/chicago
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/chicago/attachments/20150728/68d50be8/attachment.html>


More information about the Chicago mailing list