【问题标题】:Sidekiq fails, dequeueing mongoid connection times out, probably too many connectionsSidekiq 失败,dequeueing mongoid 连接超时,可能连接太多
【发布时间】:2016-06-18 15:21:42
【问题描述】:

我目前正在运行sidekiq 4.1.2。我从来没有设法同时运行多个作业。最近,我似乎遇到了 Sidekiq 的故障排除 WIKI 中描述的一个问题,称为Too many connections to MongoDB。显然,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 load cpu太多了。

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

根据我的 Sidekiq Web 界面,我有 1 个队列,称为 default,有 25 个线程。最大限度。其中 12-15 人同时忙。

知道如何解决这个问题吗?

【问题讨论】:

  • 你试过使用 kiqstand 吗? github.com/mongoid/kiqstand
  • 不,但这仅适用于 Mongoid 3。根据自述文件,我不需要它用于较新的版本。

标签: ruby-on-rails mongodb mongoid sidekiq sidetiq


【解决方案1】:

默认的最大池队列大小为 5。将 max_pool_size 增加到例如25 将启用与您的数据库的更多连接。

production:
  clients:
    default:
      options:
        max_pool_size: 25

【讨论】:

    【解决方案2】:

    更改在 mongoid.yml 生产配置中添加 wait_queue_timeout 属性:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-11-11
      • 1970-01-01
      • 2021-04-07
      • 1970-01-01
      相关资源
      最近更新 更多