No commit activity in last 3 years
No release in over 3 years
StackProf and MemoryProfiler middleware for Sidekiq
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

= 0.54.0
 Project Readme

sidekiq_profiling_middleware

Profile Sidekiq with StackProf & MemoryProfiler with optional support for S3 exports.

Installation

Two middleware classes are available:

  • SidekiqProfilingMiddleware::StackProf: requires stackprof
  • SidekiqProfilingMiddleware::MemoryProfile: requires memory_profiler

(You should only use one at a time, otherwise that will be quite confusing)

require "sidekiq_profiling_middleware/stack_prof"

Sidekiq.configure_server do |config|
  ....
  config.server_middleware do |chain|
    chain.add(
      SidekiqProfilingMiddleware::StackProf,
      only: [ThisReallySlowWorker].to_set,
      s3_bucket: "cj-profiling",
      output_prefix: "stackprof/#{ENV["GIT_SHA]}_",
    )
    # OR
    chain.add SidekiqProfilingMiddleware::StackProf, output_prefix: "tmp/#{Rails.env}_#{ENV["GIT_SHA"]}_"
  end
end

Concurrency (set it to 1)

The hooks provided by Ruby that are used by StackProf & MemoryProfiler are not able to distinguish threads well, so you will need to set your Sidekiq concurrency to 1. This will ensure that only one job operates at a time ensuring other jobs don't confuse your memory profile or stacktraces.

With this in mind you should set this up on a separate Sidekiq instance so as not to drop the concurrency capability of your Sidekiq cluster.

S3 exporting

If you run Sidekiq in a Dockerized environment like ECS or Kubernetes you will probably not want profiling reports dumped to a filesystem path as you don't want to bloat the container size and track down which Docker host contains the profiles. To solve this you can have profiles uploaded to S3 using the option s3_bucket.

The AWS SDK is used so you'll want to set your AWS config/credentials using environment variables or EC2 instance profiles (preferred when running inside AWS). See Setup Config for more info.

Alternatively you can configure the client using SidekiqProfilingMiddleware::S3.client = ......