Remediation Hub (9)
Tune MALLOC_ARENA_MAX=2 & Ruby GC Slots When Using glibc
If custom base images lack libjemalloc, setting MALLOC_ARENA_MAX=2 prevents 8x core arena multiplication across Sidekiq worker threads.
Env: MALLOC_ARENA_MAX=2 | Relief: -30% to -45% glibc overhead
When MALLOC_ARENA_MAX=2 Acts as an Immediate Guardrail
If you run an older Chatwoot build or custom distro without jemalloc compiled in, glibc defaults to 8 * vCPU arenas. Setting MALLOC_ARENA_MAX=2 forces threads to share two arenas, trading negligible allocator lock contention for hundreds of megabytes of saved virtual memory.
Pairing MALLOC_ARENA_MAX with RUBY_GC_HEAP_GROWTH_FACTOR
Set RUBY_GC_HEAP_GROWTH_FACTOR=1.15 and RUBY_GC_MALLOC_LIMIT=16777216 so Ruby triggers minor/major sweeps earlier before large webhook JSON hashes inflate RSS. Remove MALLOC_ARENA_MAX once jemalloc is active via LD_PRELOAD.
Measured Thresholds & Configuration
| Environment Variable | Recommended Value | Effect on Ruby Process |
|---|---|---|
| MALLOC_ARENA_MAX | 2 | Caps glibc arenas (fallback without jemalloc) |
| RUBY_GC_HEAP_GROWTH_FACTOR | 1.15 | Shrinks post-GC heap expansion steps |
| RUBY_GC_MALLOC_LIMIT | 16777216 | Triggers GC sooner after C-ext allocations |