I want to do a lot of url details for a REST website. Usually between 75-90k. However, I need to limit the number of simultaneous connections to the web service.
I started playing with grequests as follows, but quickly started chewing open sockets.
concurrent_limit = 30 urllist = buildUrls() hdrs = {'Host' : 'hostserver'} g_requests = (grequests.get(url, headers=hdrs) for url in urls) g_responses = grequests.map(g_requests, size=concurrent_limit)
How it works for a minute or so, I get with errors "maximum number of sockets". As far as I can tell, each of the request.get requests in grequests uses its own session, which means that a new socket is opened for each request.
I found a note on github referring to how to get grequests to use a single session. But this, apparently, effectively eliminates all requests in one common pool. This seems to have exceeded the goal of asynchronous HTTP requests.
s = requests.session() rs = [grequests.get(url, session=s) for url in urls] grequests.map(rs)
Is it possible to use grequests or gevent.Pool in such a way as to create multiple sessions?
Put another way: how can I make many simultaneous HTTP requests using either the queues or the connection pool?
python sockets gevent grequests
Marcel wilson
source share