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

High Performance Real Time Analytics - MongoSV 2012

High Performance Real Time Analytics - MongoSV 2012

Real time analytics is a compelling use case for MongoDB, but only if everything is up and running smoothly. We'll talk about how to set up and configure MongoDB to maintain high performance and redundancy. This will cover what to consider for high write throughput performance from hardware configuration through to the use of replica sets, multi-data centre deployments, monitoring and sharding to ensure your database is fast and stays online.

Presented by David Mytton at MongoSV 2012

Server Density

December 04, 2012
Tweet

More Decks by Server Density

Other Decks in Technology

Transcript

  1. •MySQL -> MongoDB •17TB data per month •27 nodes MongoDB

    at Server Density • June 2009 - +3yrs
  2. Fast out of the box? Photo: dannychoo.com • Local instance

    storage • Softlayer cloud (1 core, 8GB)
  3. Fast out of the box? Photo: dannychoo.com • Local instance

    storage • Ubuntu 10.04 LTS • Softlayer cloud (1 core, 8GB)
  4. Picture is unrelated! Mmm, ice cream. Fast out of the

    box? • Fast network • Working set in RAM
  5. mongos> db.metrics_20120508_15_1m.stats() { "sharded" : true, "flags" : 1, "ns"

    : "metrics.metrics_20120508_15_1m", "count" : 2752934, "numExtents" : 46, "size" : 746837640, "storageSize" : 823717888, "totalIndexSize" : 517581680, "indexSizes" : { "_id_" : 130358144, "a_1_i_1" : 155711920, "a_1_i_1_m_1_t_1" : 231511616 }, "avgObjSize" : 271.2878841265355, "nindexes" : 3, "nchunks" : 61,
  6. How you’ll know 1) Slow queries Thu Oct 14 17:01:11

    [conn7410] update sd.apiLog query: { c: "android/setDeviceToken", a: 1466, u: "blah", ua: "Server Density Android" } 51926ms www.flickr.com/photos/tonivc/2283676770/
  7. Picture is unrelated! Mmm, ice cream. Fast out of the

    box? • Fast network • Working set in RAM
  8. Picture is unrelated! Mmm, ice cream. Fast out of the

    box? • Fast network • Working set in RAM • Fast disks (optional)
  9. Updates in place > db.coll.stats() { "ns" : "...", ...,

    "paddingFactor" : 1, ..., "ok" : 1 }
  10. Picture is unrelated! Mmm, ice cream. Fast out of the

    box? • Fast network • Working set in RAM • Fast disks (optional)
  11. Picture is unrelated! Mmm, ice cream. Fast out of the

    box? • Fast network • Working set in RAM • Fast disks (optional) • Sharding (optional)
  12. rs.status() www.ex-astris-scientia.org/inconsistencies/ent_vs_tng.htm (yes it’s a replicator from Star Trek) {

    ! "_id" : 1, ! "name" : "rs3b:27018", ! "health" : 1, ! "state" : 2, ! "stateStr" : "SECONDARY", ! "uptime" : 1886098, ! "optime" : { ! ! "t" : 1291252178000, ! ! "i" : 13 ! }, ! "optimeDate" : ISODate("2010-12-02T01:09:38Z"), "lastHeartbeat" : ISODate("2010-12-02T01:09:38Z") },
  13. 1) myState rs.status() Value Meaning 0 Starting up (phase 1)

    1 Primary 2 Secondary 3 Recovering 4 Fatal error 5 Starting up (phase 2) 6 Unknown state 7 Arbiter 8 Down
  14. • Safe by default WriteConcern >>> from pymongo import MongoClient

    >>> connection = MongoClient(w=int/str) Value Meaning 0 Unsafe 1 Primary 2 Primary + x1 secondary 3 Primary + x2 secondaries
  15. Tags { _id : "someSet", members : [ {_id :

    0, host : "A", tags : {"dc": "ny"}}, {_id : 1, host : "B", tags : {"dc": "ny"}}, {_id : 2, host : "C", tags : {"dc": "sf"}}, {_id : 3, host : "D", tags : {"dc": "sf"}}, {_id : 4, host : "E", tags : {"dc": "cloud"}} ] settings : { getLastErrorModes : { veryImportant : {"dc" : 3}, sortOfImportant : {"dc" : 2} } } } > db.foo.insert({x:1}) > db.runCommand({getLastError : 1, w : "veryImportant"})
  16. { _id : "someSet", members : [ {_id : 0,

    host : "A", tags : {"dc": "ny"}}, {_id : 1, host : "B", tags : {"dc": "ny"}}, {_id : 2, host : "C", tags : {"dc": "sf"}}, {_id : 3, host : "D", tags : {"dc": "sf"}}, {_id : 4, host : "E", tags : {"dc": "cloud"}} ] settings : { getLastErrorModes : { veryImportant : {"dc" : 3}, sortOfImportant : {"dc" : 2} } } } > db.foo.insert({x:1}) > db.runCommand({getLastError : 1, w : "veryImportant"}) (A or B) + (C or D) + E Tags
  17. { _id : "someSet", members : [ {_id : 0,

    host : "A", tags : {"dc": "ny"}}, {_id : 1, host : "B", tags : {"dc": "ny"}}, {_id : 2, host : "C", tags : {"dc": "sf"}}, {_id : 3, host : "D", tags : {"dc": "sf"}}, {_id : 4, host : "E", tags : {"dc": "cloud"}} ] settings : { getLastErrorModes : { veryImportant : {"dc" : 3}, sortOfImportant : {"dc" : 2} } } } > db.foo.insert({x:1}) > db.runCommand({getLastError : 1, w : "sortOfImportant"}) (A + C) or (D + E) ... Tags
  18. Current operations www.flickr.com/photos/jeffhester/2784666811/ db.currentOp(); { ! ! ! "opid" :

    "shard1:299939199", ! ! ! "active" : true, ! ! ! "lockType" : "write", ! ! ! "waitingForLock" : false, ! ! ! "secs_running" : 15419, ! ! ! "op" : "remove", ! ! ! "ns" : "sd.metrics", ! ! ! "query" : { ! ! ! ! "accId" : 1391, ! ! ! ! "tA" : { ! ! ! ! ! "$lte" : ISODate("2010-11-24T19:53:00Z") ! ! ! ! } ! ! ! }, ! ! ! "client" : "10.121.12.228:44426", ! ! ! "desc" : "conn" ! ! },
  19. Picture is unrelated! Mmm, ice cream. Fast out of the

    box? • Fast network • Working set in RAM
  20. Picture is unrelated! Mmm, ice cream. Fast out of the

    box? • Fast network • Working set in RAM • bit.ly/benchrun