httpx 는 두 client class — httpx.Client (sync), httpx.AsyncClient (async). 둘 다 context manager (with httpx.Client() as client, async with httpx.AsyncClient() as client). 둘 다 TCP connection pool. Per-request 생성은 pool 무효화 + throughput 죽임.
1 process 1 client (또 다시)
OpenAI SDK 와 같은 룰. App startup 에 하나, 끝까지 share. httpx.get() 같은 bare 호출은 매번 fresh connection — TLS handshake 매번, no keep-alive.
LLM streaming 의 timeout
httpx default timeout 5 초 — LLM streaming 에서 즉사. 권장 — connect=10 (DNS resolution wait), read=300 (streaming 길게 가능), write=10, pool=10. timeout=None 은 위험 — hanging response 가 leaked connection 됨.
Async 권장
다중 동시 호출이 거의 항상 성립. AsyncClient + asyncio.gather 가 표준 패턴. Sync Client 는 단일 스레드 batch 도구에만.