is sharing transport a good way in async server, like fastapi #2518
-
I have a backend which basically proxy income http requests to other destination, using fastapi and httpx transport = AsyncHTTPTransport(limit=limit)
@app.route('/a')
async def to_a(...):
async with AsyncClient(transport=transport, base_url='http://a', timeout=a_timeout) as c:
await c.get('/xxxx')
@app.route('/b')
async def to_b(...):
async with AsyncClient(transport=transport, base_url='http://b', timeout=b_timeout) as c:
await c.get('/xxxx') why not using global my question is, does the reuse of transport sound ok? which means we share all the http request pools and reduce tcp connection creation? |
Beta Was this translation helpful? Give feedback.
Answered by
tomchristie
Dec 30, 2022
Replies: 1 comment 1 reply
-
Hrm. I think you'll find that the transport is closed when the client is closed, so I'm not sure this'll work as expected? |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
tomchristie
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hrm. I think you'll find that the transport is closed when the client is closed, so I'm not sure this'll work as expected?