[more] mongodb performance tips
TRANSCRIPT
[More] MongoDB Performance
TipsColin Howe@colinhowe
http://www.colinhowe.co.uk
MongoDB is a Sports Car
MongoDB is a Sports Car
Give it bad conditions and it crawls
3 Tricks for Minimising
Disk Access
Group Documents Together (1)
Stats system. Data = 3x RAM. Single document per day
1.6s to read an entire year
Single document per month0.3s to read an entire year
Group Documents Together (2)
Fewer random seeks= Faster
Grouped documents
= Less overhead= More in working set
See: http://bit.ly/foursquare-metrics-mongodb
Unusual Indices (1)
Index on metric type then date:Inserts started at 10k/secDropped to 2.5k/sec after 20m inserts
Index on date then metric type:
Inserts stayed at 10k/sec
No hit on query performance
Unusual Indices (2)
Only inserting to one side of index Rebalancing hits less of the index
⇒ Less to flush to disk⇒ More will be in memory
Pre-Allocate for Locality (1)
Pre-allocate data in read order Data written in key then date order
6.6ms to query data for a year Data written in date then key order
62ms to query data for a year
Pre-Allocate for Locality (2)
Data exists on disk in the order it is written (ignoring resized documents)
Reading 12 random documents from disk
= 12 seeks Reading 12 documents written at same time
= 1 seek + 11 sequential reads
MANDATORY NOTICE:
Always benchmark
your use case
Questions?