Mongo performance tuning: tips and tricks
Upcoming SlideShare
Loading in...5
×
 

Mongo performance tuning: tips and tricks

on

  • 1,825 views

stuff that matters, monitoring, tuning

stuff that matters, monitoring, tuning

Statistics

Views

Total Views
1,825
Views on SlideShare
1,825
Embed Views
0

Actions

Likes
2
Downloads
12
Comments
1

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Mongo performance tuning: tips and tricks Mongo performance tuning: tips and tricks Presentation Transcript

  • Mongo performance Stuff that matters Monitoring Tuning Conclusion vladimir.malyk@gmail.com
  • Mongo performanceStuff that matters
  • Mongo Pain. Write lockMultiple readers / Single-writer lock( http://en.wikipedia.org/wiki/Readers-writer_lock)ver < 2.0 - has a process-wide write lock2.1.1+ per-database locking( https://jira.mongodb.org/browse/SERVER-4328 )per-collection locking( https://jira.mongodb.org/browse/SERVER-1240 )
  • Mongo Pain. mmap http://docs.mongodb.org/manual/faq/storage/Page faults: will occur if you’re attempting to access partof a memory-mapped file that isn’t in memory.( http://docs.mongodb.org/manual/reference/glossary/#term-page-fault )Performance: page fault can take around 40,000 timeslonger than a nonfaulting memory operation ver 2.0+, this is addressed by detecting the likelihood of a page fault and releasing the lock before faulting - YIELD operation; SSD is a doctors stuff in this case;
  • Mongo AtomicityWrite operations are atomic on the level of a singledocument: no single write operation can atomically affect morethan one document or more than one collection.(http://docs.mongodb.org/manual/tutorial/isolate-sequence-of-operations/)hint: isolates a write operation that affects multiple documentsfrom other write operations(http://docs.mongodb.org/manual/reference/operator/isolated/)http://docs.mongodb.org/manual/reference/command/findAndModify/
  • Mongo performanceMonitoring
  • Monitoring: HTTP Console http://docs.mongodb.org/ecosystem/tools/http-interf aces/#http-console http://dbhost.net:28017/ Replica Set Admin UI, Oplog status clients DBTOP write lock % time in write lock, by 4 sec periods (form ~12% to~6%) Log - By default the slow operation threshold is 100 millis
  • Monitoring: SSH Consolenetstat -n | wc -lps aux | grep mongodbcat /proc/{pid}/limits | grep "Max open files"ulimit -n 65000(http://www.andrewrollins.com/2010/10/20/mongodb-open-file-limit/)
  • Monitoring: Custom http://sj.malyk/admin/MongoProfileLog/milestone marks: do fake update before and after app executionhttp://docs.mongodb.org/manual/tutorial/manage-the-database-profiler/http://docs.mongodb.org/manual/reference/database-profiler/https://gist.github.com/vladimir-malyk/5047107https://gist.github.com/kgorman/995a3aa5b35e92e5ab57
  • Mongo performanceTuning
  • Tuning: Heavy tricksdegradation - dont write to an unimportantcollections;partitioning - move an unimportantcollections to a separate replicaset.
  • Tuning: Indexes* Create Indexes to Support Your Queries* Use Compound Indexes to Support Several Different Queries * -10% write performance for each additional index(http://www.slideshare.net/mongodb/mongodb-performance-tuning)* Create Indexes that Support Covered Queries* Use Indexes to Sort Query Results * http://blog.mongolab.com/2012/06/cardinal-ins/ * First, fields on which you will query for exact values. * Second, fields on which you will sort. * Finally, fields on which you will query for a range of val.* Ensure Indexes Fit RAM* Creating index on a big collection takes a lot of time with writelock
  • Tuning: Common tricks http://blog.serverdensity.com/mongodb-schema-design-pitfalls/* Avoid growing documents (“moved” in system.profile)* Use field modifiers: Instead of sending a whole new documentto update an existing one, you can set or remove specific fields* Preallocate documents: preallocate the document withplaceholder values, then use the $set field modifier to change theactual value later* Field names take up space:http://blog.serverdensity.com/on-shortened-field-names-in-mongodb/* Consider using _id for your own purposes
  • Tuning: Explain http://docs.mongodb.org/manual/reference/explain/* http://docs.mongodb.org/manual/reference/explain/#explain.cursor* http://docs.mongodb.org/manual/reference/explain/#explain.net* http://docs.mongodb.org/manual/reference/explain/#explain.nscanned* http://docs.mongodb.org/manual/reference/explain/#explain.n* http://docs.mongodb.org/manual/reference/explain/#explain.scanAndOrder* http://docs.mongodb.org/manual/reference/explain/#explain.indexOnly* http://docs.mongodb.org/manual/reference/explain/#explain.nYields* http://docs.mongodb.org/manual/reference/explain/#explain.allPlans
  • Mongo performanceConclusion
  • Mongo: Tips and tricks* deal with db disk fragmentation: * manual defragmentation (via replica resync); * http://docs.mongodb.org/manual/reference/command/compact/* Cant take a write lock while out of disk space: * you need some free space - db defrag will help you;
  • Mongo: Concurrency http://docs.mongodb.org/manual/faq/concurrency/http://docs.mongodb.org/manual/faq/concurrency/#how-do-i-see-the-status-of-locks-on-my-mongod-instanceshttp://docs.mongodb.org/manual/faq/concurrency/#which-operations-lock-the-databasehttp://docs.mongodb.org/manual/faq/concurrency/#which-administrative-commands-lock-the-database * db.auth() - lock the database but only hold the lock for a very short time http://blog.serverdensity.com/goodbye-global-lock-mongodb-2-0-vs-2-2/ why its a good idea to upgrade your mongodb
  • Mongo: Some linkshttp://www.slideshare.net/mongodb/mongodb-performance-tuninghttp://blog.pythonisito.com/2011/12/mongodbs-write-lock.html