Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I detect whether my code is running "inside" Sidekiq server or Puma?

I'm using Puma as a web server, and Sidekiq as my queue runner.

For multiple things (Database connections, Redis connections, other external services) I'm using the ConnectionPool gem to manage safe access to connections.

Now, depending on whether I'm running in the context of Sidekiq or of Puma, I need those pools to be different sizes (as large as the number of Sidekiq Threads or Puma threads respectively, and they are different)

What is the best way to know, in your initializers, how big to make your connection pools based on execution context?

Thanks!

like image 741
Daniel Magliola Avatar asked Feb 06 '15 13:02

Daniel Magliola


People also ask

How do I know if I have Sidekiq?

To test your Sidekiq Worker jobs array, run WorkerNameHere.jobs in terminal and see if it contains your job with your jid. If it does, then it was enqueued in Sidekiq to be run as a job.

What is Sidekiq server?

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.

How do I run on Sidekiq?

To run sidekiq, you will need to open a terminal, navigate to your application's directory, and start the sidekiq process, exactly as you would start a web server for the application itself. When the command executes you will see a message that sidekiq has started.

Is Sidekiq multithreaded?

At the same time, Sidekiq uses multithreading so it is much more memory-efficient than Rescue.


1 Answers

You use Sidekiq.server? which returns nil when not running inside the Sidekiq process itself.

like image 53
Mike Perham Avatar answered Nov 15 '22 14:11

Mike Perham