scaling to 30,000 requests per second and beyond with mongodb

87
Scaling to 30,000 Requests Per Second and Beyond with MongoDB Mike Chesnut Director of Operations Engineering Crittercism

Upload: mchesnut

Post on 29-Jun-2015

1.013 views

Category:

Technology


0 download

DESCRIPTION

Webinar from the MongoDB "Back to Basics" series given June 12, 2014. http://www.mongodb.com/webinar/BB3-perf-consid-June-2014

TRANSCRIPT

Page 1: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Scaling to 30,000 Requests Per Secondand Beyond

with MongoDB

Mike ChesnutDirector of Operations Engineering

Crittercism

Page 2: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Scaling to 30,000 Requests Per Secondand Beyond

with MongoDB

Mike ChesnutDirector of Operations Engineering

Crittercism

40,000

Page 3: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

MongoDB World

June 23-25 world.mongodb.com

Code: 25GN for 25% off

Page 4: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

MongoDB World

June 23-25 world.mongodb.com

Code: 25GN for 25% off

Page 5: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

What I’ll Talk About

Page 6: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

What I’ll Talk About

● Crittercism - Overview● Router (mongos) Architecture● Sharding Considerations● The Balancer and Me● Q&A

Page 7: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

How a Startup Gets Started

Page 8: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

● Pick something and go with it● Make mistakes along the way● Correct the mistakes you can● Work around the ones you can’t

How a Startup Gets Started

Page 9: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Critter-What?

A Brief History...

Page 10: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Critter-What?

Page 11: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Architecture

APIFeedback

Page 12: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Architecture

APIFeedback

App Loads

Crashes

HandledExceptions

Page 13: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Architecture

APIFeedback

App Loads

Crashes

HandledExceptions

Page 14: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Architecture

DynamoDB

APIFeedback

App Loads

Crashes

HandledExceptions

Metadata

Page 15: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Architecture

DynamoDB

APIFeedback

App Loads

Crashes

HandledExceptions

Metadata

Page 16: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Architecture

DynamoDB

API

API

Feedback

App Loads

Crashes

HandledExceptions

Metadata

PerformanceData

Geo Data

Page 17: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Critter-What?

… Which brings us to today.

Page 18: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Critter-What?

Page 19: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Critter-What?

● feedback widget

● crash reporting

● live stats

● crash grouping

● app performance management

● geo data

● user analytics

● executive dashboard

Page 20: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Architecture

DynamoDB

API

API

Feedback

App Loads

Crashes

HandledExceptions

Metadata

PerformanceData

Geo Data

Page 21: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Architecture

DynamoDB

API

API

Feedback

App Loads

Crashes

HandledExceptions

Metadata

PerformanceData

Geo Data

40,000+ req/s

Page 22: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Growth

Page 23: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Router Architecture

Page 24: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Router Architecture

mongodserver

mongodserver

mongodserver

replica set

mongodserver

mongodserver

mongodserver

replica set

mongodserver

mongodserver

mongodserver

replica setmongos

clientprocess

application server

mongos

clientprocess

application server

Client Application(s) MongoDB Cluster

Page 25: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Single mongos per client problems we encountered:

Router Architecture

Page 26: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Router Architecture

Single mongos per client problems we encountered:● thousands of connections to config servers● config server CPU load● configdb propagation delays

Page 27: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Router Architecture

mongodserver

mongodserver

mongodserver

replica set

mongodserver

mongodserver

mongodserver

replica set

mongodserver

mongodserver

mongodserver

replica set

mongos

clientprocess

application server

mongos

clientprocess

application server

Client Application(s) MongoDB ClusterRouter Tier

Page 28: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Router Architecture

Separate mongos tier advantages:

Page 29: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Router Architecture

Separate mongos tier advantages:● greatly reduced number of connections to each mongod● far fewer hosts talking to the config servers● much faster configdb propagation

Page 30: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Router Architecture

Separate mongos tier advantages:● greatly reduced number of connections to each mongod● far fewer hosts talking to the config servers● much faster configdb propagation

Disadvantages:

Page 31: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Router Architecture

Separate mongos tier advantages:● greatly reduced number of connections to each mongod● far fewer hosts talking to the config servers● much faster configdb propagation

Disadvantages:● additional network hop● fewer points of failure

Page 32: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 33: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Pick something you want to live with.

Sharding Considerations

Page 34: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 35: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 36: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 37: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 38: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 39: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 40: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 41: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 42: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 43: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 44: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 45: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 46: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 47: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 48: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Sharding Considerations

Page 49: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

Page 50: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

Why wouldn’t you run the balancer in the first place?● great question● for us, it’s because we deleted a ton of data at one point, and left a

