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

2011-MongoDC-Scaling.pdf

 2011-MongoDC-Scaling.pdf

Avatar for mongodb

mongodb

July 12, 2011
Tweet

More Decks by mongodb

Other Decks in Programming

Transcript

  1. Horizontal Scaling • Vertical scaling is limited • Hard to

    scale vertically in the cloud • Can scale wider than higher
  2. Replica Sets • One master at any time • Programmer

    determines if read hits master or a slave • Easy to setup to scale reads
  3. db.people.find( { state : “NY” } ).addOption( SlaveOK ) •

    routed to a secondary automatically • will use master if no secondary is available
  4. Not Enough • Writes don’t scale • Reads are out

    of date on slaves • RAM/Data Size doesn’t scale
  5. • Distribute write load • Keep working set in RAM

    • Consistent reads • Preserve functionality Why Shard?
  6. Sharding Design Goals • Scale linearly • Increase capacity with

    no downtime • Transparent to the application • Low administration to add capacity
  7. • Choose how you partition data • Convert from single

    replica set to sharding with no downtime • Full feature set • Fully consistent by default Basics
  8. Architecture client mongos ... mongos mongod mongod ... Shards mongod

    mongod mongod Config Servers mongod mongod mongod mongod mongod mongod mongod client client client
  9. Data Center Primary Data Center Secondary S1 p=1 S1 p=1

    S1 p=0 S2 p=0 S3 p=0 S2 p=1 S3 p=1 S2 p=1 S3 p=1 Config 2 Config 2 Config 1 mongos mongos mongos mongos Typical Basic Setup
  10. Range Based • collection is broken into chunks by range

    • chunks default to 64mb or 100,000 objects
  11. Choosing a Shard Key • Shard key determines how data

    is partitioned • Hard to change • Most important performance decision
  12. Use Case: Photos { photo_id : ???? , data :

    <binary> } What’s the right key? • auto increment • MD5( data ) • month() + MD5(data)
  13. Initial Loading • System start with 1 chunk • Writes

    will hit 1 shard and then move • Pre-splitting for initial bulk loading can dramatically improve bulk load time
  14. Administering a Cluster • Do not wait too long to

    add capacity • Need capacity for normal workload + cost of moving data • Stay < 70% operational capacity
  15. Hardware Considerations • Understand working set and make sure it

    can fit in RAM • Choose appropriate sized boxes for shards • Too small and admin/overhead goes up • Too large, and you can’t add capacity smoothly
  16. Download MongoDB http://www.mongodb.org and  let  us  know  what  you  think

    @eliothorowitz        @mongodb 10gen is hiring! http://www.10gen.com/jobs
  17. Use Case: User Profiles { email : “[email protected]” , addresses

    : [ { state : “NY” } ] } • Shard by email • Lookup by email hits 1 node • Index on { “addresses.state” : 1 }
  18. Use Case: Activity Stream { user_id : XXX, event_id :

    YYY , data : ZZZ } • Shard by user_id • Looking up an activity stream hits 1 node • Writing even is distributed • Index on { “event_id” : 1 } for deletes