mongodb debugging-performance-problems

64
MongoDB Debugging Performance Problems @ConradIrwin

Upload: mongodb

Post on 08-Jul-2015

605 views

Category:

Technology


2 download

DESCRIPTION

Running a MongoDB cluster is usually smooth sailing, but as your load increases you may notice things start to slow down. This talk will run through a few of the options you have to notice problems, and the ways to fix them. We’ll be focussing mainly on running a cluster inside EC2, as the challenges are slightly different, but you should learn something regardless of where you’re hosted.

TRANSCRIPT

Page 1: Mongodb debugging-performance-problems

MongoDB

Debugging Performance Problems

@ConradIrwin

Page 2: Mongodb debugging-performance-problems
Page 3: Mongodb debugging-performance-problems

50M crashes/day

4TB data / 100GB index

15 nodes / 3* availability zones

Page 4: Mongodb debugging-performance-problems

I don't care if MongoDB is slow

I care if my app is slow

Page 5: Mongodb debugging-performance-problems

How to make my app fast again if it's slow because of the way I'm using MongoDB

Page 6: Mongodb debugging-performance-problems

What does slow mean?

Page 7: Mongodb debugging-performance-problems
Page 8: Mongodb debugging-performance-problems

Performance over time

Page 9: Mongodb debugging-performance-problems

Performance over time

Page 10: Mongodb debugging-performance-problems
Page 11: Mongodb debugging-performance-problems

It's slow :(

Page 12: Mongodb debugging-performance-problems
Page 13: Mongodb debugging-performance-problems
Page 14: Mongodb debugging-performance-problems

Solution 1

Denormalize

Page 15: Mongodb debugging-performance-problems
Page 16: Mongodb debugging-performance-problems

It's fast :)

Page 17: Mongodb debugging-performance-problems

It's slow :(

Page 18: Mongodb debugging-performance-problems

db.errors. find({project_id: x}). sort({ _id: -1}). limit(30)

Page 19: Mongodb debugging-performance-problems

db.errors. find({project_id: x}). sort({ _id: -1}). limit(30). explain()

Page 20: Mongodb debugging-performance-problems

{ "cursor" : "BtreeCursor _id_ reverse", "isMultiKey" : false, "n" : 0, "nscannedObjects" : 227756, "nscanned" : 227756, "nscannedObjectsAllPlans" : 227756, "nscannedAllPlans" : 227756, "scanAndOrder" : false, "indexOnly" : false, "nYields" : 1779, "nChunkSkips" : 0, "millis" : 461, "indexBounds" : { "_id" : [ [ { "$maxElement" : 1 }, { "$minElement" : 1 } ] ] }, "server" : "Jaroussky.local:27017", "filterSet" : false}

Page 21: Mongodb debugging-performance-problems

{"cursor" : "BtreeCursor _id_ reverse",

"nscanned" : 227756,

"indexBounds" : {"_id" : [ [{"$maxElement" : 1}, {"$minElement" : 1}] ] }}

Page 22: Mongodb debugging-performance-problems

Solution 2

Index

Page 23: Mongodb debugging-performance-problems

db.errors.ensureIndex( {project_id: 1, _id: -1})

Page 24: Mongodb debugging-performance-problems

{"cursor" : "BtreeCursor project_id_1__id_1","nscanned" : 6,"indexBounds" : { "project_id" : [[ ObjectId(x),ObjectId(x) ]], "_id" : [[ {"$minElement" : 1}, {"$maxElement" : 1} ]]}}

Page 25: Mongodb debugging-performance-problems

It's fast :)

Page 26: Mongodb debugging-performance-problems

It's slow :(

Page 27: Mongodb debugging-performance-problems

Only 1 query...

Indexed properly...

Page 28: Mongodb debugging-performance-problems

mongostat

Page 29: Mongodb debugging-performance-problems

insert query update delete getmore command flushes mapped 5 97 57 *0 95 127|0 0 320g 5 98 61 *0 113 146|0 0 320g 8 94 61 *0 95 137|0 0 320g

vsize res faults locked db idx miss % qr|qw ar|aw 641g 8.65g 7 bugsnag:47.7% 0 0|0 0|0 641g 8.66g 2 bugsnag:21.0% 0 0|0 0|0 641g 8.64g 3 bugsnag:23.4% 0 0|0 0|0

