scale your mongodb in 5 easy steps
TRANSCRIPT
5 Steps to Scale your MongoDB5 Steps to Scale your MongoDB
1. Optimize your Queries1. Optimize your Queriesquery = db.coll.find({title:”My blog”})query.explain();
{"cursor" : "BasicCursor"cursor : BasicCursor ,"indexBounds" : [ ],"nscanned" : 57594,"nscannedObjects" : 57594,"n" : 3,"millis" : 108
}
db.coll.ensureIndex({title:1})
2. Know your working set size2. Know your working set sizeActive
Documents +Documents + Used Indexes
RAM
Disk
3. Tune your file system3. Tune your file system
• EXT3 == badEXT3 bad– Slow file allocation & initialization
EXT4 / XFS == d• EXT4 / XFS == good• Access time tracking == bad
– noatime, nodiratime
4. Choose the right disks4. Choose the right disksSingle Disk
~200 seeks / second
RAID 0
~200 seeks / second ~200 seeks / second ~200 seeks / second
RAID 10
~400 seeks / second ~400 seeks / second ~400 seeks / second
5. Sharding for MongoSMongoS
gwrites & RAM
Sh d 1 Sh d 2 Sh d 3 Sh d 4Shard 10..10
Shard 210..20
Shard 320..30
Shard 430..40
Primary
Secondary
Primary
Secondary
Primary
Secondary
Primary
Secondary
Secondary
y
Secondary
y
Secondary
y
Secondary
y