部署 Passenger + Nginx 程序运行一段时间报错,没有找到具体的原因,求教

tianlitao · 2016年12月22日 · 最后由 michael 回复于 2016年12月30日 · 2083 次阅读

production.log 日志

ActiveRecord::ConnectionTimeoutError (could not obtain a database connection within 5.000 seconds (waited 5.000 seconds)):
  activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:190:in `block in wait_poll'
  activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `loop'
  activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:181:in `wait_poll'
  activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:136:in `block in poll'
  /usr/local/rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'
  activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:146:in `synchronize'
  activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:134:in `poll'
  activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:418:in `acquire_connection'
  activerecord (4.1.7) lib/active_record/connection_adapters/abstract/connection_pool.rb:351:in `block in checkout'
  /usr/local/rvm/rubies/ruby-2.0.0-p643/lib/ruby/2.0.0/monitor.rb:211:in `mon_synchronize'

nginx 配置

client_max_body_size 1000m;
passenger_max_pool_size 10;
server {
    listen       80;
      server_name  localhost;
          location / {
             root   /we/test/public;
             index  index.html index.htm;
             passenger_enabled on;
         }
}  

database.yml

development: &development
  adapter: mysql2
  encoding: utf8
  host: localhost
  database: mall
  pool: 10
  username: test
  password: 123456
  reconnect: true
  timeout: 5000

sidekiq.yml

production:
  :concurrency: 10

尝试过的解决办法: 把 pool 加大,config.ru 添加

use ActiveRecord::ConnectionAdapters::ConnectionManagement

都没有解决此问题,不定时的就会出现这个报错,找不到具体引发的原因 😭 求教

database.yml production 的配置呢?

Sidekiq concurrency 设置和一些注意事项 pool 要大于 concurrency,直接在 sidekiq.yml 和 database.yml 改。
另外有个链接 Sidekiq Advanced-Options#concurrency 也可以看看。

@huacnlee production 和 development 是一致

@hww pool 值加大了,没有效果,试过把 pool 设置为了 30,依然有此问题的

对,如果你有 Sidekiq 或其他的服务的话,需要确保哪些服务的最大进程/线程数量是在 database.yml 配置这个 pool 之下的

我要查查 DB connection 资源情况了,是 ruby 连接太多,还是 db 连接数太少?

需要 登录 后方可回复, 如果你还没有账号请 注册新账号