Skip to content
Mike Perham edited this page Oct 14, 2020 · 2 revisions

Sidekiq uses memory. You'll see memory consumed booting Rails, loading your application code and running your jobs.

RSS

RSS (Resident Set Size) is the amount of physical RAM consumed by a process. Typically a Sidekiq process will start at some small value and reach some steady state value where RAM usage remains flat.

Bloat

On Linux, glibc clashes very badly with Ruby's multithreading and bloats quickly. Set MALLOC_ARENA_MAX=2.

If your process balloons up quickly upon processing some job, that can mean a job is loading a lot of data into memory. It's common for a poorly written ActiveRecord query to load many thousands of rows into memory.

Optimization

  1. Set MALLOC_ARENA_MAX=2. This environment variable is the closest thing to a silver bullet if you are using Linux/glibc in production. On Heroku, heroku config:set MALLOC_ARENA_MAX=2
  2. Use derailed_benchmarks to find gems in your Gemfile which need a diet.
  3. Switch to jemalloc. Ruby 2.7 works great with jemalloc 5.x.

More Reading

Here's a collection of really useful blog posts about the Ruby VM, GC and memory. Nate Berkopec is the expert in profiling, memory usage and optimization if your company needs help optimizing a memory hungry app.