Search code examples
ruby-on-railssidekiqpuma

Is it possible to run Sidekiq in the same process with a puma rails server?


Is there anything in its architecture that makes it hard to do?

I want to run an existing rails+sidekiq application in a VM with very little memory, and loading the entire rails stack in two different process is using a lot of RAM.


Solution

  • Puma is built to spin up homogenous web worker threads, and divide incoming requests among them. If you wanted to modify it to spawn off separate Sidekiq threads, it should technically be possible with a crazy puma.rb file, but there's no precedent I can find for doing so (edit: Mike’s answer below points out that the sucker_punch gem can essentially do this, for the same purpose of memory efficiency). Practically-speaking, if your VM cannot support running two Rails processes at a time, it probably won't be able to handle the increased memory load as your application does the work of both Sidekiq and Puma… but that depends on your workload.

    If this is just for development purposes, you might be able to accomplish what you're looking for by turning on Sidekiq's inline mode (normally meant just for testing):

    require 'sidekiq/testing'
    Sidekiq::Testing.inline!
    

    This will cause all perform_async calls to actually execute inline, instead of going into Redis and being picked up by the Sidekiq process.