Skip to content

Commit f747549

Browse files
authored
Merge pull request #3735 from PolicyEngine/fix/metadata-gzip-compresslevel
Lower ASGI gzip compresslevel from 9 to 4
2 parents 012ea08 + a7f5e46 commit f747549

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
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.

policyengine_api/asgi_factory.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ def create_asgi_app(wsgi_app) -> FastAPI:
5353
redoc_url=None,
5454
openapi_url=None,
5555
)
56-
app.add_middleware(GZipMiddleware, minimum_size=1000)
56+
# compresslevel 4 instead of starlette's default 9: /us/metadata is ~70MB
57+
# raw, and level-9 compression inside the request costs seconds of CPU on
58+
# Cloud Run (where no nginx sidecar handles gzip, unlike App Engine flex).
59+
# Measured on the real payload: level 9 = 5.5s -> 9.0MB, level 4 = 0.7s ->
60+
# 9.9MB — 7.5x faster for ~10% larger output.
61+
app.add_middleware(GZipMiddleware, minimum_size=1000, compresslevel=4)
5762

5863
@app.middleware("http")
5964
async def add_cors_for_native_routes(request, call_next):

0 commit comments

Comments
 (0)