httpclient: Consider removing magic from AsyncHTTPClient
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 25/100
- Issue type
- Refactor
- Clarity
- Needs clarification
- Activity status
- Stale
- Tech stack
- python
- Domain
- networking
Research direction
Start by reading AsyncHTTPClient.new and the force_instance behavior described in the issue, then review AsyncHTTPClient.close and the concerns from #2026. Compare the effects on SimpleAsyncHTTPClient and CurlAsyncHTTPClient, including max_clients, connection caching, and cleanup. Done requires a decided API direction rather than a specified edit.
Written by the indexing model from the issue text.
Description
AsyncHTTPClient.__new__ is very magical: Unless you pass force_instance=True when constructing an AsyncHTTPClient, you may be reusing an existing object. This is partly done for convenience and efficiency (so you don't have to pass a single object around to reuse existing curl objects with their connection cache), but also to enforce good internet citizenship (so you have to think about what you're doing and increase max_clients before unleashing a massively parallel webcrawler).
The downside, of course, is that this magic is surprising and arguably un-pythonic and un-tornadoic. The force_instance workaround is unnatural, and this arrangement makes AsyncHTTPClient.close difficult to use safely (see #2026).
For Tornado 5.0, does it make sense to eliminate this magic and encourage developers to create a single AsyncHTTPClient at startup and pass it around? (or we could start encouraging this pattern now and make the actual change in a future x.0 release) The creation of a SimpleAsyncHTTPClient is fairly cheap since they are stateless, so the main "cost" to users of that client implementation would be the fact that the max_clients limit would effectively be lifted (some of these users will see that as a benefit rather than a cost). This change would have a larger performance impact on users of CurlAsyncHTTPClient since they'd lose the benefit of that objects' connection cache if they were "creating" new clients all over the place. The absence of an explicit close() call would also mean that these newly-created objects would be relying on GC for cleanup, which is expensive due to internal circular references.
- Dominant language
- Python
- Stars
- 22.2k
- Forks
- 5.6k
- Avg merge
- 3h 42m
- Merged PRs (30d)
- 16
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tornadoweb/tornado
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
tornadoweb/tornado#3701 · 1 comment ·
-
httpserver
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
tornadoweb/tornado#1050 · 2 comments ·
-
Difficulty 3/5 1-2 days Newbie friendliness 55/100
tornadoweb/tornado#3728 ·
-
Difficulty 3/5 1-2 days Newbie friendliness 64/100
tornadoweb/tornado#3651 · 2 comments ·
-
Difficulty 4/5 3-5 days Newbie friendliness 50/100
tornadoweb/tornado#3616 · 2 comments ·
All issues in tornadoweb/tornado
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100