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

tianlitao · 发布于 2016年12月22日 · 最后由 michael 回复于 2016年12月30日 · 542 次阅读
14602

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

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

共收到 5 条回复
De6df3

database.yml production 的配置呢?

14293

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

14602

@huacnlee production 和development 是一致

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

De6df3

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

2556

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

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