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

Effective Deployment Architecture - Kevn Matulef

mongodb
April 04, 2012

Effective Deployment Architecture - Kevn Matulef

MongoDB Beijing 2012

mongodb

April 04, 2012
Tweet

More Decks by mongodb

Other Decks in Technology

Transcript

  1. After Party 5:30-7:30pm Sunday Bar & Grill Room 101, Tower

    C, Fang Heng Guo Ji Building, Futong Dong Dajie ෞ௨תେ֗6߸ํ߃ࠃ࠽C࠲101ࣨ
  2. Replica Sets Overview •Replica Sets is MongoDB’s data redundancy and

    availability mechanism •Designed to cope with hardware failures, server downtimes, and so on
  3. Some RS Features •Asynchronous replication from writable node (Primary) to

    read-only nodes (Secondaries) •Automatic failover when the Primary goes offline •App-level definition of “write replication” (the w argument to getLastError) •Secondary nodes can replicate with a slaveDelay
  4. Replica Set 1 Arbiter •Single datacenter •Same switch, power (1

    rack) •Points of failure: •Power •Network •Datacenter •Two node failure •Automatic recovery of single node crash Primary Secondary
  5. Replica Set 2 •Single datacenter •Multiple power/network zones •Points of

    failure: •Datacenter •Two node failure •Automatic recovery of single node crash •w=2 not practical
  6. Replica Set 3 •Single datacenter •Multiple power/network zones •Points of

    failure: •Datacenter •Two node failure •Automatic recovery of single node crash •w=2 practical, can tolerate 1- node failure
  7. Replica Set 4 •Multi datacenter •Disaster Recovery node for safety

    •Can’t do multi data center durable write safely since only 1 node in distant DC DR
  8. Replica Set 5 delayed •Three data centers •Can survive full

    data center loss •Can do w= { dc : 2 } to guarantee write in 2 data centers
  9. Sharding Overview •Sharding is MongoDB’s horizontal scaling architecture •Designed to

    allow you to grow your database capacity linearly with your requirements
  10. When do you need sharding? •If your write load can’t

    be handled by a single replica set’s primary for some reason •If your working set can’t fit into a single replica set’s physical memory capacity
  11. Basics • Each shard should be a replica set •

    All rules for replica sets before apply to each shard
  12. Config Servers • Need to have 3 - best on

    at least 2 different power/network zones • Only need 1 of the 3 to be available • Use host names (mongoconfig[123]) • Take backups • Not Replica Sets
  13. Internals •When collections are sharded, the cluster tracks ranges of

    documents, called chunks. •As chunks grow in size, the cluster automatically splits them into smaller chunks. •If one shard has too many chunks gets, the cluster automatically migrates chunks. •This is all invisible to applications (unless they peek).
  14. Splitting •Splitting happens automatically. •It’s possible to split a chunk

    manually, with the split command. •Splitting is essentially a logical operation: no data gets moved around.
  15. Migrating •Migrations happen automatically, when the number of chunks on

    any shard is too great. •It’s possible to migrate a chunk manually, with the moveChunk command. •Migrations can be expensive, and so you can disable them, e.g., during peak load times on your database: // connect to mongos > use config > db.settings.update( { _id: "balancer" }, { $set : { stopped: true } } , true );
  16. Things Happen • Handle spikes and failure gracefully • Queue

    non-synchronous writes • Isolate components and features • Login and Interacting with e-mail vs. updating contact list • Read only mode?
  17. Develop Your Playbook • Monitor • load, disk, cpu (MMS)

    • Alerts • Procedures • Backups, adding replica set members, adding shards
  18. Practice • (In staging - which should be the same

    as production!) • Randomly shutdown boxes and see how things react • Load test