-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Memory
Sidekiq uses memory. You'll see memory consumed booting Rails, loading your application code and running your jobs.
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.
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.
- 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
- Use
derailed_benchmarks
to find gems in your Gemfile which need a diet. - Switch to
jemalloc
. Ruby 2.7 works great with jemalloc 5.x.
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.