MM Logged Time¶ ↑
MM Logged Time logs query and load times for MongoMapper, like so:
(0.5ms) all query mm-test-1-8-7.parakeets {:name=>“Bro”} (0.1ms) all load mm-test-1-8-7.parakeets {:name=>“Bro”}
Load time is logged separately because sometimes MongoMapper, not MongoDB, is the bottleneck:
(48.6ms) all query mes-geo.places {:ancestor_ids=>2347581, … } (623.7ms) all load mes-geo.places {:ancestor_ids=>2347581, … }
When you run into such a problem you may have to skip MongoMapper and use the Mongo Ruby driver, or hack a MongoMapper document that doesn’t use the Dirty plugin. (Removing the Dirty plugin can halve the load time. The Ruby driver is even faster, its “load time” is already reflected in the query time above.)
Installation¶ ↑
Add mm-logged-time to your Gemfile:
gem ‘mm-logged-time’
You may wish to only include it in your development group:
group :development do gem ‘mm-logged-time’ end
Once you have MongoMapper set up with a logger, you can turn on logged time. You don’t need to be running Rails, but for example in my Rails app I have this in mongo_config.rb:
if Rails.env == “development” MongoMapper.connection = Mongo::Connection.new(‘localhost’, 27017, :logger => Rails.logger) require ‘mm_logged_time’ # this overrides first, last, and all MongoMapper.logged_time_level = Logger::DEBUG end
To turn it off either set the logger to a less verbose level, or:
MongoMapper.logged_time_level = nil
That’s it. Happy logging!
Warning¶ ↑
The only want to separate out MongoMappers’s load and query was to totally clobber some functions in MM’s source. Future updates to MongoMapper could cause this gem to break your app.
Of course, gem updates to an app are always fickle in my experience. Please don’t be deterred from using mm-logged-time. Gem updates == breakage. Just be aware that mm-logged-time could be the culprit if you update MongoMapper.
Development/Tests¶ ↑
gem install bundler bundle bundle exec rake
Pull Requests¶ ↑
Pull requests, bug reports, and feedback are welcome!
License¶ ↑
Public domain.