Skip to content

Lower ASGI gzip compresslevel from 9 to 4#3735

Draft
anth-volk wants to merge 1 commit into
masterfrom
fix/metadata-gzip-compresslevel
Draft

Lower ASGI gzip compresslevel from 9 to 4#3735
anth-volk wants to merge 1 commit into
masterfrom
fix/metadata-gzip-compresslevel

Conversation

@anth-volk

Copy link
Copy Markdown
Collaborator

Fixes #3734

Summary

Stage 2 of the Cloud Run cutover failed its warm-parity gate at 3.25× (limit 1.20×), localized entirely to /us/metadata: p95 13.2 s on Cloud Run vs 4.3 s on App Engine, while liveness/readiness are faster on Cloud Run. The ~70 MB raw metadata payload is gzipped in-request by starlette's GZipMiddleware at its default compresslevel=9 on Cloud Run; App Engine flex never pays this cost because its nginx sidecar handles gzip natively at a low level.

Change

One line in asgi_factory.py: explicit compresslevel=4.

Measured on the actual production metadata payload (70.8 MB):

Level Compress time Output
9 (current default) 5.46 s 9.0 MB
6 1.33 s 9.1 MB
4 (this PR) 0.73 s 9.9 MB
1 0.40 s 10.9 MB

7.5× faster compression for ~10% larger output (~0.2 s extra transfer at typical bandwidth vs ~5 s of CPU saved per request).

Verification

  • tests/unit/test_asgi_factory.py: 15/15 pass; ruff clean.
  • Empirical projection: CR metadata TTFB ≈ 9.8 s − (level-9 − level-4 compression delta on Cloud Run CPU) → expected to land near GAE's ~2–4 s.
  • Definitive check after merge+deploy: re-run the Stage 2 Phase A parity capture (capture_migration_baseline.py --repetitions 10 both platforms) — gate is CR p95 ≤ GAE p95 × 1.20.

Out of scope per maintainer: the 70 MB payload itself (metadata slimming planned separately) and the Accept-Encoding: identity 500 (Cloud Run ~32 MB response cap; single known consumer always sends gzip; mooted by slimming).


🤖 Generated with Claude Code

Stage 2 warm-parity measurement found /us/metadata p95 at 13.2s on
Cloud Run vs 4.3s on App Engine. The ~70MB raw payload is compressed
in-request by GZipMiddleware at starlette's default level 9 on Cloud
Run, while App Engine's nginx sidecar gzips natively. Measured on the
real payload: level 9 = 5.5s -> 9.0MB, level 4 = 0.7s -> 9.9MB, a 7.5x
compression speedup for ~10% larger output (~0.2s extra transfer).

Fixes #3734

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codecov

codecov Bot commented Jul 6, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 79.82%. Comparing base (74c146f) to head (a7f5e46).
⚠️ Report is 2 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #3735   +/-   ##
=======================================
  Coverage   79.82%   79.82%           
=======================================
  Files          70       70           
  Lines        4336     4336           
  Branches      808      808           
=======================================
  Hits         3461     3461           
  Misses        655      655           
  Partials      220      220           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Cloud Run /us/metadata is 3x slower than App Engine: GZipMiddleware compresses 70MB at level 9 in-request

1 participant