Enable jemalloc via LD_PRELOAD on Chatwoot Puma & Sidekiq
Preloading libjemalloc.so.2 replaces glibc ptmalloc2 in official Chatwoot Docker images, flattening Sidekiq and Puma RSS plateaus.
Memory Reduction: -40% to -58% RSS | Flag: LD_PRELOAD libjemalloc.so.2
Step 1: Verify libjemalloc Shared Library Path in Image
Check your Chatwoot container architecture before mounting LD_PRELOAD: on x86_64 Debian images the library resides at /usr/lib/x86_64-linux-gnu/libjemalloc.so.2 (or /usr/lib/aarch64-linux-gnu/libjemalloc.so.2 on ARM64). Test with docker compose run --rm rails ldd $(which ruby) or ls -la /usr/lib/*/libjemalloc*.
Step 2: Apply LD_PRELOAD to Both rails and sidekiq Services
Inject LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libjemalloc.so.2 inside both the Puma web service and every Sidekiq worker service in docker-compose.yml. Confirm jemalloc is active via Ruby: bundle exec rails runner "puts RbConfig::CONFIG['LIBS']" or inspecting /proc/1/maps for libjemalloc.
Measured Thresholds & Configuration
| Service Container | Default glibc RSS | With LD_PRELOAD jemalloc |
|---|---|---|
| rails (Puma 2 workers) | 1.85 - 2.60 GB | 0.95 - 1.35 GB |
| sidekiq (15 threads) | 3.40 - 5.80 GB | 1.15 - 1.75 GB |
| Combined Ruby Footprint | 5.25 - 8.40 GB (OOM risk) | 2.10 - 3.10 GB (8 GB KVM safe) |