[more] mongodb performance tips

12
[More] MongoDB Performance Tips Colin Howe @colinhowe http://www.colinhowe.co.uk

Upload: colinthehowe

Post on 02-Jul-2015

420 views

Category:

Technology


1 download

TRANSCRIPT

Page 1: [More] MongoDB Performance Tips

[More] MongoDB Performance

TipsColin Howe@colinhowe

http://www.colinhowe.co.uk

Page 2: [More] MongoDB Performance Tips

MongoDB is a Sports Car

Page 3: [More] MongoDB Performance Tips

MongoDB is a Sports Car

Give it bad conditions and it crawls

Page 4: [More] MongoDB Performance Tips

3 Tricks for Minimising

Disk Access

Page 5: [More] MongoDB Performance Tips

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

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

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

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

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

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

MANDATORY NOTICE:

Always benchmark

your use case

Page 12: [More] MongoDB Performance Tips

Questions?