[more] mongodb performance tips
TRANSCRIPT
![Page 1: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/1.jpg)
[More] MongoDB Performance
TipsColin Howe@colinhowe
http://www.colinhowe.co.uk
![Page 2: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/2.jpg)
MongoDB is a Sports Car
![Page 3: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/3.jpg)
MongoDB is a Sports Car
Give it bad conditions and it crawls
![Page 4: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/4.jpg)
3 Tricks for Minimising
Disk Access
![Page 5: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/5.jpg)
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
![Page 6: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/6.jpg)
Group Documents Together (2)
Fewer random seeks= Faster
Grouped documents
= Less overhead= More in working set
See: http://bit.ly/foursquare-metrics-mongodb
![Page 7: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/7.jpg)
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
![Page 8: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/8.jpg)
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
![Page 9: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/9.jpg)
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
![Page 10: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/10.jpg)
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
![Page 11: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/11.jpg)
MANDATORY NOTICE:
Always benchmark
your use case
![Page 12: [More] MongoDB Performance Tips](https://reader033.vdocuments.net/reader033/viewer/2022052601/559498a21a28ab091f8b46d0/html5/thumbnails/12.jpg)
Questions?