Skip to content

Reduce memory usage with puma_worker_killer and distro query optimization#919

Merged
andrew merged 3 commits intomainfrom
reduce-memory-usage
Apr 5, 2026
Merged

Reduce memory usage with puma_worker_killer and distro query optimization#919
andrew merged 3 commits intomainfrom
reduce-memory-usage

Conversation

@andrew
Copy link
Copy Markdown
Member

@andrew andrew commented Apr 5, 2026

Add puma_worker_killer to automatically restart Puma workers that exceed memory limits. Puma is now running in clustered mode with preload_app! for copy-on-write memory savings.

PumaWorkerKiller config:

  • 512 MB RAM limit (configurable via PWK_RAM_MB env var)
  • Checks every 30 seconds, kills workers at 90% usage
  • Rolling restart every 6 hours to prevent gradual bloat

Also refactors DistrosController#index which was loading the entire distros table into memory twice (via .to_a), then running three passes of group_by/map/sort_by on each set. Now uses find_each with selective columns (skipping raw_content text blob) and does deduplication in a single pass via Distro.grouped_and_deduped.

andrew added 3 commits April 5, 2026 09:40
…tion

Add puma_worker_killer to restart workers that exceed memory limits, enable
clustered mode with preload_app for copy-on-write savings, and refactor
DistrosController#index to use find_each with selective columns instead of
loading the entire distros table into memory twice.
Covers grouping by key, deduplication by pretty_name, sort order within
and across groups, nil grouping_key exclusion, and scope filtering for
the new model methods introduced in the memory optimization.
Move ungrouped distros filtering to a WHERE clause with selective columns
instead of loading all records into memory. Default WEB_CONCURRENCY to 0
in development to avoid unnecessary clustered mode. Fix test that relied
on generate_slug not running.
@andrew andrew merged commit 22e592b into main Apr 5, 2026
1 check passed
@andrew andrew deleted the reduce-memory-usage branch April 5, 2026 15:07
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