Mongo performance tuning: tips and tricks


Published on

stuff that matters, monitoring, tuning

Published in: Technology
No Downloads
Total views
On SlideShare
From Embeds
Number of Embeds
Embeds 0
No embeds

No notes for slide

Mongo performance tuning: tips and tricks

  1. 1. Mongo performance Stuff that matters Monitoring Tuning Conclusion
  2. 2. Mongo performanceStuff that matters
  3. 3. Mongo Pain. Write lockMultiple readers / Single-writer lock( < 2.0 - has a process-wide write lock2.1.1+ per-database locking( )per-collection locking( )
  4. 4. 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;
  5. 5. 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(
  6. 6. Mongo performanceMonitoring
  7. 7. 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
  8. 8. Monitoring: SSH Consolenetstat -n | wc -lps aux | grep mongodbcat /proc/{pid}/limits | grep "Max open files"ulimit -n 65000(
  9. 9. Monitoring: Custom http://sj.malyk/admin/MongoProfileLog/milestone marks: do fake update before and after app execution
  10. 10. Mongo performanceTuning
  11. 11. Tuning: Heavy tricksdegradation - dont write to an unimportantcollections;partitioning - move an unimportantcollections to a separate replicaset.
  12. 12. 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
  13. 13. 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
  14. 14. Tuning: Explain********
  15. 15. Mongo performanceConclusion
  16. 16. 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;
  17. 17. 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
  18. 18. Mongo: Some links