Maximum Number Of Connections Per Host With Twisted.web.client.agent
I have the following code which creates an HTTPConnectionPool using TwistedMatrix Python framework, and an Agent for HTTP requests: self.pool = HTTPConnectionPool(reactor, pers
Solution 1:
The reason setting maxPersistentPerHost
to 1
didn't help is that maxPersistentPerHost
is for controlling the maximum number of persistent connections to cache per host. It does not prevent additional connections from being opened in order to service new requests, it will only cause them to be closed immediately after a response is received, if the maximum number of cached connections has already been reached.
You can enforce serialization in a number of ways. One way to have a "FIFO queue" is with twisted.internet.defer.DeferredLock
. Use it together with Agent
like this:
lock = DeferredLock()
d1 = lock.run(agent.request, url, ...)
d2 = lock.run(agent.request, url, ...)
The second request will not run until after the first as completed.
Post a Comment for "Maximum Number Of Connections Per Host With Twisted.web.client.agent"