SlideShare a Scribd company logo
1 of 23
MongoDB Performance 
Tuning Mastery 
MongoDB Meetup London 
Kenny Gorman 
Chief Technologist; Data @ Rackspace 
Co-Founder @ ObjectRocket 
@kennygorman
Order Matters 
1. Schema design 
1. Workload tuning 
1. Instance tuning 
1. Reactive tuning
Schema Design 
● Why MongoDB? 
● Resist your urge to model relationally 
● Develop sound workload patterns 
● Test those patterns
Workload Tuning 
Identify Tune 
● Profile 
● Explain 
● Tune
Profiler 
while performance_problems(): 
bad_statements = find_candidates() 
for statement in bad_statements: 
statement.explain() 
● What is the function for 
performance_problems()? 
● If true, then tools()
Profiler 
● Per DB, capped 
● db.system.profile 
● Your most 
important tool 
● Leave it on. Yes, I 
said that. Leave it 
the F*&K on.
Profiler 
$> db.setProfilingLevel(2); 
{ "was" : 0, "slowms" : 100, "ok" : 1 } 
$> db.testme.save({"name":"Kenny"}); 
$> db.system.profile.find().pretty() 
{ "ts" : ISODate("2013-02-11T18:45:06.857Z"), 
"op" : "insert", 
"ns" : "test.testme", 
"keyUpdates" : 0, 
"numYield" : 0, 
"lockStats" : {..}, 
"millis" : 0, 
"client" : "127.0.0.1", 
"user" : "" }
Profiler 
{ 
"ts" : ISODate("2012-09-14T16:34:00.010Z"), // date it occurred 
"op" : "query", // the 
operation type 
"ns" : "game.players", // the 
db and collection 
"query" : { "total_games" : 1000 }, // query document 
"ntoreturn" : 0, // # 
docs returned with limit() 
"ntoskip" : 0, 
// # of docs to skip() 
"nscanned" : 959967, // number of docs 
scanned 
"keyUpdates" : 0, // 
updates of secondary indexes 
"numYield" : 1, // # of 
times yields took place 
"lockStats" : { ... }, // 
subdoc of lock stats 
"nreturned" : 0, // # 
docs actually returned 
"responseLength" : 20, // size 
of doc 
"millis" : 859, // how 
long it took 
"client" : "127.0.0.1", // 
http://docs.mongodb.org/manual/reference/database-profiler/ 
client asked for it 
"user" : "" 
// the user asking for it 
}
Profiler: Finding Candidates 
// response time by operation type 
db.system.profile.aggregate( 
{ $group : { 
_id :"$op", 
count:{$sum:1}, 
"max response time":{$max:"$millis"}, 
"avg response time":{$avg:"$millis"} 
}}); 
// slowest by namespace 
db.system.profile.aggregate( 
{ $group : { 
_id :"$ns", 
count:{$sum:1}, 
"max response time":{$max:"$millis"}, 
"avg response time":{$avg:"$millis"} 
}}, 
{$sort: { 
"max response time":-1} 
}); 
// slowest by client 
db.system.profile.aggregate( 
{$group : { 
_id :"$client", 
count:{$sum:1}, 
"max response time":{$max:"$millis"}, 
"avg response time":{$avg:"$millis"} 
}}, 
{$sort: { 
"max response time":-1} 
}); 
// summary moved vs non-moved 
db.system.profile.aggregate( 
{ $group : { 
_id :"$moved", 
count:{$sum:1}, 
"max response time":{$max:"$millis"}, 
"avg response time":{$avg:"$millis"} 
}});
Explain: What am I looking for? 
● fastmod 
● nscanned != nreturned 
● key updates 
● moves 
● lock waits 
● just returning too much data (count or size or both) 
● bad cardinality
Explain 
● Take the document from profiler output, 
explain it 
● Look at results, make corrections 
● Rinse and repeat
Explain 
$>db.system.profile.find({"op":"query","ns":"test.testme"}).pretty(); 
{ "ts" : ISODate("2013-02-11T19:53:16.302Z"), 
"op" : "query", 
"ns" : "test.testme", 
"query" : { "name" : 1 }, 
"ntoreturn" : 0, 
"ntoskip" : 0, 
"nscanned" : 32001, 
// why scanning so many? 
"keyUpdates" : 0, 
"numYield" : 0, 
"lockStats" : {...}, 
"nreturned" : 1, 
// just to return 1 
"responseLength" : 56, 
"millis" : 29, 
// slow! 
"client" : "127.0.0.1", 
"user" : "" 
}
Explain 
$> db.testme.find({ "name": 1 }).explain() 
{ 
"cursor" : "BasicCursor", 
// Basic 
"isMultiKey" : false, 
"n" : 1, 
"nscannedObjects" : 32001, 
"nscanned" : 32001, 
"nscannedObjectsAllPlans" : 32001, 
"nscannedAllPlans" : 32001, 
"scanAndOrder" : false, 
"indexOnly" : false, 
"nYields" : 0, 
"nChunkSkips" : 0, 
"millis" : 14, 
"indexBounds" : { 
// WTF! 
}, 
... 
}
Explain 
$> db.testme.ensureIndex({"name":-1}); 
$> db.testme.find({"name":1}).explain() 
{ 
"cursor" : "BtreeCursor name_-1", 
// Btree 
"isMultiKey" : false, 
"n" : 1, 
"nscannedObjects" : 1, 
"nscanned" : 1, 
"nscannedObjectsAllPlans" : 1, 
"nscannedAllPlans" : 1, 
"scanAndOrder" : false, 
"indexOnly" : false, 
"nYields" : 0, 
"nChunkSkips" : 0, 
"millis" : 0, 
"indexBounds" : { 
"name" : [ 
[ 
1, 
// w00t! 
1 
] 
] 
}, 
... 
}
Now I need tools
Response time analysis 
● Response time analysis techniques come from Oracle community circa 
2000-2004. 
● Response time = service time + queue time ( time_to_complete + 
time_waiting_in_queue ) 
● Each document in profile collection a couple response time attributes. 
o millis 
o timeAcquiring 
o timeLocked 
● The only true measure of response time in MongoDB 
● Aids in prioritization of tuning opportunities. Finding the bang for the buck, 
or the immediate performance problem.
Definitions: 
system.profile.lockStats.timeLockedMicros 
The time in microseconds the operation held a specific lock. For operations that require more than one lock, like those 
that lock the localdatabase to update the oplog, then this value may be longer than the total length of the operation 
(i.e. millis.) 
system.profile.lockStats.timeAcquiringMicros 
The time in microseconds the operation spent waiting to acquire a specific lock. 
system.profile.millis 
The time in milliseconds for the server to perform the operation. This time does not include network time nor time to 
acquire the lock.
Response time analysis 
$>db.system.profile.aggregate( 
[ 
{ $project : { 
"op" : "$op", 
"millis" : "$millis", 
"timeAcquiringMicrosrMS" : { $divide : [ "$lockStats.timeAcquiringMicros.r", 1000 ] 
}, 
"timeAcquiringMicroswMS" : { $divide : [ "$lockStats.timeAcquiringMicros.w", 1000 ] 
}, 
"timeLockedMicrosrMS" : { $divide : [ "$lockStats.timeLockedMicros.r", 1000 ] }, 
"timeLockedMicroswMS" : { $divide : [ "$lockStats.timeLockedMicros.w", 1000 ] } } 
}, 
{ $project : { 
"op" : "$op", 
"millis" : "$millis", 
"total_time" : { $add : [ "$millis", "$timeAcquiringMicrosrMS", 
"$timeAcquiringMicroswMS" ] }, 
"timeAcquiringMicrosrMS" : "$timeAcquiringMicrosrMS", 
"timeAcquiringMicroswMS" : "$timeAcquiringMicroswMS", 
"timeLockedMicrosrMS" : "$timeLockedMicrosrMS", 
"timeLockedMicroswMS" : "$timeLockedMicroswMS" } 
}, 
{ $group : { 
_id : "$op", 
"average response time" : { $avg : "$millis" }, 
"average response time + acquire time": { $avg: "$total_time"}, 
"average acquire time reads" : { $avg : "$timeAcquiringMicrosrMS" }, 
"average acquire time writes" : { $avg : "$timeAcquiringMicroswMS" }, 
"average lock time reads" : { $avg : "$timeLockedMicrosrMS" }, 
"average lock time writes" : { $avg : "$timeLockedMicroswMS" } } 
} 
] 
);
Response time analysis 
{ 
"_id" : "insert", 
"average response time" : 0.07363770250368189, 
// time executing 
"average acquire time reads" : 0, 
"average acquire time writes" : 5.623796023564078, // time 
waiting 
"average lock time reads" : 0, 
"average lock time writes" : 0.25491826215022123 // time in 
lock.. woah. 
} 
{ 
"_id" : "update", 
"average response time" : 0.23551171393341552, 
// time executing.. moves? 
"average acquire time reads" : 0, 
"average acquire time writes" : 10.261996300863133, // lots of 
waiting 
"average lock time reads" : 0, 
"average lock time writes" : 0.3795672009864362 
// time in lock.. again! 
}
Response time analysis 
● Python code to get you started with profiler and graphite: 
https://github.com/kgorman/slum
Instance Tuning 
● Mongostat 
● Cache management, Hot Set, and Disk I/O. 
● Locks and Sharding 
● Some thoughts on Hardware
Links 
http://www.kennygorman.com/mongodb-profiler-helpful-queries/ 
https://gist.github.com/kgorman/134896c7414fde8e090b 
https://github.com/kgorman/slum 
https://github.com/kgorman/ocean 
http://docs.mongodb.org/manual/reference/database-profiler/ 
http://docs.mongodb.org/manual/reference/method/cursor.explain/#explain-output- 
fields-core
Contact 
@kennygorman 
kenny.gorman@rackspace.com

