Hartator
Hartator

Reputation: 5145

Lots of Cursor Drop/Close and request to 'system.namespaces' with mongoid

I wonder if it's a normal behavior to have a fews of cursor closed and a fews query to ['system.namespaces'] per page request with mongoid ?

A sample of what I get :

Started GET "/index.html" for 127.0.0.1 at 2011-11-23 12:06:55 +0100
MONGODB ugs['system.namespaces'].find({})
...a request to MongoDB via Mongoid...
Processing by Websites::PagesController#index as */*
MONGODB ugs['system.namespaces'].find({})
MONGODB [DEBUG] Cursor#close 4936656287055121097
...a request to MongoDB via Mongoid...
MONGODB ugs['system.namespaces'].find({})
...a request to MongoDB via Mongoid...    
MONGODB [DEBUG] Cursor#close 6165957166476725254
...a request to MongoDB via Mongoid... 
MONGODB [DEBUG] Cursor#close 6639712559104429118
...a request to MongoDB via Mongoid... 
MONGODB [DEBUG] Cursor#close 6639712559104429118
...a request to MongoDB via Mongoid... 
MONGODB [DEBUG] Cursor#close 4128671431420447906
Completed 200 OK in 694ms (Views: 693.8ms)

It seems to cut the performance down, any ideas to avoid this ?

Using : Rails 3.1.2, Ruby 1.9.2, Mongoid 2.3.3, Mongo 1.4.0 and MongoDB 2.0.1.

Mongoid.yml :

development:
  host: xx.xx.xx.xx (distant)
  username: xx
  password: xx
  database: xx
  max_retries_on_connection_failure: 5
  identity_map_enabled: true

Upvotes: 0

Views: 362

Answers (1)

Tyler Brock
Tyler Brock

Reputation: 30146

It looks normal for mongoid.

This could also be because of connection pooling. Some of the MongoDB drivers use connection pooling to make concurrent requests possible.

There is some information on that here

Without seeing your code though, I'm not sure, it could be the way you've set up your queries.

Lets take a look at the docs for the ruby driver:

The driver implements connection pooling. By default, only one socket connection will be opened to MongoDB. However, if you're running a multi-threaded application, you can specify a maximum pool size and a maximum timeout for waiting for old connections to be released to the pool.

To set up a pooled connection to a single MongoDB instance:

@conn = Connection.new("localhost", 27017, :pool_size => 5, :timeout => 5) Though the pooling architecture will undoubtedly evolve, it currently owes much credit to the connection pooling implementations in ActiveRecord and PyMongo.

Ok, so by default only one connection should be opened. I don't know if mongoid changes that setting to try and increase performance. Maybe we could take a look at some of your code? Hope this info helps.

Upvotes: 2

Related Questions