简体   繁体   English

{model name} 没有连接池

[英]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:我们有一个 rails 4 应用程序,它有一个计划的 rake 任务,它将产生 sidekiq 工作人员,我们开始看到错误:

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.我们尝试在 sidekiq 设置中降低并发性并在数据库设置中增加池大小,但尚未解决问题,并且我们一直在应用程序中为模型获取No connection pool for

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好像补丁很老了,我们可以看到这篇文章提到了它: https://medium.com/points-san-francisco/threading-with-rails-eeb843bfa20

The article mentions that the patch is not working for Rails 5 upwards.文章提到该补丁不适用于 Rails 5 以上版本。 So if your Rails app is still stuck at Rails 4 it may be the reason.因此,如果您的 Rails 应用程序仍然卡在 Rails 4 上,这可能就是原因。

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.但基本上,如果您的数据库池等于Rails_max_thread (考虑到您的网络服务器是 Puma),那么它可能会在某个时候达到可用数据库连接的最大数量,然后需要为数据库匹配资源(RAM、计算等)。 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)默认 Rails 最大线程数为 5,这经常被讨论https://twitter.com/nateberkopec/status/1564689914830229504?s=20&t=2uzgF8xYNRzgWtjEJuvfEQ但您可以通过将线程数减少到类似 3 并增加线程数来减轻数据库负载Puma 并发(Puma 工人)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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