SlideShare a Scribd company logo
featuring special guest Sean Bean
Let’s talk about production 
MongoDB 
Database Happiness 
Developer Fun
But it doesn’t need to be 
this way.
Let’s use House Stark as an 
example
It starts with the data model 
_id name home p_id 
0 Ned Stark Winterfell 0 
1 Arya Stark Winterfell 1 
2 Bran Stark Winterfell 2 
p_id proficiencies 
0 
keeping a cool 
head 
1 
pulling off the short 
hair look 
2 riding piggyback
Arrays in MongoDB 
{ 
_id: ObjectId(“000”), 
name: “Ned Stark”, 
relatives: [ 
ObjectId(“001”), 
ObjectId(“002”) 
] 
} 
{ 
_id: ObjectId(“000”), 
name: “Ned Stark”, 
relatives: [ 
{ 
_id: ObjectId(“001”), 
name: “Arya Stark”, 
… 
}, 
{ 
_id: ObjectId(“002”), 
name: “Bran Stark”, 
… 
} 
] 
} 
vs.
What are “total normalization” 
trade-offs? 
{ 
_id: ObjectId(“000”), 
name: “Ned Stark”, 
relatives: [ 
ObjectId(“001”), 
ObjectId(“002”) 
] 
}
Here is Ned Stark. 
His relatives are: 
ObjectId(“001”) ObjectId(“002”)
And “partial denormalization”? 
{ 
_id: ObjectId(“000”), 
name: “Ned Stark”, 
relatives: [ 
{ 
_id: ObjectId(“001”), 
name: “Arya Stark”, 
img: “../arya.png” 
} 
{ 
_id: ObjectId(“002”), 
name: “Bran Stark”, 
img: “../bran.png” 
} 
] 
}
Here is Ned Stark. 
His relatives are: 
Arya Stark Bran Stark
Rules on Arrays 
High reads, low updates/writes 
Array should be bound in size 
Don’t need to frequently access 
embedded items individually
#1 cause of slow databases: 
(lack of) indexes
cursor.explain() tells us if we’re 
indexed 
{ 
"cursor" : "<Cursor Type and Index>", 
"n" : <num>, 
"nscannedObjects" : <num>, 
"nscanned" : <num>, 
"nscannedObjectsAllPlans" : <num>, 
"nscannedAllPlans" : <num>, 
"scanAndOrder" : <boolean>, 
"indexOnly" : <boolean>, 
"millis" : <num>, 
"indexBounds" : { <index bounds> }, 
"allPlans" : [ 
{ "cursor" : "<Cursor Type and Index>", 
"n" : <num>, 
"nscannedObjects" : <num>, 
"nscanned" : <num>, 
"indexBounds" : { <index bounds> } 
}, 
... 
] 
}
Remember our indexing 
essentials 
scanAndOrder 
n vs nScanned 
NO BasicCursor!!!!!!!!!!!!! NO! 
Tier 3 
Tier 2 
Tier 1
Running Production MongoDB Lightning Talk
How to save your database 
• mongod logs 
• db.currentOp() & db.killOp()
There’s lots of good info in the 
logs 
• 2014-10-09T02:26:58.994-0700 [conn367784] query gotDB.people query: { 
$query: { isAlive: true }, $orderby: { age: 1 } } planSummary: IXSCAN { isAlive: 
1 }, cursorid:1736436984952 ntoreturn:10 ntoskip:0 nscanned:7677 
nscannedObjects:7677 scanAndOrder:1 keyUpdates:0 numYields:0 
locks(micros) r:115557 nreturned:10 reslen:34036 115ms 
• 2014-10-09T21:26:58.994-0700 [conn127156] command gotDB.$cmd 
command: mapReduce { $msg: "query not recording (too large)" } 
planSummary: COLLSCAN keyUpdates:0 numYields:3843 locks(micros) 
W:2840 r:85085260 w:26899 reslen:187 76657ms
Use currentOp() to triage slow 
operations 
db.currentOp().inprog.forEach( 
function(op) { 
if(op.secs_running > 5) printjson(op); 
} 
)
Terminate slowness 
{ 
"locks": { 
"^myDB": "R" 
}, 
"ns": "myDB.bar", 
"op": "query", 
"opid": 1344808, 
"query": {}, 
"secs_running": 53, 
"waitingForLock": false 
} 
db.killOp(1344808)
Thanks for listening! 
chris@mongolab.com 
@chrisckchang 
@mongolab
Ad

Recommended

Mongodb index 讀書心得
Mongodb index 讀書心得
cc liu
 
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
Webinarserie: Einführung in MongoDB: “Back to Basics” - Teil 3 - Interaktion ...
MongoDB
 
