2016-03-24 40 views
5

我的堆栈:RoR4.2.6,Mongoid 5.0.1如何处理rails/mongoid中的出队连接超时?

我使用Apache的基准标杆我的网站,并保持击球失误类似如下:

2016-03-24 22:15:36 +0000 pid=23187, severity=FATAL, 
ActionView::Template::Error (Timed out attempting to dequeue connection after 1 sec.): 
    22: =link_to '/albums/' + mention.object.slug do 
    23:  .small-12.medium-6.large-4.columns.left 
    24:  .mention-box 
    25:   %img.mention-thumb{src: mention.object.thumb_url} 
    26:   %h5.mention-name 
    27:   = mention.object.name 
    28:   %br 
    app/models/mention.rb:13:in `object' 
    app/views/posts/_full_mention.html.haml:25:in `block in _app_views_posts__full_mention_html_haml___1744802549767261808_47000690052420' 

,并仅供参考,这是行这是越来越称为mention.rb,只是一个简单的查找查询:

def object 
    Object.const_get(type).find(mention_id) 
    end 

我的假设是,这意味着我打的MongoDB有太多的要求,它不能跟上,但不完全知道如何解决此问题。我应该为mongoid设置一个更高的队列超时时间吗?感谢任何建议!

回答

8

当初相同的问题,通过 在mongoid.yml生产配置添加wait_queue_timeout属性解决:

production: 
    clients: 
    default: 
    uri: mongodb://xxx.com:27017/mongo 
    options: 
     connect_timeout: 15 
     wait_queue_timeout: 15 
+4

yup!我最终也以这种方式解决了这个问题。谢谢你的回应! –

5

代替调整wait_queue_timeout其是用于:

的时间等待,以秒为单位在连接池中进行连接[..] [1]

我建议调整min_pool_sizemax_pool_size

的最小/连接池中的最大连接数[1]

让你的服务器/后台工作不必等待连接。

如果您使用多线程应用程序服务器(Puma)或Sidekiq内部运行应用程序,则需要设置适当大小的连接池。

[1] https://docs.mongodb.com/ecosystem/tutorial/mongoid-installation/