How can I use connection timeouts in rails / mongoid?

My stack: RoR4.2.6, Mongoid 5.0.1

I am comparing my site using apache test and am making the following errors:

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' 

and for reference only, this is the line called up in the .rb mention, just a simple search request:

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

My guess is that this means that I am pushing mongoDB with too many requests, and it cannot keep up, but I'm not quite sure how to resolve this. Should I just set a higher queue timeout for the mongoid? Appreciate any advice!

+5
source share
2 answers

If the same problem, resolved by adding the wait_queue_timeout attribute to the mongoid.yml configuration:

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

Instead of setting wait_queue_timeout , which is intended for:

The timeout in seconds in the connection pool for the connection [..] [1]

I suggest min_pool_size and max_pool_size .

Minimum / maximum number of connections in the connection pool [1]

therefore, your server / background worker does not need to wait for a connection.

If you use the application using a multi-threaded application server (Puma) or inside Sidekiq, you need to configure the connection pool with the appropriate size.

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

+5
source

Source: https://habr.com/ru/post/1245736/


All Articles