Ruby on rails Sidekiq失败,mongoid连接超时,可能连接太多

Ruby on rails Sidekiq失败,mongoid连接超时,可能连接太多,ruby-on-rails,mongodb,mongoid,sidekiq,sidetiq,Ruby On Rails,Mongodb,Mongoid,Sidekiq,Sidetiq,我目前正在运行sidekiq 4.1.2。我从来没有能够同时处理超过一把的工作。最近,我似乎遇到了Sidekiq的疑难解答WIKI中描述的一个问题,名为。显然,mongoid 3没有正确地断开工人的连接。但是,我使用的是mongoid 5.1.3 当一个作业在运行其他几个作业时,试图通过查询访问数据库时,我的问题就会出现: Timeout::Error: Timed out attempting to dequeue connection after 30 sec. /home/me/appli

我目前正在运行
sidekiq 4.1.2
。我从来没有能够同时处理超过一把的工作。最近,我似乎遇到了Sidekiq的疑难解答WIKI中描述的一个问题,名为。显然,
mongoid 3
没有正确地断开工人的连接。但是,我使用的是
mongoid 5.1.3

当一个作业在运行其他几个作业时,试图通过查询访问数据库时,我的问题就会出现:

Timeout::Error: Timed out attempting to dequeue connection after 30 sec.
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/connection_pool/queue.rb:190:in `wait_for_next!'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/connection_pool/queue.rb:176:in `block in dequeue_connection'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/connection_pool/queue.rb:190:in `wait_for_next!'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/connection_pool/queue.rb:176:in `block in dequeue_connection'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/connection_pool/queue.rb:172:in `loop'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/connection_pool/queue.rb:172:in `dequeue_connection'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/connection_pool/queue.rb:62:in `block in dequeue'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/connection_pool/queue.rb:61:in `synchronize'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/connection_pool/queue.rb:61:in `dequeue'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/connection_pool.rb:51:in `checkout'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/connection_pool.rb:107:in `with_connection'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/server/context.rb:63:in `with_connection'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/operation/executable.rb:34:in `execute'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/collection/view/iterable.rb:80:in `send_initial_query'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/collection/view/iterable.rb:41:in `block in each'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/retryable.rb:51:in `call'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/retryable.rb:51:in `read_with_retry'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongo-2.2.5/lib/mongo/collection/view/iterable.rb:39:in `each'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongoid-5.1.3/lib/mongoid/query_cache.rb:207:in `each'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongoid-5.1.3/lib/mongoid/contextual/mongo.rb:121:in `each'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongoid-5.1.3/lib/mongoid/contextual/mongo.rb:295:in `map'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongoid-5.1.3/lib/mongoid/contextual/mongo.rb:295:in `map'
/home/me/applications/myapp/shared/bundle/ruby/2.2.0/gems/mongoid-5.1.3/lib/mongoid/contextual.rb:20:in `map'
/home/me/applications/myapp/releases/20160618143407/app/jobs/myjob.rb:8:in `block in perform'
一个作业失败后,其他作业很快就会失败。这通常发生在几手作业成功完成后,这可能表明这些作业没有与数据库断开连接。查看
top
我看不出mongo的cpu负载太大

与此同时,我注意到我的
sidetiq 0.7.0
启用的定期作业没有正确调度。一个作业已停止排队,其他作业在重新启动后仅排队一次

根据我的Sidekiq web界面,我有一个队列,名为default,有25个线程。最多12-15人同时忙碌


知道如何解决此问题吗?

更改mongoid.yml生产配置中添加wait\u queue\u timeout属性:

production:
  clients:
    default:
     uri:  mongodb://aaaaa.com:27017/mongo
     options:
       connect_timeout: 30
       wait_queue_timeout: 30

默认的最大池队列大小为5。将
max\u pool\u size
最大值增加到例如25,将启用到数据库的更多连接

production:
  clients:
    default:
      options:
        max_pool_size: 25

你试过使用kiqstand吗?没有,但只适合Mongoid 3。根据自述文件,我不需要更新版本。