Upgrade to Pro — share decks privately, control downloads, hide ads and more …

MongoDB UK 2012: Overview of Sharding

mongodb
June 20, 2012
350

MongoDB UK 2012: Overview of Sharding

Daniel Roberts, 10gen
Primer on horizontal scaling with MongoDB. Introduces the core concepts behind storing and querying large datasets in addition to presenting the architecture, mechanics, and configuration of a sharded cluster.

mongodb

June 20, 2012
Tweet

Transcript

  1. Write scaling - add Shards write read shard1 node_c1 node_b1

    node_a1 shard2 node_c2 node_b2 node_a2
  2. Write scaling - add Shards write read shard1 node_c1 node_b1

    node_a1 shard2 node_c2 node_b2 node_a2 shard3 node_c3 node_b3 node_a3
  3. MongoDB Sharding Automatic partitioning and management Range based Convert to

    sharded system with no downtime Fully consistent • • • •
  4. Range Based Partitioning >"db.posts.save("{age:40}") -∞ +∞ -∞ 40 41 +∞

    Data in inserted Ranges are split into more “chunks” • •
  5. How MongoDB Sharding works >"db.posts.save("{age:40}") >"db.posts.save("{age:50}") -∞ +∞ -∞ 40

    41 +∞ 41 50 51 +∞ More Data in inserted Ranges are split into more“chunks” • •
  6. -∞ +∞ 41 +∞ 51 +∞ How MongoDB Sharding works

    >"db.posts.save("{age:40}") >"db.posts.save("{age:50}") >"db.posts.save("{age:60}") -∞ 40 41 50 61 +∞ 51 60 shard1
  7. How MongoDB Sharding works >"db.runCommand("{"addshard":""shard2""}"); -∞ 40 41 50 61

    +∞ 51 60 shard1 shard2 >"db.runCommand("{"addshard":""shard3""}"); shard3
  8. mongos Shard Router Acts just like a MongoD 1 or

    as many as you want Can run on App Servers Caches meta-data from config servers • • • • •
  9. Config Server 3 of them Changes use 2 phase commit

    If any are down, meta data goes read only System is online as long as 1/3 is up • • • •
  10. Keys { name: “Jared”, email: “[email protected]”, } { name: “Scott”,

    email: “[email protected]”, } { name: “Dan”, email: “[email protected]”, } > db.runCommand( { shardcollection: “test.users”, key: { email: 1 }} )
  11. Chunks Min Key Max Key Shard -∞ [email protected] 1 [email protected]

    [email protected] 1 [email protected] [email protected] 1 [email protected] +∞ 1 Stored in the config servers Cached in MongoS Used to route requests and keep cluster balanced • • •
  12. Balancing Shard 1 Shard 2 Shard 3 Shard 4 5

    9 1 6 10 2 7 11 3 8 12 4 17 21 13 18 22 14 19 23 15 20 24 16 29 33 25 30 34 26 31 35 27 32 36 28 41 45 37 42 46 38 43 47 39 44 48 40 mongos balancer config config config Chunks!
  13. Balancing mongos balancer config config config Shard 1 Shard 2

    Shard 3 Shard 4 5 9 1 6 10 2 7 11 3 8 12 4 21 22 23 24 33 34 35 36 45 46 47 48 Imbalance Imbalance
  14. Balancing mongos balancer Move chunk 1 to Shard 2 config

    config config Shard 1 Shard 2 Shard 3 Shard 4 5 9 1 6 10 2 7 11 3 8 12 4 21 22 23 24 33 34 35 36 45 46 47 48