SlideShare a Scribd company logo
Technical Services Engineer, Palo Alto, CA @ MongoDB
Daniel Coupal
#MongoDB
Performance Tuning and
Monitoring Using MMS
2 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Agenda
1. What and who is MMS for?
2. Performance and monitoring examples
3. Setting it up and getting around
4. Wrapping up
5. Q&A
MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
1. What and who is MMS for?
4 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
What is MMS?
The MongoDB Management Service
• a free Cloud service for monitoring and
managing your MongoDB clusters
• or available to run On-Prem for
customers with the Standard or
Enterprise Subscriptions
• tool that makes MongoDB easier to use
5 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Who is MMS for?
• Developers
– Track bottlenecks
• Ops Team
– Monitor health of the clusters
– Backup databases
– Automate updates and add capacity
• MongoDB Technical Service Team
“For years, MongoDB has been planning to do monitoring right.“
“We want the Ops People to have the same enthusiasm as the Developers.”
6 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
What is in MMS?
A. Monitoring
1. Cloud: Sept 2011
2. On-Prem: July 2013
B. Backups
1. Cloud: April 2013
2. On-Prem: April 2014
C. Automation
1. Cloud: April 2014 (Beta)
7 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
What is in MMS monitoring?
A. Metric Collection and Reporting
B. Alerting
(Email, SMS, PagerDuty, HipChat, SNMP)
C. Event Tracking
D. Database Stats
E. Hardware Stats
F. Logs and Profile Data
8 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
A. Metric Collection and Reporting
9 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
B. Alerting
10 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
C. Event Tracking
11 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
D. Database Stats
12 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
E. Hardware Stats (CPU, disk)
13 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
F. Logs and Profile Data
MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
2. Performance tuning and monitoring
15 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
How to do performance tuning?
1. Assess the problem and establish acceptable behavior
2. Measure the current performance
3. Find the bottleneck*
4. Remove the bottleneck
5. Re-test to confirm
6. Repeat
* - (This is often the hard part)
(Adapted from http://en.wikipedia.org/wiki/Performance_tuning )
16 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Pro-Tip: know thyself
You have to recognize normal to know when it isn’t.
Source: http://www.flickr.com/photos/skippy/6853920/
17 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Some handy metrics to watch
• Memory usage
• Opcounters
• Lock %
• Queues
• Background flush average
• Replication
– Replication oplog window
– Replication lag
18 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Fun fact: oplog idempotency
• Operations in the oplog only affect the value once, so
they can be run multiple times safely.
• Examples
– If you increment n from 2 to 3, n = 3 is fine; n + 1 is not.
– Updating all documents that match a query is not, list of
documents to update is.
• Frequent, large updates means a big oplog to sync.
• Updates that change a set mean writing the entire
new version of the set to the oplog.
19 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 1: replication lag
Scenario:
Customer reports 150,000s of replication lag.
Equals to almost 2 days of lag!
20 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 1: replication lag
Some common causes of replication lag:
• Secondaries underspec’d vs primaries
• Access patterns between primary and
secondaries
• Insufficient bandwidth
• Foreground index builds on secondaries
“…when you have eliminated the impossible, whatever remains,
however improbable, must be the truth…” -- Sherlock Holmes
Sir Arthur Conan Doyle, The Sign of the Four
21 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 1: replication lag
Example:
• ~1500 ops per minute (opcounters)
• 0.1 MB per object (average object size, local db)
• ~1500 ops/min / 60 seconds * 0.1 MB/op * 8b/B
=~ 20 mbps required bandwidth
 Huge updates (oplog is idempotent) translated to 30
mbps, while they only had 10 mbps
22 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Lesson: remember to use alerts!
Don’t wait until your secondaries fall off
your oplog!
23 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Scenario:
• User-facing web application with social functionality.
• Customer was seeing significant performance
degradation after adding and removing an index from
their replicaset.
• Their replicaset had 2 visible data-bearing nodes,
each on real hardware, with dedicated 15K RPM disks
and a significant amount of RAM.
• Why were things slow?
24 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Opcounters: queries rose a bit, however writes
were flat…
25 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Background flush average: went up
considerably!
26 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Queues: also went up considerably!
27 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Journal stats: went up much higher than
the ops…
28 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Connections: also went up…
29 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Background flush average: consistent
until then
30 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Opcounters: interesting… around July 9th
31 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Page faults: something’s going on!
32 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Local DB average object size: growing!
33 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Now what?
Time to analyze the logs
What query or queries were going crazy?
And what sort of query would grow in size
without growing significantly in volume?
Remember:
Growing disk latency (caused by page faults?)
And journal/oplog entries growing even
though writes (inserts/updates) were flat.
34 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Log analysis
The best tools for analyzing MongoDB
logs are included in mtools*:
• mlogfilter
filter logs for slow queries, collection scans, …
• mplotqueries
graph query response times and volumes
* https://github.com/rueckstiess/mtools
35 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Log analysis (example syntax)
Show me queries that took more than
1000 ms from 6 am to 6 pm:
mlogfilter mongodb.log --from 06:00 --to
18:00 --slow 1000 > mongodb-filtered.log
Now, graph those queries:
mplotqueries --logscale mongodb-filtered.log
36 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
37 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Filter more!
--operation
Logarithmic!
--logscale
38 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Sample query
Wed Jul 17 14:16:44 [conn60560] update x.y query: { e:
”[id1]" } update: { $addToSet: { fr: ”[id2]" } }
nscanned:1 nupdated:1 keyUpdates:1 locks(micros) w:889
6504ms
6.5 seconds to add a single value to a set!
39 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
http://docs.mongodb.org/manual/reference/operator/addToSet/
The $addToSet operator adds a value to an array only if
the value is not in the array already. If the value is in the
array, $addToSet returns without modifying the array.
Consider the following example:
db.collection.update({field:value}, {$addToSet: {field:value1}});
Here, $addToSet appends value1 to the array stored in
field, only if value1 is not already a member of this array.
40 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
https://jira.mongodb.org/browse/SERVER-8192
“IndexSpec::getKeys() finds the set of index keys for a given
document and index key spec. It's used when inserting / updating /
deleting a document to update the index entries, and also for
performing in memory sorts, deduping $or clauses and for other
purposes.
Right now extracting 10k elements from a nested object field within
an array takes on the order of seconds on a decently fast machine.
We could see how much we can optimize the implementation.”
41 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
What else?!
• Wed Jul 17 14:11:59 [conn56541] update x.y query: {
e: ”[id1]" } update: { $addToSet: { fr: ”[id2]" } }
nscanned:1 nmoved:1 nupdated:1 keyUpdates:0
locks(micros) w:85145 11768ms
• Almost 12 seconds!
This time, there’s “nmoved:1”, too.
This means a document was moved on
disk, it outgrew the space allocated for it.
42 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Wait, there’s more!
• Wed Jul 17 13:40:14 [conn28600] query x.y [snip]
ntoreturn:16 ntoskip:0 nscanned:16779 scanAndOrder:1
keyUpdates:0 numYields: 906 locks(micros) r:46877422
nreturned:16 reslen:6948 38172ms
• 38 seconds! Scanned 17k documents,
returned 16.
43 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
What next?
Short term fix: disable the new feature for
the heaviest users! After that:
• rework the code to avoid $addToSet
• add indexes for queries scanning collections
• use powerOf2Sizes
(http://docs.mongodb.org/manual/reference/command/collMod/)
to reduce fragmentation and document moves
44 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Example 2: slow performance
Did it work?
(Yes.)
(So far. ;) )
45 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Monitoring: watch for warnings
MMS warns you if your systems
a) are running outdated versions
b) have startup warnings
c) if a mongod is publicly visible
Don’t ignore these warnings!
MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
3. Setting it up and getting around
47 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Setting up monitoring for the Cloud
http://mms.mongodb.com/help/monitoring/tutorial/
• Setup an account (Free)
• Install the agent
– Download the binary
– Set the API key in the configuration file
• Add your hosts
– Add a seed host, MMS will discover the cluster
• Optional: hardware stats through Munin-node
• Optional: enable logging and profiling
48 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Setting up monitoring “On-Prem”
• Available (included) to Customers with
– Enterprise subscription
– OR Standard subscription
• One host to run the server for up to 400 hosts
• One RPM/Deb package to install
• Installing the backup requires more planning
and more resources (hosts, disks, …)
– The alternative is use MMS Backups in the Cloud,
we removed the complexity for you.
49 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
MMS Monitoring Architecture
50 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
List of monitored hosts
51 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Notes
• Agent written in Go
• Failover: run multiple agents (1 primary)
• Hosts: use CNAMEs, especially on AWS!
• You can use a group per environment (each needs an
agent)
• Connections are over SSL
• On-Prem solution for Enterprise or Standard
customers that don’t want to use the hosted service
• Makes it easier for the technical services to help you!
MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
4. Wrapping up
53 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
The Technical Services Team
• We are here to make you successful,
open tickets
– We support 1000s of customers
– Another customer may had the same issue
as you
• Throw any problems to the Technical
Services Team
54 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
What’s next for MMS?
• Continuous updates
– Cloud: ~every 3 weeks
– On-Prem: ~every 3 months
• Automation service
• A lot of more information at:
MongoDB World 2014 @
NYC on June 23-25
55 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Summary
• MMS is a great, free service
• Setup is easy
• Metrics and graphs are awesome
• Preventing failures even more awesome
• Using MMS makes it easier for the
Technical Services Team to help you
• Monitor your DBs like a Pro, use MMS
MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
5. Questions?
MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Appendix
58 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Other MMS References
• Tons of webinars and other presentations
http://www.mongodb.com/presentations
• Five MMS Monitoring Alerts to Keep Your MongoDB Deployment on Track
http://www.mongodb.com/blog/post/five-mms-monitoring-alerts-keep-your-
mongodb-deployment-track
• Digging into the meaning of some metrics
– Lock % : http://blog.mms.mongodb.com/post/78650784046/learn-about-lock-percentage-concurrency-
in-mongodb
– Replication Oplog Window : http://blog.mms.mongodb.com/post/77279440964/replica-set-health-is-
more-than-just-replication-lag
• How to fix some warnings reported by MMS
– http://docs.mongodb.org/manual/administration/production-notes/
(includes readahead settings)
59 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Examining memory and disk
Memory: resident vs virtual vs non-mapped
60 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Examining memory and disk
Page faults and Record Stats
61 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Examining memory and disk
Background flush and Disk IO
(Check out http://www.wmarrow.com/strcalc/ )
MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal
Thank you for using

More Related Content

PDF
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
PPTX
Mongo db pefrormance optimization strategies
PDF
mongoDB Performance
PDF
10 Key MongoDB Performance Indicators
PDF
Mongo performance tuning: tips and tricks
PPTX
Concurrency Patterns with MongoDB
PDF
MongoDB World 2016: From the Polls to the Trolls: Seeing What the World Think...
PDF
MongoDB memory management demystified
MongoDB performance tuning and load testing, NOSQL Now! 2013 Conference prese...
Mongo db pefrormance optimization strategies
mongoDB Performance
10 Key MongoDB Performance Indicators
Mongo performance tuning: tips and tricks
Concurrency Patterns with MongoDB
MongoDB World 2016: From the Polls to the Trolls: Seeing What the World Think...
MongoDB memory management demystified

What's hot (20)

PDF
How to monitor MongoDB
PPTX
Webinar: Performance Tuning + Optimization
PDF
Optimizing MongoDB: Lessons Learned at Localytics
PPTX
Understanding and tuning WiredTiger, the new high performance database engine...
PDF
Postgres connections at scale
PPTX
Back to Basics Webinar 6: Production Deployment
PDF
Mongodb replication
PPTX
Breaking the Oracle Tie; High Performance OLTP and Analytics Using MongoDB
PDF
Development to Production with Sharded MongoDB Clusters
PPTX
Back to Basics Spanish Webinar 3 - Introducción a los replica sets
PDF
Mongodb
PPTX
Back to Basics 2017: Introduction to Sharding
PDF
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
PPTX
MongoDB - External Authentication
KEY
MongoDB Command Line Tools
PPTX
Back to Basics Spanish 4 Introduction to sharding
PPTX
MongoDB Auto-Sharding at Mongo Seattle
PPT
MongoDB Basic Concepts
PDF
Setting up mongodb sharded cluster in 30 minutes
KEY
MongoDB Best Practices in AWS
How to monitor MongoDB
Webinar: Performance Tuning + Optimization
Optimizing MongoDB: Lessons Learned at Localytics
Understanding and tuning WiredTiger, the new high performance database engine...
Postgres connections at scale
Back to Basics Webinar 6: Production Deployment
Mongodb replication
Breaking the Oracle Tie; High Performance OLTP and Analytics Using MongoDB
Development to Production with Sharded MongoDB Clusters
Back to Basics Spanish Webinar 3 - Introducción a los replica sets
Mongodb
Back to Basics 2017: Introduction to Sharding
Evolution of MonogDB Sharding and Its Best Practices - Ranjith A - Mydbops Team
MongoDB - External Authentication
MongoDB Command Line Tools
Back to Basics Spanish 4 Introduction to sharding
MongoDB Auto-Sharding at Mongo Seattle
MongoDB Basic Concepts
Setting up mongodb sharded cluster in 30 minutes
MongoDB Best Practices in AWS
Ad

Similar to MongoDB Performance Tuning and Monitoring (20)

PPTX
MongoDB performance tuning and monitoring with MMS
PPTX
Performance Tuning and Monitoring Using MMS
PPTX
Performance Tuning On the Fly at CMP.LY Using MongoDB Management Service
PPTX
Performance Tuning on the Fly at CMP.LY
PPTX
Is It Fast? : Measuring MongoDB Performance
PDF
Silicon Valley Code Camp 2014 - Advanced MongoDB
PPT
Evolution and Scaling of MongoDB Management Service Running on MongoDB
PDF
MongoDB Performance Tuning
PPTX
MongoDB Deployment Checklist
PPTX
Performance Tuning Cheat Sheet for MongoDB
PPTX
1404 app dev series - session 8 - monitoring & performance tuning
PDF
MMS: The Easiest Way to Run MongoDB
PPTX
How to learn MongoDB for beginner's
PPTX
Performance Tuning and Optimization
PDF
Silicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
PPTX
Conceptos básicos. Seminario web 6: Despliegue de producción
PPTX
An Introduction to MongoDB Ops Manager
PDF
Mongo db improve the performance of your application codemotion2016
PDF
Silicon Valley Code Camp 2016 - MongoDB in production
PPTX
Automated Slow Query Analysis: Dex the Index Robot
MongoDB performance tuning and monitoring with MMS
Performance Tuning and Monitoring Using MMS
Performance Tuning On the Fly at CMP.LY Using MongoDB Management Service
Performance Tuning on the Fly at CMP.LY
Is It Fast? : Measuring MongoDB Performance
Silicon Valley Code Camp 2014 - Advanced MongoDB
Evolution and Scaling of MongoDB Management Service Running on MongoDB
MongoDB Performance Tuning
MongoDB Deployment Checklist
Performance Tuning Cheat Sheet for MongoDB
1404 app dev series - session 8 - monitoring & performance tuning
MMS: The Easiest Way to Run MongoDB
How to learn MongoDB for beginner's
Performance Tuning and Optimization
Silicon Valley Code Camp 2015 - Advanced MongoDB - The Sequel
Conceptos básicos. Seminario web 6: Despliegue de producción
An Introduction to MongoDB Ops Manager
Mongo db improve the performance of your application codemotion2016
Silicon Valley Code Camp 2016 - MongoDB in production
Automated Slow Query Analysis: Dex the Index Robot
Ad

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
PDF
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...

Recently uploaded (20)

PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PPTX
sap open course for s4hana steps from ECC to s4
PPTX
Spectroscopy.pptx food analysis technology
PDF
Encapsulation theory and applications.pdf
PDF
NewMind AI Weekly Chronicles - August'25-Week II
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Machine learning based COVID-19 study performance prediction
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPT
Teaching material agriculture food technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Electronic commerce courselecture one. Pdf
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Agricultural_Statistics_at_a_Glance_2022_0.pdf
sap open course for s4hana steps from ECC to s4
Spectroscopy.pptx food analysis technology
Encapsulation theory and applications.pdf
NewMind AI Weekly Chronicles - August'25-Week II
20250228 LYD VKU AI Blended-Learning.pptx
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Machine learning based COVID-19 study performance prediction
Advanced methodologies resolving dimensionality complications for autism neur...
Review of recent advances in non-invasive hemoglobin estimation
Dropbox Q2 2025 Financial Results & Investor Presentation
Diabetes mellitus diagnosis method based random forest with bat algorithm
Teaching material agriculture food technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Spectral efficient network and resource selection model in 5G networks
Encapsulation_ Review paper, used for researhc scholars
Electronic commerce courselecture one. Pdf
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx

MongoDB Performance Tuning and Monitoring

  • 1. Technical Services Engineer, Palo Alto, CA @ MongoDB Daniel Coupal #MongoDB Performance Tuning and Monitoring Using MMS
  • 2. 2 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Agenda 1. What and who is MMS for? 2. Performance and monitoring examples 3. Setting it up and getting around 4. Wrapping up 5. Q&A
  • 3. MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal 1. What and who is MMS for?
  • 4. 4 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal What is MMS? The MongoDB Management Service • a free Cloud service for monitoring and managing your MongoDB clusters • or available to run On-Prem for customers with the Standard or Enterprise Subscriptions • tool that makes MongoDB easier to use
  • 5. 5 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Who is MMS for? • Developers – Track bottlenecks • Ops Team – Monitor health of the clusters – Backup databases – Automate updates and add capacity • MongoDB Technical Service Team “For years, MongoDB has been planning to do monitoring right.“ “We want the Ops People to have the same enthusiasm as the Developers.”
  • 6. 6 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal What is in MMS? A. Monitoring 1. Cloud: Sept 2011 2. On-Prem: July 2013 B. Backups 1. Cloud: April 2013 2. On-Prem: April 2014 C. Automation 1. Cloud: April 2014 (Beta)
  • 7. 7 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal What is in MMS monitoring? A. Metric Collection and Reporting B. Alerting (Email, SMS, PagerDuty, HipChat, SNMP) C. Event Tracking D. Database Stats E. Hardware Stats F. Logs and Profile Data
  • 8. 8 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal A. Metric Collection and Reporting
  • 9. 9 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal B. Alerting
  • 10. 10 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal C. Event Tracking
  • 11. 11 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal D. Database Stats
  • 12. 12 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal E. Hardware Stats (CPU, disk)
  • 13. 13 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal F. Logs and Profile Data
  • 14. MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal 2. Performance tuning and monitoring
  • 15. 15 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal How to do performance tuning? 1. Assess the problem and establish acceptable behavior 2. Measure the current performance 3. Find the bottleneck* 4. Remove the bottleneck 5. Re-test to confirm 6. Repeat * - (This is often the hard part) (Adapted from http://en.wikipedia.org/wiki/Performance_tuning )
  • 16. 16 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Pro-Tip: know thyself You have to recognize normal to know when it isn’t. Source: http://www.flickr.com/photos/skippy/6853920/
  • 17. 17 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Some handy metrics to watch • Memory usage • Opcounters • Lock % • Queues • Background flush average • Replication – Replication oplog window – Replication lag
  • 18. 18 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Fun fact: oplog idempotency • Operations in the oplog only affect the value once, so they can be run multiple times safely. • Examples – If you increment n from 2 to 3, n = 3 is fine; n + 1 is not. – Updating all documents that match a query is not, list of documents to update is. • Frequent, large updates means a big oplog to sync. • Updates that change a set mean writing the entire new version of the set to the oplog.
  • 19. 19 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 1: replication lag Scenario: Customer reports 150,000s of replication lag. Equals to almost 2 days of lag!
  • 20. 20 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 1: replication lag Some common causes of replication lag: • Secondaries underspec’d vs primaries • Access patterns between primary and secondaries • Insufficient bandwidth • Foreground index builds on secondaries “…when you have eliminated the impossible, whatever remains, however improbable, must be the truth…” -- Sherlock Holmes Sir Arthur Conan Doyle, The Sign of the Four
  • 21. 21 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 1: replication lag Example: • ~1500 ops per minute (opcounters) • 0.1 MB per object (average object size, local db) • ~1500 ops/min / 60 seconds * 0.1 MB/op * 8b/B =~ 20 mbps required bandwidth  Huge updates (oplog is idempotent) translated to 30 mbps, while they only had 10 mbps
  • 22. 22 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Lesson: remember to use alerts! Don’t wait until your secondaries fall off your oplog!
  • 23. 23 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Scenario: • User-facing web application with social functionality. • Customer was seeing significant performance degradation after adding and removing an index from their replicaset. • Their replicaset had 2 visible data-bearing nodes, each on real hardware, with dedicated 15K RPM disks and a significant amount of RAM. • Why were things slow?
  • 24. 24 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Opcounters: queries rose a bit, however writes were flat…
  • 25. 25 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Background flush average: went up considerably!
  • 26. 26 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Queues: also went up considerably!
  • 27. 27 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Journal stats: went up much higher than the ops…
  • 28. 28 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Connections: also went up…
  • 29. 29 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Background flush average: consistent until then
  • 30. 30 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Opcounters: interesting… around July 9th
  • 31. 31 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Page faults: something’s going on!
  • 32. 32 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Local DB average object size: growing!
  • 33. 33 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Now what? Time to analyze the logs What query or queries were going crazy? And what sort of query would grow in size without growing significantly in volume? Remember: Growing disk latency (caused by page faults?) And journal/oplog entries growing even though writes (inserts/updates) were flat.
  • 34. 34 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Log analysis The best tools for analyzing MongoDB logs are included in mtools*: • mlogfilter filter logs for slow queries, collection scans, … • mplotqueries graph query response times and volumes * https://github.com/rueckstiess/mtools
  • 35. 35 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Log analysis (example syntax) Show me queries that took more than 1000 ms from 6 am to 6 pm: mlogfilter mongodb.log --from 06:00 --to 18:00 --slow 1000 > mongodb-filtered.log Now, graph those queries: mplotqueries --logscale mongodb-filtered.log
  • 36. 36 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance
  • 37. 37 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Filter more! --operation Logarithmic! --logscale
  • 38. 38 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Sample query Wed Jul 17 14:16:44 [conn60560] update x.y query: { e: ”[id1]" } update: { $addToSet: { fr: ”[id2]" } } nscanned:1 nupdated:1 keyUpdates:1 locks(micros) w:889 6504ms 6.5 seconds to add a single value to a set!
  • 39. 39 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance http://docs.mongodb.org/manual/reference/operator/addToSet/ The $addToSet operator adds a value to an array only if the value is not in the array already. If the value is in the array, $addToSet returns without modifying the array. Consider the following example: db.collection.update({field:value}, {$addToSet: {field:value1}}); Here, $addToSet appends value1 to the array stored in field, only if value1 is not already a member of this array.
  • 40. 40 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance https://jira.mongodb.org/browse/SERVER-8192 “IndexSpec::getKeys() finds the set of index keys for a given document and index key spec. It's used when inserting / updating / deleting a document to update the index entries, and also for performing in memory sorts, deduping $or clauses and for other purposes. Right now extracting 10k elements from a nested object field within an array takes on the order of seconds on a decently fast machine. We could see how much we can optimize the implementation.”
  • 41. 41 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance What else?! • Wed Jul 17 14:11:59 [conn56541] update x.y query: { e: ”[id1]" } update: { $addToSet: { fr: ”[id2]" } } nscanned:1 nmoved:1 nupdated:1 keyUpdates:0 locks(micros) w:85145 11768ms • Almost 12 seconds! This time, there’s “nmoved:1”, too. This means a document was moved on disk, it outgrew the space allocated for it.
  • 42. 42 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Wait, there’s more! • Wed Jul 17 13:40:14 [conn28600] query x.y [snip] ntoreturn:16 ntoskip:0 nscanned:16779 scanAndOrder:1 keyUpdates:0 numYields: 906 locks(micros) r:46877422 nreturned:16 reslen:6948 38172ms • 38 seconds! Scanned 17k documents, returned 16.
  • 43. 43 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance What next? Short term fix: disable the new feature for the heaviest users! After that: • rework the code to avoid $addToSet • add indexes for queries scanning collections • use powerOf2Sizes (http://docs.mongodb.org/manual/reference/command/collMod/) to reduce fragmentation and document moves
  • 44. 44 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Example 2: slow performance Did it work? (Yes.) (So far. ;) )
  • 45. 45 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Monitoring: watch for warnings MMS warns you if your systems a) are running outdated versions b) have startup warnings c) if a mongod is publicly visible Don’t ignore these warnings!
  • 46. MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal 3. Setting it up and getting around
  • 47. 47 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Setting up monitoring for the Cloud http://mms.mongodb.com/help/monitoring/tutorial/ • Setup an account (Free) • Install the agent – Download the binary – Set the API key in the configuration file • Add your hosts – Add a seed host, MMS will discover the cluster • Optional: hardware stats through Munin-node • Optional: enable logging and profiling
  • 48. 48 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Setting up monitoring “On-Prem” • Available (included) to Customers with – Enterprise subscription – OR Standard subscription • One host to run the server for up to 400 hosts • One RPM/Deb package to install • Installing the backup requires more planning and more resources (hosts, disks, …) – The alternative is use MMS Backups in the Cloud, we removed the complexity for you.
  • 49. 49 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal MMS Monitoring Architecture
  • 50. 50 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal List of monitored hosts
  • 51. 51 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Notes • Agent written in Go • Failover: run multiple agents (1 primary) • Hosts: use CNAMEs, especially on AWS! • You can use a group per environment (each needs an agent) • Connections are over SSL • On-Prem solution for Enterprise or Standard customers that don’t want to use the hosted service • Makes it easier for the technical services to help you!
  • 52. MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal 4. Wrapping up
  • 53. 53 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal The Technical Services Team • We are here to make you successful, open tickets – We support 1000s of customers – Another customer may had the same issue as you • Throw any problems to the Technical Services Team
  • 54. 54 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal What’s next for MMS? • Continuous updates – Cloud: ~every 3 weeks – On-Prem: ~every 3 months • Automation service • A lot of more information at: MongoDB World 2014 @ NYC on June 23-25
  • 55. 55 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Summary • MMS is a great, free service • Setup is easy • Metrics and graphs are awesome • Preventing failures even more awesome • Using MMS makes it easier for the Technical Services Team to help you • Monitor your DBs like a Pro, use MMS
  • 56. MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal 5. Questions?
  • 57. MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Appendix
  • 58. 58 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Other MMS References • Tons of webinars and other presentations http://www.mongodb.com/presentations • Five MMS Monitoring Alerts to Keep Your MongoDB Deployment on Track http://www.mongodb.com/blog/post/five-mms-monitoring-alerts-keep-your- mongodb-deployment-track • Digging into the meaning of some metrics – Lock % : http://blog.mms.mongodb.com/post/78650784046/learn-about-lock-percentage-concurrency- in-mongodb – Replication Oplog Window : http://blog.mms.mongodb.com/post/77279440964/replica-set-health-is- more-than-just-replication-lag • How to fix some warnings reported by MMS – http://docs.mongodb.org/manual/administration/production-notes/ (includes readahead settings)
  • 59. 59 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Examining memory and disk Memory: resident vs virtual vs non-mapped
  • 60. 60 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Examining memory and disk Page faults and Record Stats
  • 61. 61 MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Examining memory and disk Background flush and Disk IO (Check out http://www.wmarrow.com/strcalc/ )
  • 62. MongoDB Performance Tuning and Monitoring Using MMS, Daniel Coupal Thank you for using

Editor's Notes

  • #53: 50:00 elapsed minutes