Indexing documents
Indexing documents
MongoDB
 
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
MongoDB
 
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB .local Munich 2019: Tips and Tricks++ for Querying and Indexing MongoDB
MongoDB
 
Schema design
Schema design
christkv
 
Scaling MongoDB; Sharding Into and Beyond the Multi-Terabyte Range
Scaling MongoDB; Sharding Into and Beyond the Multi-Terabyte Range
MongoDB
 
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
MongoDB .local Munich 2019: New Encryption Capabilities in MongoDB 4.2: A Dee...
MongoDB
 
Geospatial Indexing and Querying with MongoDB
Geospatial Indexing and Querying with MongoDB
Grant Goodale
 
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
yoyamasaki
 
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
MongoDB
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
MongoDB Performance Debugging
MongoDB Performance Debugging
MongoDB
 
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB
 
MongoDB Indexing Constraints and Creative Schemas
MongoDB Indexing Constraints and Creative Schemas
MongoDB
 
Mongodb debugging-performance-problems
Mongodb debugging-performance-problems
MongoDB
 
Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.
Ravi Teja
 
Webinar: MongoDB 2.4 Feature Demo and Q&A on Hash-based Sharding
Webinar: MongoDB 2.4 Feature Demo and Q&A on Hash-based Sharding
MongoDB
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
MongoDB
MongoDB
Rawin Windygallery
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
MongoDB
 
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
Building Your First MongoDB Application
Building Your First MongoDB Application
Tugdual Grall
 
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Grant Goodale
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 
NoSQL - Hands on
NoSQL - Hands on
Johannes Hoppe
 
Whats new in iOS5
Whats new in iOS5
Paul Ardeleanu
 
Flexible Event Tracking (Paul Gebheim)
Flexible Event Tracking (Paul Gebheim)
MongoSF
 
Hablemos de Systemd
Hablemos de Systemd
Rodolfo Pilas
 

More Related Content

What's hot (20)

Geospatial Indexing and Querying with MongoDB
Geospatial Indexing and Querying with MongoDB
Grant Goodale
 
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
yoyamasaki
 
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
MongoDB
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
MongoDB Performance Debugging
MongoDB Performance Debugging
MongoDB
 
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB
 
MongoDB Indexing Constraints and Creative Schemas
MongoDB Indexing Constraints and Creative Schemas
MongoDB
 
Mongodb debugging-performance-problems
Mongodb debugging-performance-problems
MongoDB
 
Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.
Ravi Teja
 
Webinar: MongoDB 2.4 Feature Demo and Q&A on Hash-based Sharding
Webinar: MongoDB 2.4 Feature Demo and Q&A on Hash-based Sharding
MongoDB
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
MongoDB
MongoDB
Rawin Windygallery
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
MongoDB
 
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
Building Your First MongoDB Application
Building Your First MongoDB Application
Tugdual Grall
 
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Grant Goodale
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 
NoSQL - Hands on
NoSQL - Hands on
Johannes Hoppe
 
Whats new in iOS5
Whats new in iOS5
Paul Ardeleanu
 
Geospatial Indexing and Querying with MongoDB
Geospatial Indexing and Querying with MongoDB
Grant Goodale
 
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
ドキュメントデータベースとして MySQLを使う!? ~MySQL JSON UDF~
yoyamasaki
 
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
MongoDB
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
MongoDB Performance Debugging
MongoDB Performance Debugging
MongoDB
 
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB .local Munich 2019: Aggregation Pipeline Power++: How MongoDB 4.2 Pip...
MongoDB
 
MongoDB Indexing Constraints and Creative Schemas
MongoDB Indexing Constraints and Creative Schemas
MongoDB
 
Mongodb debugging-performance-problems
Mongodb debugging-performance-problems
MongoDB
 
Building a Location-based platform with MongoDB from Zero.
Building a Location-based platform with MongoDB from Zero.
Ravi Teja
 
Webinar: MongoDB 2.4 Feature Demo and Q&A on Hash-based Sharding
Webinar: MongoDB 2.4 Feature Demo and Q&A on Hash-based Sharding
MongoDB
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
MongoDB
 
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB .local Houston 2019: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
Building Your First MongoDB Application
Building Your First MongoDB Application
Tugdual Grall
 
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Mapping Flatland: Using MongoDB for an MMO Crossword Game (GDC Online 2011)
Grant Goodale
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
MongoDB
 

Viewers also liked (6)

Flexible Event Tracking (Paul Gebheim)
Flexible Event Tracking (Paul Gebheim)
MongoSF
 
Hablemos de Systemd
Hablemos de Systemd
Rodolfo Pilas
 
Mongodb administración
Mongodb administración
Juan Ladetto
 
Gestión de índices en MongoDB
Gestión de índices en MongoDB
Lorena Perez Verdasco
 
TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...
TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...
Big Data Spain
 
Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)
MongoSF
 
Flexible Event Tracking (Paul Gebheim)
Flexible Event Tracking (Paul Gebheim)
MongoSF
 
Mongodb administración
Mongodb administración
Juan Ladetto
 
TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...
TENSORFLOW: ARCHITECTURE AND USE CASE - NASA SPACE APPS CHALLENGE by Gema Par...
Big Data Spain
 
Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)
MongoSF
 
Ad

Similar to Running Production MongoDB Lightning Talk (20)

Query Optimization in MongoDB
Query Optimization in MongoDB
Hamoon Mohammadian Pour
 
Fast querying indexing for performance (4)
Fast querying indexing for performance (4)
MongoDB
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
Douglas Duncan
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
MongoDB
 
Quick overview on mongo db
Quick overview on mongo db
Eman Mohamed
 
Performance Tuning and Optimization
Performance Tuning and Optimization
MongoDB
 
Mongodb Training Tutorial in Bangalore
Mongodb Training Tutorial in Bangalore
rajkamaltibacademy
 
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
 
Nosql part 2
Nosql part 2
Ruru Chowdhury
 
Mdb dn 2016_05_index_tuning
Mdb dn 2016_05_index_tuning
Daniel M. Farrell
 
MongoDB's index and query optimize
MongoDB's index and query optimize
mysqlops
 
Mongodb Performance
Mongodb Performance
Jack
 
Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011
bostonrb
 
Mongo db improve the performance of your application codemotion2016
Mongo db improve the performance of your application codemotion2016
Juan Antonio Roy Couto
 
Mongophilly indexing-2011-04-26
Mongophilly indexing-2011-04-26
kreuter
 
Indexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdf
Malak Abu Hammad
 
Mongo db tutorials
Mongo db tutorials
Anuj Jain
 
Indexing with MongoDB
Indexing with MongoDB
MongoDB
 
MongoDB_ppt.pptx
MongoDB_ppt.pptx
1AP18CS037ShirishKul
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
anujaggarwal49
 
Fast querying indexing for performance (4)
Fast querying indexing for performance (4)
MongoDB
 
MongoDB and Indexes - MUG Denver - 20160329
MongoDB and Indexes - MUG Denver - 20160329
Douglas Duncan
 
Indexing Strategies to Help You Scale
Indexing Strategies to Help You Scale
MongoDB
 
Quick overview on mongo db
Quick overview on mongo db
Eman Mohamed
 
Performance Tuning and Optimization
Performance Tuning and Optimization
MongoDB
 
Mongodb Training Tutorial in Bangalore
Mongodb Training Tutorial in Bangalore
rajkamaltibacademy
 
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB.local DC 2018: Tips and Tricks for Avoiding Common Query Pitfalls
MongoDB
 
MongoDB's index and query optimize
MongoDB's index and query optimize
mysqlops
 
Mongodb Performance
Mongodb Performance
Jack
 
Mongodb in-anger-boston-rb-2011
Mongodb in-anger-boston-rb-2011
bostonrb
 
Mongo db improve the performance of your application codemotion2016
Mongo db improve the performance of your application codemotion2016
Juan Antonio Roy Couto
 
Mongophilly indexing-2011-04-26
Mongophilly indexing-2011-04-26
kreuter
 
Indexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdf
Malak Abu Hammad
 
Mongo db tutorials
Mongo db tutorials
Anuj Jain
 
Indexing with MongoDB
Indexing with MongoDB
MongoDB
 
Mongo Nosql CRUD Operations
Mongo Nosql CRUD Operations
anujaggarwal49
 
Ad

Recently uploaded (20)

Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 
Daily Lesson Log MATATAG ICT TEchnology 8
Daily Lesson Log MATATAG ICT TEchnology 8
LOIDAALMAZAN3
 
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
2025_06_18 - OpenMetadata Community Meeting.pdf
2025_06_18 - OpenMetadata Community Meeting.pdf
OpenMetadata
 
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Smarter Aviation Data Management: Lessons from Swedavia Airports and Sweco
Safe Software
 
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
 
9-1-1 Addressing: End-to-End Automation Using FME
9-1-1 Addressing: End-to-End Automation Using FME
Safe Software
 
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape schützt, was zählt! Und besonders mit dem neust...
Josef Weingand
 
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
Agentic AI for Developers and Data Scientists Build an AI Agent in 10 Lines o...
All Things Open
 
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
Database Benchmarking for Performance Masterclass: Session 2 - Data Modeling ...
ScyllaDB
 
"Scaling in space and time with Temporal", Andriy Lupa.pdf
"Scaling in space and time with Temporal", Andriy Lupa.pdf
Fwdays
 
