mperham / connection_pool

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

Timed out error with puma/rails #136

Closed negruandrei closed 3 years ago

negruandrei commented 3 years ago

Hi,

I am seeing this error when using the connection_pool gem:

exception raised is: Waited 10 sec
        /vendor/bundle/ruby/2.5.0/gems/connection_pool-2.2.2/lib/connection_pool/timed_stack.rb:87:in block (2 levels) in pop
    /vendor/bundle/ruby/2.5.0/gems/connection_pool-2.2.2/lib/connection_pool/timed_stack.rb:79:in loop
    /vendor/bundle/ruby/2.5.0/gems/connection_pool-2.2.2/lib/connection_pool/timed_stack.rb:79:in block in pop
    /vendor/bundle/ruby/2.5.0/gems/connection_pool-2.2.2/lib/connection_pool/timed_stack.rb:78:in synchronize
    /vendor/bundle/ruby/2.5.0/gems/connection_pool-2.2.2/lib/connection_pool/timed_stack.rb:78:in pop
    /vendor/bundle/ruby/2.5.0/gems/connection_pool-2.2.2/lib/connection_pool.rb:93:in checkout
    /vendor/bundle/ruby/2.5.0/gems/connection_pool-2.2.2/lib/connection_pool.rb:62:in block in with
    /vendor/bundle/ruby/2.5.0/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in handle_interrupt
    /vendor/bundle/ruby/2.5.0/gems/connection_pool-2.2.2/lib/connection_pool.rb:61:in with
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache/redis_cache_store.rb:331:in block in read_entry
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache/redis_cache_store.rb:446:in failsafe
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache/redis_cache_store.rb:330:in read_entry
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache/strategy/local_cache.rb:124:in block in read_entry
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache/strategy/local_cache.rb:78:in block in fetch_entry
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache/strategy/local_cache.rb:78:in fetch
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache/strategy/local_cache.rb:78:in fetch_entry
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache/strategy/local_cache.rb:124:in read_entry
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache/redis_cache_store.rb:74:in read_entry
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache.rb:313:in block in fetch
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache.rb:663:in block in instrument
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/notifications.rb:170:in instrument
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache.rb:663:in instrument
    /vendor/bundle/ruby/2.5.0/gems/activesupport-5.2.2/lib/active_support/cache.rb:312:in fetch

Puma version: Version 3.12.1 (ruby 2.5.3-p105), codename: Llamas in Pajamas

Redis is running locally on this VM and is running fine. connection_pool config:

 config.cache_store = :redis_cache_store, {
        url: "redis://localhost:6379/0",
        connect_timeout:    30,  # Defaults to 20 seconds
        read_timeout:       0.2, # Defaults to 1 second
        write_timeout:      0.2, # Defaults to 1 second
        reconnect_attempts: 1,   # Defaults to 0
        pool_size: 40,
        pool_timeout: 10
    }

Rails: gem 'rails', '5.2.2'

Ruby: # ruby -v ruby 2.5.3p105 (2018-10-18 revision 65156)

Can you confirm if the pool is per worker (i.e. each worker has 40 connections available) or are those 40 shared among all the workers (4 in total) ?

Thank you !

mperham commented 3 years ago

I don't know, this is a puma/rails question. It depends on how/when puma is forking. Generally, pools are per-process. (don't use the term "worker", it's nebulous)