Question

In SideKiq the documention says

Sidekiq.configure_server do |config|
  config.redis = {:namespace => "figs_#{Rails.env}", :size => 25, :url => 'redis://localhost:6379/0'}
end
Sidekiq.configure_client do |config|
  config.redis = {:namespace => "figs_#{Rails.env}", :size => 25, :url => 'redis://localhost:6379/0'}
end

I am curious about what does this configure_server and configure_client mean here ?

     config.redis = {:namespace => "figs_#{Rails.env}", :size => 25, :url => 'redis://localhost:6379/0'}

Is obviously the location of redis, queue type etc.

Was it helpful?

Solution

The client is anything that pushes jobs to Redis, typically your passenger, puma or unicorn process running Rails or Sinatra. The server is the Sidekiq process which pulls jobs from Redis. One complexity: a Sidekiq server process can push new jobs to Redis thus acting like a client too!

config/sidekiq.yml is meant to allow the same config as command line args. The initializer is meant for more complicated config which requires Ruby, for instance the Redis connection info or custom middleware.

OTHER TIPS

I like to think about it as it applies to Heroku. There are two main processes (dynos) web, and worker.

Dynos that are of type web are where your application (web server) runs from and thus all connections from the router are delivered to your web dynos for your application to serve a response to.

Dynos that are of type worker are where your background jobs are processed on. It is where Sidekiq executes it's perform method in, that way it doesn't block on your web dyno.

It is in web dynos that Sidekiq.configure_client is run from. It configures how your web dyno connects to Sidekiq and submits jobs.

It is in worker dynos that Sidekiq.configure_server is run from. It configures how your worker dyno connects to Sidekiq and processes jobs.

from Railscasts

Sidekiq has client-side middleware which runs before a job is inserted into Redis and server-side which runs before the job is processed. This middleware retrying jobs, logging them and handling exceptions.

So you can set for example size 25 for processing jobs (server-side) and 10 for adding jobs to queue (client side). This should increase probability of make queue empty.

But I still do not understand why there is some configuration in config/initializers/sidekiq.rb and some other, but similiar in /config/sidekiq.yml (see Sidekiq:Advanced options)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top