Skip to content

fix: stop memory governor over-count and clamp starvation#109

Merged
ServerSideHannes merged 4 commits into
mainfrom
fix/governor-overcount-and-clamp-starvation
Jul 6, 2026
Merged

fix: stop memory governor over-count and clamp starvation#109
ServerSideHannes merged 4 commits into
mainfrom
fix/governor-overcount-and-clamp-starvation

Conversation

@ServerSideHannes

Copy link
Copy Markdown
Owner

Summary

  • Fix streaming_upload_peak to match measured framed-upload peaks (4*part for small parts, 2*part + FRAME for multi-frame) instead of 2*part + 2*frame which double-counted the frame and scaled with multi-GB Content-Length
  • Add governor_memory_footprint() to cap request-gate reservations at the 512MB-workload peak so a 6.6GB Content-Length no longer reserves 500MB+
  • When an estimate still exceeds the governor budget, clamp to the routine-workload peak — not the entire budget — so concurrent ~50MB Scylla parts are not starved behind one oversized slot

Root cause

Prod showed MEMORY_CLAMPED_TO_BUDGET at ~509MB and perpetual MEMORY_BACKPRESSURE with requested_mb == limit_mb while a normal ~33MB Scylla part was active. The governor treated clamped requests as owning the full budget slot.

Test plan

  • uv run pytest tests/unit/ — 472 passed
  • New tests/unit/test_governor_peak_and_clamp.py covers multi-GB estimate cap, clamp non-monopolization, and concurrent Scylla-sized parts under 312MB budget
  • Deploy to staging; confirm Scylla SST backups no longer log perpetual MEMORY_BACKPRESSURE at requested_mb == limit_mb
  • Confirm S3PROXY_MEMORY_LIMIT_MB=312 pods admit multiple concurrent ~50MB parts

Made with Cursor

ServerSideHannes and others added 4 commits July 6, 2026 11:48
The framed upload path peaks at 2*internal_part + one frame, but
streaming_upload_peak used 2*part + 2*frame and scaled with multi-GB
Content-Length. When that estimate exceeded the governor budget, clamp
reserved the entire budget — starving concurrent ~50MB Scylla parts.

- Tighten streaming_upload_peak to measured 4*part (small) / 2*part+frame (large)
- Cap governor reservations at the 512MB-workload peak via governor_memory_footprint
- Clamp oversized requests to routine peak, not the whole budget
- Add regression tests for multi-GB estimates and concurrent Scylla parts

Co-authored-by: Cursor <cursoragent@cursor.com>
Add explicit guards for the old 2*part+2*frame formula and full-budget
clamp, prod replay (33MB active + multi-GB estimate at 312MB), request-
handler reservation spy, deployed budget matrix, mixed Scylla workload,
and signed 50MB Scylla part tracemalloc bounds.

Co-authored-by: Cursor <cursoragent@cursor.com>
Break a long line and move request-handler spy out of the for-loop to
avoid B023 closure-over-loop-variable warnings.

Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@ServerSideHannes ServerSideHannes merged commit fa07e55 into main Jul 6, 2026
4 checks passed
@ServerSideHannes ServerSideHannes deleted the fix/governor-overcount-and-clamp-starvation branch July 6, 2026 10:01
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.

1 participant