feat(perf): implement HTTP connection pooling with httpx.AsyncClient singleton and Keep-Alive
- get_http_client: singleton AsyncClient with limits(max_keepalive=10, max_connections=20, keepalive_expiry=60s) - close_http_client: clean socket pool teardown in FastAPI lifespan shutdown - refactor dictionary fetchers to reuse pooled client and avoid 5x TLS handshakes per word lookup - add test_http_connection_pooling (22/22 pytest passed)
This commit is contained in:
1 parent
c4a6edee37
commit
438dfdb055
4 files changed
+211
-132
No files matched your search
+2
-1
@@ -25,7 +25,7 @@ from app.auth import (
|
||||
record_login_success,
|
||||
change_user_password,
|
||||
)
|
||||
from app.dictionary import lookup_term, USER_AGENT
|
||||
from app.dictionary import lookup_term, USER_AGENT, close_http_client
|
||||
from app.export import export_csv, export_json, export_anki_tsv, export_markdown
|
||||
from app.srs import calculate_sm2, generate_quiz_options, build_activity_heatmap, calculate_cefr_level
|
||||
from app.reader import parse_epub, parse_text, parse_pdf, count_words
|
||||
@@ -36,6 +36,7 @@ async def lifespan(app: FastAPI):
|
||||
init_db()
|
||||
ensure_admin_user()
|
||||
yield
|
||||
await close_http_client()
|
||||
|
||||
|
||||
app = FastAPI(
|
||||
|
||||
Reference in new issue
Block a user