简体   繁体   中英

No connection pool for {model name}

We have a rails 4 app that has a scheduled rake task, which will spawn sidekiq workers, and we started to see errors:

An ActiveRecord::ConnectionNotEstablished occured in background
Exception
No connection pool for User

config/initializers/leaked_connections.rb:44:in `connection_with_forbid_implicit'
lib/ads_apis/ads_geo_targeter_base.rb:75:in `seeder_sync_targeting'

which is simply:

user = User.find(user_id)

we tried to lower the concurrency at sidekiq settings and increasing the pool size at the database settings, but hasn't fixed the issue, and we keep getting No connection pool for for models at the app.

Is there any hint to investigate this?

Seems like the patch is pretty old, we can see it mentionned in this article: https://medium.com/points-san-francisco/threading-with-rails-eeb843bfa20

The article mentions that the patch is not working for Rails 5 upwards. So if your Rails app is still stuck at Rails 4 it may be the reason.

Also the point of this patch is to alleviate the database load. But basically if your db pool is equal to Rails_max_thread (considering your webserver is Puma) then it may reach the max number of available database connections at some point and then require matching resources (RAM, computing etc ) for the database. Then I am not too sure in what aspect the patch would be that useful..

Default Rails max threads is 5, and this is often discussed https://twitter.com/nateberkopec/status/1564689914830229504?s=20&t=2uzgF8xYNRzgWtjEJuvfEQ but you may alleviate the database load by reducing the number of threads to something like 3 and increasing Puma concurrency (Puma workers)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM