Skip to content

Add RSS-based worker recycling - #91

Open
avilaton wants to merge 2 commits into
davidbrochart:mainfrom
avilaton:max-rss-recycling
Open

avilaton wants to merge 2 commits into
davidbrochart:mainfrom
avilaton:max-rss-recycling

Conversation

@avilaton

@avilaton avilaton commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This adds optional RSS-based worker recycling.

Workers can now be configured with max_rss or --max-rss to recycle after their current resident set size exceeds a configured MiB limit. The RSS monitor runs periodically inside each worker and triggers the existing graceful worker termination path, so in-flight requests still drain under graceful_timeout before the master process respawns the worker.

Current RSS is read with psutil.Process().memory_info().rss, which adds psutil as a dependency. With workers == 0, there is no master process to respawn the worker, so exceeding max_rss stops the single worker, matching existing max_requests behavior.

Tests

  • uv run pytest tests/test_config.py tests/test___main__.py tests/test_run.py -q — passed
  • uv run pytest — passed
  • uv run ruff check — passed
  • uv run ruff format --check — passed
  • uv run ty check — passed

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@davidbrochart

Copy link
Copy Markdown
Owner

Current RSS is read from Linux /proc/self/status VmRSS.

Maybe use psutil's memory_info().rss?

@avilaton

avilaton commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

Good idea, switched to psutil.Process().memory_info().rss, which also makes it work beyond Linux.

@avilaton
avilaton marked this pull request as ready for review October 2, 2026 14:12

This branch has not been deployed

No deployments
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.

2 participants