netIn netOut conn set repl time 47k 73k 145 bugsnag1 PRI 06:34:05 63k 99k 146 bugsnag1 PRI 06:34:06 98k 124k 146 bugsnag1 PRI 06:34:07

Page 30: Mongodb debugging-performance-problems

command locked db time 127|0 bugsnag:47.7% 06:34:05 146|0 bugsnag:21.0% 06:34:06 137|0 bugsnag:23.4% 06:34:07

Page 31: Mongodb debugging-performance-problems
Page 32: Mongodb debugging-performance-problems

Solution 3

Shard

Page 33: Mongodb debugging-performance-problems
Page 34: Mongodb debugging-performance-problems

sh.shardCollection("errors"{ project_id: 1, _id: -1})

Page 35: Mongodb debugging-performance-problems

command locked db time 83|0 bugsnag:3.1% 06:46:12 69|0 bugsnag:4.1% 06:46:13 73|0 bugsnag:2.4% 06:46:14

Page 36: Mongodb debugging-performance-problems

It's fast :)

Page 37: Mongodb debugging-performance-problems

It's slow :(

Page 38: Mongodb debugging-performance-problems

Only 1 query...

Indexed properly...

Lock % ok...

Page 39: Mongodb debugging-performance-problems

iostat

Page 40: Mongodb debugging-performance-problems

Device: rrqm/s wrqm/s r/s w/s rkB/s wkB/s avgrq-szxvdi 0.00 2.00 15.00 743.00 436.00 7905.50 22.01xvdi 0.00 2.00 0.00 663.00 0.00 6706.00 20.23xvdi 0.00 1.00 0.00 726.00 0.00 5593.50 15.41

avgqu-sz await r_await w_await svctm %util 11.02 14.54 5.33 14.73 0.60 45.60 8.04 12.12 0.00 12.12 0.51 33.60 13.01 17.92 0.00 17.92 0.50 36.40

Page 41: Mongodb debugging-performance-problems

rkB/s wkB/s await %util 7660 138 14.73 83.60 2248 2043 12.12 65.20 7905 436 17.92 45.60

Page 42: Mongodb debugging-performance-problems

db.stats()['indexSize']= 3852071824

= 3932614656free -b (m3.medium)

Page 43: Mongodb debugging-performance-problems

Solution 4

Scale

Page 44: Mongodb debugging-performance-problems

db.stats()['indexSize']= 3852071824

= 15775363072free -b (r3.large)

Page 45: Mongodb debugging-performance-problems

It's fast :)

Page 46: Mongodb debugging-performance-problems

It's slow :(

Page 47: Mongodb debugging-performance-problems

Main query seems fine...

"Quick" queries sometimes slow...

Page 48: Mongodb debugging-performance-problems

mongotop

Page 49: Mongodb debugging-performance-problems

ns total read write 2014-06-22T19:11:35 bugsnag.events 95ms 0ms 95ms bugsnag.errors 80ms 6ms 74msbugsnag.system.namespaces 26ms 26ms 0ms bugsnag.projects 12ms 5ms 7ms bugsnag.users 15ms 2ms 13ms bugsnag.error_aggregates 4ms 0ms 4ms bugsnag.deploys 4ms 3ms 1ms bugsnag.event_tallies 3ms 0ms 3ms

Page 50: Mongodb debugging-performance-problems

ns tot r w bugsnag.events 95 0 95 bugsnag.errors 80 6 74bugsnag.projects 12 5 7 bugsnag.users 15 7 8

Page 51: Mongodb debugging-performance-problems
Page 52: Mongodb debugging-performance-problems

Solution 5

Tag shards

Page 53: Mongodb debugging-performance-problems
Page 54: Mongodb debugging-performance-problems

It's fast :)

Page 55: Mongodb debugging-performance-problems

Solution 1

Denormalize

Page 56: Mongodb debugging-performance-problems

Solution 2

Index

Page 57: Mongodb debugging-performance-problems

Solution 3

Shard

Page 58: Mongodb debugging-performance-problems

Solution 4

Scale

Page 59: Mongodb debugging-performance-problems

Solution 5

Tag shards

Page 60: Mongodb debugging-performance-problems

Solution 6

...

Page 61: Mongodb debugging-performance-problems

NewRelic / Skylight

explain()

mongostat

iostat

mongotop

...

Page 62: Mongodb debugging-performance-problems

It will be slow

Page 63: Mongodb debugging-performance-problems

You can speed it up

Page 64: Mongodb debugging-performance-problems

Thanks!@ConradIrwin