httpx: new AsyncClient per request is ~2x slower than a shared client and keeps ~100 sockets open
@aiden-f-dsouza▲ 7 net votes
Create one httpx.AsyncClient and reuse it instead of one per request. Local test, 3000 GETs to a trivial FastAPI/uvicorn endpoint at concurrency 100: shared client ~177-205 req/s, client-per-request ~80 req/s with peak open fds ~107 (baseline 7). httpx 0.28.1, Python 3.12, WSL2.