Skip to content

Handle SimpleAsyncHTTPClient request timeout in heavy-loaded situation - #885

Merged
bdarnell merged 3 commits into
tornadoweb:masterfrom
codeb2cc:async-request-timeout
Nov 3, 2013
Merged

bdarnell merged 3 commits into
tornadoweb:masterfrom
codeb2cc:async-request-timeout

Conversation

@codeb2cc

Copy link
Copy Markdown
Contributor

In a heavy-loaded situation when requests have to be queued, they may have waitted for a long time before pop out and get actual process. These requests become useless and already timeout indeed. The connect_timeout and request_timeout in HTTPRequest and their timeout callback only matter when the _HTTPConnection get created. The SimpleAsyncHTTPClient handles requests ignoring their age in queue. As a result old requests get processed and block new request.
I've added a async_timeout param to HTTPRequest and corresponding timeout logic in the SimpleAsyncHTTPClient, hoping this would solve the problem.

The connect_timeout and request_timeout in HTTPRequest only matter when
the _HTTPConnection get created. In heavy-loadded situation requests in
SimpleAsyncHTTPClient may have already timeouted before they pop out
from queue and get actual processed. This commit adds an timeout
callback for every request appended to SimpleAsyncHTTPClient's request
queue that cannot be processed immediately.
@bdarnell

bdarnell commented Sep 1, 2013

Copy link
Copy Markdown
Member

This is a good idea, but I wish it didn't add yet another timeout parameter. Is there ever a time when you'd want a different value for this new timeout (which I would call queue_timeout instead of async_timeout) and connect_timeout? The key difference between connect_timeout and request_timeout is that the former allows the request to be aborted before any potentially-expensive server-side work has begun, and this new timeout seems to fit in the same category.

@codeb2cc

codeb2cc commented Sep 2, 2013

Copy link
Copy Markdown
Contributor Author

I've added the new timeout parameter because I'm afraid that adding extra logic to the current connect_timeout is bad and disruptive. And in real world case I do need a different value. I usually set connect_timeout to 3s because I know that if the request cannot be connected in 3s it's almost certainly blocked by the GFW or other network issue. Then I need to close it and retry again. Meanwhile the queue timeout is fine to be 5~10s. But It's not quite a common case and I would be happy to use the exsting connect_timeout since it do make the code look cleaner and less redundant.

@bdarnell
bdarnell merged commit 2d5f396 into tornadoweb:master Nov 3, 2013
@codeb2cc
codeb2cc deleted the async-request-timeout branch November 4, 2013 01:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants