mperham / connection_pool

Generic connection pooling for Ruby
MIT License
1.63k stars 143 forks source link

Can I "warm" a ConnectionPool? #85

Closed rmosolgo closed 8 years ago

rmosolgo commented 8 years ago

Hi, thanks for the great gem! We use it in react-rails for server rendering.

Let's say my pool is:

ConnectionPool.new { really_long_setup }

And later I'm going to need 10 of those. Is there a way I can do the really_long_setup ahead of time?

I thought maybe

pool_size.times do 
  pool.with { |member| member }
end

but I would expect that to use the same member each time. (Also, I'm not sure how I could tell if the pool was initialized or not.)

mperham commented 8 years ago

You can perform some work or instantiate the first resource in a Rails initializer but there's no easy way to make a connection pool eager load its resources. Do you mean that all 10 elements require a long setup to create? If so, I'm not sure there's any easy solution to your problem.

rmosolgo commented 8 years ago

Fair 'nuf, I think one would be enough. (Basically, for production, I'd rather raise errors at startup instead of randomly at runtime whenever the pool gets hit.)

Thanks!