Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/metadata-gzip-compresslevel.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Lower the ASGI gzip compression level from 9 to 4 so large responses like /us/metadata spend seconds less CPU compressing on Cloud Run, restoring warm-latency parity with App Engine.
7 changes: 6 additions & 1 deletion policyengine_api/asgi_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,12 @@ def create_asgi_app(wsgi_app) -> FastAPI:
redoc_url=None,
openapi_url=None,
)
app.add_middleware(GZipMiddleware, minimum_size=1000)
# compresslevel 4 instead of starlette's default 9: /us/metadata is ~70MB
# raw, and level-9 compression inside the request costs seconds of CPU on
# Cloud Run (where no nginx sidecar handles gzip, unlike App Engine flex).
# Measured on the real payload: level 9 = 5.5s -> 9.0MB, level 4 = 0.7s ->
# 9.9MB — 7.5x faster for ~10% larger output.
app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=4)

@app.middleware("http")
async def add_cors_for_native_routes(request, call_next):
Expand Down
Loading