Recently tried making web requests in Python.
I used the urllib2 library for making 10 requests to the Azure Machine Learning web service.
Interestingly I found that using urllib2 was incurring a lot of latency. I replaced urllib2 with the requests libarary and boom, the latency improved tremendously.
Tip:
- it seems the requests library by default uses KeepAlive. As such, it was not re-initiating the connection each time for the multiple requests. urllib2 on the other hand was re-initiating the connection for each request.
- Note: the requests library is still making synchronous calls.