Rick Copeland @rick446 Arborian Consulting, LLC
Rick Copeland @rick446 Arborian Consulting, LLC
used well)
Mainly write Python now, but have done C++, C#,
+1 Year
Row
Column
Document
Field
Think JSON
Primitive types + arrays, documents
{ title: "Slides for Scaling with MongoDB", author: "Rick Copeland", date: ISODate("20012-02-29T19:30:00Z"), text: "My slides are available on speakerdeck.com", comments: [ { author: "anonymous", date: ISODate("20012-02-29T19:30:01Z"), text: "Frist psot!" }, { author: "mark, date: ISODate("20012-02-29T19:45:23Z"), text: "Nice slides" } ] }
Embed comment data in blog post document
Seek = 5+ ms
Looked at 7 objects
Looked at 3 objects
Working set =
sizeof(frequently used data) + sizeof(frequently used indexes)
Right-aligned indexes reduce working set size Working set should fit in available RAM for best performance Page faults are the biggest cause of performance loss in MongoDB
> db.foo.stats() { "ns" : "test.foo", "count" : 1338330, "size" : 46915928, "avgObjSize" : 35.05557523181876, "storageSize" : 86092032, "numExtents" : 12, "nindexes" : 2, "lastExtentSize" : 20872960, "paddingFactor" : 1, "flags" : 0, "totalIndexSize" : 99860480, "indexSizes" : { "_id_" : 55877632, "x_1" : 43982848}, "ok" : 1 }
Data Size
Read
Secondary
Read
Secondary
Primary handles all writes Application optionally sends reads to slaves Heartbeat manages automatic failover
Special collection (the oplog) records operations idempotently Secondaries read from primary oplog and replay operations locally Space is preallocated and fixed for the oplog
{ "ts" : Timestamp(1317653790000, 2), Insert "h" : -6022751846629753359, "op" : "i", Collection name "ns" : "confoo.People", "o" : { "_id" : ObjectId("4e89cd1e0364241932324269"), "first" : "Rick", "last" : "Copeland } }
Object to insert
Priority
Slower nodes with lower priority Backup or read-only nodes to never be primary
slaveDelay
Fat-finger protection
guarantees
Configuration
MongoS MongoS
Config 1 Config 2 Config 3
Shard 1 0..10
Primary
Shard 2 10..20
Primary
Shard 3 20..30
Primary
Shard 4 30..40
Primary
Secondary
Secondary
Secondary
Secondary
Secondary
Secondary
Secondary
Secondary
Shard 2 Priority 1
Shard 2 Priority 1
Shard 2 Priority 0
Shard 3 Priority 1
Shard 3 Priority 1
RS3
Shard 3 Priority 0
Config 1
Config 2
Config 3
Writes and reads both scale (with good choice of shard key) Reads scale while remaining strongly consistent
Partitioning ensures you get more usable RAM Pitfall: dont wait too long to add capacity