More Related Content

Recently uploaded

Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101vincent683379
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyJohn Staveley
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfFIDO Alliance
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastUXDXConf
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekCzechDreamin
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPTiSEO AI
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfFIDO Alliance
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeCzechDreamin
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...CzechDreamin
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfFIDO Alliance
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceSamy Fodil
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityScyllaDB
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimaginedpanagenda
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfFIDO Alliance
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyUXDXConf
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe中 央社
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...panagenda
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessUXDXConf
 

Recently uploaded (20)

Syngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdfSyngulon - Selection technology May 2024.pdf
Syngulon - Selection technology May 2024.pdf
 
AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101AI presentation and introduction - Retrieval Augmented Generation RAG 101
AI presentation and introduction - Retrieval Augmented Generation RAG 101
 
Demystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John StaveleyDemystifying gRPC in .Net by John Staveley
Demystifying gRPC in .Net by John Staveley
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
Designing for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at ComcastDesigning for Hardware Accessibility at Comcast
Designing for Hardware Accessibility at Comcast
 
AI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří KarpíšekAI revolution and Salesforce, Jiří Karpíšek
AI revolution and Salesforce, Jiří Karpíšek
 
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
1111 ChatGPT Prompts PDF Free Download - Prompts for ChatGPT
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024Enterprise Knowledge Graphs - Data Summit 2024
Enterprise Knowledge Graphs - Data Summit 2024
 
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi IbrahimzadeFree and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
Free and Effective: Making Flows Publicly Accessible, Yumi Ibrahimzade
 
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
Behind the Scenes From the Manager's Chair: Decoding the Secrets of Successfu...
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
WebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM PerformanceWebAssembly is Key to Better LLM Performance
WebAssembly is Key to Better LLM Performance
 
Optimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through ObservabilityOptimizing NoSQL Performance Through Observability
Optimizing NoSQL Performance Through Observability
 
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties ReimaginedEasier, Faster, and More Powerful – Notes Document Properties Reimagined
Easier, Faster, and More Powerful – Notes Document Properties Reimagined
 
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdfLinux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
Linux Foundation Edge _ Overview of FDO Software Components _ Randy at Intel.pdf
 
A Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System StrategyA Business-Centric Approach to Design System Strategy
A Business-Centric Approach to Design System Strategy
 
Portal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russePortal Kombat : extension du réseau de propagande russe
Portal Kombat : extension du réseau de propagande russe
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Structuring Teams and Portfolios for Success
Structuring Teams and Portfolios for SuccessStructuring Teams and Portfolios for Success
Structuring Teams and Portfolios for Success
 

Featured

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Applitools
 

Featured (20)

Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
Unlocking the Power of ChatGPT and AI in Testing - A Real-World Look, present...
 

MongoDB performance tuning mastery

  • 1. MongoDB Performance Tuning Mastery MongoDB Meetup London Kenny Gorman Chief Technologist; Data @ Rackspace Co-Founder @ ObjectRocket @kennygorman
  • 2. Order Matters 1. Schema design 1. Workload tuning 1. Instance tuning 1. Reactive tuning
  • 3. Schema Design ● Why MongoDB? ● Resist your urge to model relationally ● Develop sound workload patterns ● Test those patterns
  • 4. Workload Tuning Identify Tune ● Profile ● Explain ● Tune
  • 5. Profiler while performance_problems(): bad_statements = find_candidates() for statement in bad_statements: statement.explain() ● What is the function for performance_problems()? ● If true, then tools()
  • 6. Profiler ● Per DB, capped ● db.system.profile ● Your most important tool ● Leave it on. Yes, I said that. Leave it the F*&K on.
  • 7. Profiler $> db.setProfilingLevel(2); { "was" : 0, "slowms" : 100, "ok" : 1 } $> db.testme.save({"name":"Kenny"}); $> db.system.profile.find().pretty() { "ts" : ISODate("2013-02-11T18:45:06.857Z"), "op" : "insert", "ns" : "test.testme", "keyUpdates" : 0, "numYield" : 0, "lockStats" : {..}, "millis" : 0, "client" : "127.0.0.1", "user" : "" }
  • 8. Profiler { "ts" : ISODate("2012-09-14T16:34:00.010Z"), // date it occurred "op" : "query", // the operation type "ns" : "game.players", // the db and collection "query" : { "total_games" : 1000 }, // query document "ntoreturn" : 0, // # docs returned with limit() "ntoskip" : 0, // # of docs to skip() "nscanned" : 959967, // number of docs scanned "keyUpdates" : 0, // updates of secondary indexes "numYield" : 1, // # of times yields took place "lockStats" : { ... }, // subdoc of lock stats "nreturned" : 0, // # docs actually returned "responseLength" : 20, // size of doc "millis" : 859, // how long it took "client" : "127.0.0.1", // http://docs.mongodb.org/manual/reference/database-profiler/ client asked for it "user" : "" // the user asking for it }
  • 9. Profiler: Finding Candidates // response time by operation type db.system.profile.aggregate( { $group : { _id :"$op", count:{$sum:1}, "max response time":{$max:"$millis"}, "avg response time":{$avg:"$millis"} }}); // slowest by namespace db.system.profile.aggregate( { $group : { _id :"$ns", count:{$sum:1}, "max response time":{$max:"$millis"}, "avg response time":{$avg:"$millis"} }}, {$sort: { "max response time":-1} }); // slowest by client db.system.profile.aggregate( {$group : { _id :"$client", count:{$sum:1}, "max response time":{$max:"$millis"}, "avg response time":{$avg:"$millis"} }}, {$sort: { "max response time":-1} }); // summary moved vs non-moved db.system.profile.aggregate( { $group : { _id :"$moved", count:{$sum:1}, "max response time":{$max:"$millis"}, "avg response time":{$avg:"$millis"} }});
  • 10. Explain: What am I looking for? ● fastmod ● nscanned != nreturned ● key updates ● moves ● lock waits ● just returning too much data (count or size or both) ● bad cardinality
  • 11. Explain ● Take the document from profiler output, explain it ● Look at results, make corrections ● Rinse and repeat
  • 12. Explain $>db.system.profile.find({"op":"query","ns":"test.testme"}).pretty(); { "ts" : ISODate("2013-02-11T19:53:16.302Z"), "op" : "query", "ns" : "test.testme", "query" : { "name" : 1 }, "ntoreturn" : 0, "ntoskip" : 0, "nscanned" : 32001, // why scanning so many? "keyUpdates" : 0, "numYield" : 0, "lockStats" : {...}, "nreturned" : 1, // just to return 1 "responseLength" : 56, "millis" : 29, // slow! "client" : "127.0.0.1", "user" : "" }
  • 13. Explain $> db.testme.find({ "name": 1 }).explain() { "cursor" : "BasicCursor", // Basic "isMultiKey" : false, "n" : 1, "nscannedObjects" : 32001, "nscanned" : 32001, "nscannedObjectsAllPlans" : 32001, "nscannedAllPlans" : 32001, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 14, "indexBounds" : { // WTF! }, ... }
  • 14. Explain $> db.testme.ensureIndex({"name":-1}); $> db.testme.find({"name":1}).explain() { "cursor" : "BtreeCursor name_-1", // Btree "isMultiKey" : false, "n" : 1, "nscannedObjects" : 1, "nscanned" : 1, "nscannedObjectsAllPlans" : 1, "nscannedAllPlans" : 1, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 0, "nChunkSkips" : 0, "millis" : 0, "indexBounds" : { "name" : [ [ 1, // w00t! 1 ] ] }, ... }
  • 15. Now I need tools
  • 16. Response time analysis ● Response time analysis techniques come from Oracle community circa 2000-2004. ● Response time = service time + queue time ( time_to_complete + time_waiting_in_queue ) ● Each document in profile collection a couple response time attributes. o millis o timeAcquiring o timeLocked ● The only true measure of response time in MongoDB ● Aids in prioritization of tuning opportunities. Finding the bang for the buck, or the immediate performance problem.
  • 17. Definitions: system.profile.lockStats.timeLockedMicros The time in microseconds the operation held a specific lock. For operations that require more than one lock, like those that lock the localdatabase to update the oplog, then this value may be longer than the total length of the operation (i.e. millis.) system.profile.lockStats.timeAcquiringMicros The time in microseconds the operation spent waiting to acquire a specific lock. system.profile.millis The time in milliseconds for the server to perform the operation. This time does not include network time nor time to acquire the lock.
  • 18. Response time analysis $>db.system.profile.aggregate( [ { $project : { "op" : "$op", "millis" : "$millis", "timeAcquiringMicrosrMS" : { $divide : [ "$lockStats.timeAcquiringMicros.r", 1000 ] }, "timeAcquiringMicroswMS" : { $divide : [ "$lockStats.timeAcquiringMicros.w", 1000 ] }, "timeLockedMicrosrMS" : { $divide : [ "$lockStats.timeLockedMicros.r", 1000 ] }, "timeLockedMicroswMS" : { $divide : [ "$lockStats.timeLockedMicros.w", 1000 ] } } }, { $project : { "op" : "$op", "millis" : "$millis", "total_time" : { $add : [ "$millis", "$timeAcquiringMicrosrMS", "$timeAcquiringMicroswMS" ] }, "timeAcquiringMicrosrMS" : "$timeAcquiringMicrosrMS", "timeAcquiringMicroswMS" : "$timeAcquiringMicroswMS", "timeLockedMicrosrMS" : "$timeLockedMicrosrMS", "timeLockedMicroswMS" : "$timeLockedMicroswMS" } }, { $group : { _id : "$op", "average response time" : { $avg : "$millis" }, "average response time + acquire time": { $avg: "$total_time"}, "average acquire time reads" : { $avg : "$timeAcquiringMicrosrMS" }, "average acquire time writes" : { $avg : "$timeAcquiringMicroswMS" }, "average lock time reads" : { $avg : "$timeLockedMicrosrMS" }, "average lock time writes" : { $avg : "$timeLockedMicroswMS" } } } ] );
  • 19. Response time analysis { "_id" : "insert", "average response time" : 0.07363770250368189, // time executing "average acquire time reads" : 0, "average acquire time writes" : 5.623796023564078, // time waiting "average lock time reads" : 0, "average lock time writes" : 0.25491826215022123 // time in lock.. woah. } { "_id" : "update", "average response time" : 0.23551171393341552, // time executing.. moves? "average acquire time reads" : 0, "average acquire time writes" : 10.261996300863133, // lots of waiting "average lock time reads" : 0, "average lock time writes" : 0.3795672009864362 // time in lock.. again! }
  • 20. Response time analysis ● Python code to get you started with profiler and graphite: https://github.com/kgorman/slum
  • 21. Instance Tuning ● Mongostat ● Cache management, Hot Set, and Disk I/O. ● Locks and Sharding ● Some thoughts on Hardware
  • 22. Links http://www.kennygorman.com/mongodb-profiler-helpful-queries/ https://gist.github.com/kgorman/134896c7414fde8e090b https://github.com/kgorman/slum https://github.com/kgorman/ocean http://docs.mongodb.org/manual/reference/database-profiler/ http://docs.mongodb.org/manual/reference/method/cursor.explain/#explain-output- fields-core

Editor's Notes

  1. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.
  2. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.
  3. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.
  4. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.
  5. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.
  6. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.
  7. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.
  8. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.
  9. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.
  10. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.
  11. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.
  12. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared. Use new Aggregation Framework Allows for aggregated queries from loads of data Examples: https://gist.github.com/995a3aa5b35e92e5ab57
  13. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared. Use new Aggregation Framework Allows for aggregated queries from loads of data Examples: https://gist.github.com/995a3aa5b35e92e5ab57
  14. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared. Use new Aggregation Framework Allows for aggregated queries from loads of data Examples: https://gist.github.com/995a3aa5b35e92e5ab57
  15. Data is saved in capped collections, 1 per shard db.system.profile Turn it on, gather data, later analyze for tuning opportunities db.setProfilingLevel(1,20) db.getProfilingStatus() 1 document per statement show profile db.system.profile.find() leave it on, don't be scared.