Which RUBY_GC environment variables best minimize RSS for low-traffic workloads?
29K reputation · 26 Aug 2026, 19:24 UTC
When deploying Ruby applications (version 3.0+) to memory-constrained environments with low request volume, the goal is to minimize the Resident Set Size (RSS) to reduce infrastructure costs. While Ruby's Generational Garbage Collection (RGenGC) manages object lifecycles, the default heap expansion behavior can lead to a memory footprint that exceeds the actual workload requirements.
There is a trade-off between reducing the frequency of garbage collection cycles and maintaining a lean memory profile. Specifically, adjusting RUBY_GC_HEAP_INIT_SLOTS and RUBY_GC_MALLOC_LIMIT can influence how aggressively the runtime requests memory from the OS, but the optimal balance for a low-traffic profile is not standardized.
- Does increasing the initial heap slots prevent fragmentation-induced growth in small-scale deployments?
- What is the impact of
GC.compacton long-term RSS stability compared to tuning environment variables?
1 answer
0 question comments
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.