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

Mongo performance tuning: tips and tricks



stuff that matters, monitoring, tuning

stuff that matters, monitoring, tuning



Total Views
Views on SlideShare
Embed Views



0 Embeds 0

No embeds



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.

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
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
  • Mongo performanceStuff that matters
  • Mongo Pain. Write lockMultiple readers / Single-writer lock( < 2.0 - has a process-wide write lock2.1.1+ per-database locking( )per-collection locking( )
  • Mongo Pain. mmap faults: will occur if you’re attempting to access partof a memory-mapped file that isn’t in memory.( )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.( isolates a write operation that affects multiple documentsfrom other write operations(
  • Mongo performanceMonitoring
  • Monitoring: HTTP Console aces/#http-console 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(
  • Monitoring: Custom http://sj.malyk/admin/MongoProfileLog/milestone marks: do fake update before and after app execution
  • 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(* Create Indexes that Support Covered Queries* Use Indexes to Sort Query Results * * 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* 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:* Consider using _id for your own purposes
  • Tuning: Explain********
  • Mongo performanceConclusion
  • Mongo: Tips and tricks* deal with db disk fragmentation: * manual defragmentation (via replica resync); ** Cant take a write lock while out of disk space: * you need some free space - db defrag will help you;
  • Mongo: Concurrency * db.auth() - lock the database but only hold the lock for a very short time why its a good idea to upgrade your mongodb
  • Mongo: Some links