Security Tips for Enterprise Azure Solutions
Security Tips for Enterprise Azure Solutions
Michele Leroux Bustamante
 
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Coordinated Disclosure for ML - What's Different and What's the Same.pdf
Priyanka Aash
 
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
AI Agents and FME: A How-to Guide on Generating Synthetic Metadata
Safe Software
 
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
 
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
GenAI Opportunities and Challenges - Where 370 Enterprises Are Focusing Now.pdf
Priyanka Aash
 
The Future of Product Management in AI ERA.pdf
The Future of Product Management in AI ERA.pdf
Alyona Owens
 
From Manual to Auto Searching- FME in the Driver's Seat
From Manual to Auto Searching- FME in the Driver's Seat
Safe Software
 

Running Production MongoDB Lightning Talk

  • 2. Let’s talk about production MongoDB Database Happiness Developer Fun
  • 3. But it doesn’t need to be this way.
  • 4. Let’s use House Stark as an example
  • 5. It starts with the data model _id name home p_id 0 Ned Stark Winterfell 0 1 Arya Stark Winterfell 1 2 Bran Stark Winterfell 2 p_id proficiencies 0 keeping a cool head 1 pulling off the short hair look 2 riding piggyback
  • 6. Arrays in MongoDB { _id: ObjectId(“000”), name: “Ned Stark”, relatives: [ ObjectId(“001”), ObjectId(“002”) ] } { _id: ObjectId(“000”), name: “Ned Stark”, relatives: [ { _id: ObjectId(“001”), name: “Arya Stark”, … }, { _id: ObjectId(“002”), name: “Bran Stark”, … } ] } vs.
  • 7. What are “total normalization” trade-offs? { _id: ObjectId(“000”), name: “Ned Stark”, relatives: [ ObjectId(“001”), ObjectId(“002”) ] }
  • 8. Here is Ned Stark. His relatives are: ObjectId(“001”) ObjectId(“002”)
  • 9. And “partial denormalization”? { _id: ObjectId(“000”), name: “Ned Stark”, relatives: [ { _id: ObjectId(“001”), name: “Arya Stark”, img: “../arya.png” } { _id: ObjectId(“002”), name: “Bran Stark”, img: “../bran.png” } ] }
  • 10. Here is Ned Stark. His relatives are: Arya Stark Bran Stark
  • 11. Rules on Arrays High reads, low updates/writes Array should be bound in size Don’t need to frequently access embedded items individually
  • 12. #1 cause of slow databases: (lack of) indexes
  • 13. cursor.explain() tells us if we’re indexed { "cursor" : "<Cursor Type and Index>", "n" : <num>, "nscannedObjects" : <num>, "nscanned" : <num>, "nscannedObjectsAllPlans" : <num>, "nscannedAllPlans" : <num>, "scanAndOrder" : <boolean>, "indexOnly" : <boolean>, "millis" : <num>, "indexBounds" : { <index bounds> }, "allPlans" : [ { "cursor" : "<Cursor Type and Index>", "n" : <num>, "nscannedObjects" : <num>, "nscanned" : <num>, "indexBounds" : { <index bounds> } }, ... ] }
  • 14. Remember our indexing essentials scanAndOrder n vs nScanned NO BasicCursor!!!!!!!!!!!!! NO! Tier 3 Tier 2 Tier 1
  • 16. How to save your database • mongod logs • db.currentOp() & db.killOp()
  • 17. There’s lots of good info in the logs • 2014-10-09T02:26:58.994-0700 [conn367784] query gotDB.people query: { $query: { isAlive: true }, $orderby: { age: 1 } } planSummary: IXSCAN { isAlive: 1 }, cursorid:1736436984952 ntoreturn:10 ntoskip:0 nscanned:7677 nscannedObjects:7677 scanAndOrder:1 keyUpdates:0 numYields:0 locks(micros) r:115557 nreturned:10 reslen:34036 115ms • 2014-10-09T21:26:58.994-0700 [conn127156] command gotDB.$cmd command: mapReduce { $msg: "query not recording (too large)" } planSummary: COLLSCAN keyUpdates:0 numYields:3843 locks(micros) W:2840 r:85085260 w:26899 reslen:187 76657ms
  • 18. Use currentOp() to triage slow operations db.currentOp().inprog.forEach( function(op) { if(op.secs_running > 5) printjson(op); } )
  • 19. Terminate slowness { "locks": { "^myDB": "R" }, "ns": "myDB.bar", "op": "query", "opid": 1344808, "query": {}, "secs_running": 53, "waitingForLock": false } db.killOp(1344808)
  • 20. Thanks for listening! [email protected] @chrisckchang @mongolab

Editor's Notes

  • #12: query too large
  • #18: note 2.6 logs check to see connections are authenticating, where connections are coming from, what operations are slow, etc. what’s going on to my database right now