bunch of holes○ we turned it off while deleting this data○ and then were unable to turn it back on

● but maybe you start without it● or maybe you need to turn it off for maintenance and forget to turn

it back on

Obviously, don’t do this. But if you do, here’s what happens...

Page 51: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

Fresh, new, empty cluster… But no balancer running.

Page 52: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

Page 53: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

Page 54: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

Page 55: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

Page 56: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

Page 57: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

Now we’re pretty full, so let’s add another shard...

Page 58: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

Page 59: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

And keep inserting...

Page 60: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

Suddenly we find ourselves with a very unbalanced cluster.

Page 61: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

But if we enable the balancer, it will DoS the 5th shard!

Page 62: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

The approximate effect looks something like this:

Page 63: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

The approximate effect looks something like this:

Page 64: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

The approximate effect looks something like this:

Page 65: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

The approximate effect looks something like this:

Page 66: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

The approximate effect looks something like this:

Page 67: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

The Balancer and Me

The approximate effect looks something like this:

Page 68: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

So what can we do?

The Balancer and Me

Page 69: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

So what can we do?

1. add IOPS

The Balancer and Me

Page 70: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

So what can we do?

1. add IOPS2. make sure your config servers have plenty of CPU (and IOPS)

The Balancer and Me

Page 71: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

So what can we do?

1. add IOPS2. make sure your config servers have plenty of CPU (and IOPS)3. slowly move chunks manually

The Balancer and Me

Page 72: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

So what can we do?

1. add IOPS2. make sure your config servers have plenty of CPU (and IOPS)3. slowly move chunks manually4. approach a balanced state

The Balancer and Me

Page 73: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

So what can we do?

1. add IOPS2. make sure your config servers have plenty of CPU (and IOPS)3. slowly move chunks manually4. approach a balanced state5. hold your breath

The Balancer and Me

Page 74: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

So what can we do?

1. add IOPS2. make sure your config servers have plenty of CPU (and IOPS)3. slowly move chunks manually4. approach a balanced state5. hold your breath6. try re-enabling the balancer

The Balancer and Me

Page 75: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

How to manually balance:

The Balancer and Me

Page 76: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

How to manually balance:

1. determine a chunk on a hot shard2. monitor effects on both the source and target shards3. move the chunk4. allow the system to settle5. repeat

The Balancer and Me

Page 77: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

How to manually balance:

1. determine a chunk on a hot shard

mongos> db.chunks.find({"shard":"<shard_name>",

"ns":"<db_name>.<collection>"}).limit(1).pretty()

You’ll get a single chunk (as both min and max); note its shard key and

ObjectId.

The Balancer and Me

Page 78: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

How to manually balance:

1. determine a chunk on a hot shard

"min" : {

"unsymbolized_hash" :

"1572663b72e87[...]",

"_id" : ObjectId("50b97db98238[...]")

},

The Balancer and Me

Page 79: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

How to manually balance:

1. determine a chunk on a hot shard2. monitor effects on both the source and target shards

iostat -xhm 1

mongostat

The Balancer and Me

Page 80: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

How to manually balance:

1. determine a chunk on a hot shard2. monitor effects on both the source and target shards3. move the chunk

mongos> sh.moveChunk("<db_name>.<collection>",

{ "unsymbolized_hash" : "1572663b72e87[...]",

"_id" : ObjectId("50b97db98238[...]") },

"<target_shard>")

The Balancer and Me

Page 81: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

How to manually balance:

1. determine a chunk on a hot shard2. monitor effects on both the source and target shards3. move the chunk4. allow the system to settle5. repeat

The Balancer and Me

Page 82: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Conclusion here:

Run the balancer.

The Balancer and Me

Page 83: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

● Design ahead of timeo “NoSQL” lets you play it by earo but some of these decisions will bite you later

● Be willing to correct past mistakeso dedicate time and resources to adaptingo learn how to live with the mistakes you can’t correct

Summary

Page 84: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

References

● MongoDB Blog post:http://blog.mongodb.org/post/77278906988/crittercism-scaling-to-billions-of-requests-per-day-on

● MongoDB Documentation on mongos routers:http://docs.mongodb.org/master/core/sharded-cluster-query-routing/

● MongoDB Documentation on the balancer:http://docs.mongodb.org/manual/tutorial/manage-sharded-cluster-balancer/

● MongoDB Documentation on shard keys:http://docs.mongodb.org/manual/core/sharding-shard-key/

Crittercism: http://www.crittercism.com/

Page 85: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

MongoDB World

June 23-25 world.mongodb.com

Code: 25GN for 25% off

Page 86: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Q&A

Page 87: Scaling to 30,000 Requests Per Second and Beyond with MongoDB

Thank You!