18

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!

Daniel Magliola
  • 30,898
  • 61
  • 164
  • 243

2 Answers2

54

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

Eric Saboia
  • 1,224
  • 12
  • 14
Mike Perham
  • 21,300
  • 6
  • 59
  • 61
0

I don't know about your specific case (puma/sidekiq), but in general you can find this information in the $PROGRAM_NAME variable. Also similar are $0 and __FILE__.

stoodfarback
  • 1,299
  • 9
  • 12