How MongoDB works

688 views

Published on

Deck for a short talk I've given on a EPAM Software Engineering Conference 2013.

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
688
On SlideShare
0
From Embeds
0
Number of Embeds
10
Actions
Shares
0
Downloads
0
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

How MongoDB works

  1. 1. How MongoDB worksUladzimir MihuraSenior Software Engineer, EPAM Systems Software Engineering Conference 2013
  2. 2. Data Model{name:mongo,  type:DB}
  3. 3. Data Model: Document oriented{    _id:  1,    name:  {        first:  Michael,        last:  Faraday    },    birth:  new  Date(Sep  22,  1791),    death:  new  Date(Aug  25,  1867),    contribs:  [Chemistry,  Electricity,  Diamagnetism]}
  4. 4. Data Model: BSON {  hello:  SEC  2013} x19x00x00x00  x02hellox09x00x00x00  SEC  2013x00
  5. 5. Data Model: Structure Document Collection Database MongoDB Instance
  6. 6. Readingdb.foo.find({name:Niels,  surname:Bohr})
  7. 7. Reading: Dynamic Queries• find, findOne• accepts a conditions object • regex, strings, numbers, etc...• rich operators • $lt, $gt, $or, $and, $in, $ne, ...• projections • specify fields to return
  8. 8. Reading: Indexes• B-Tree• multiply fields Di Lu Rh• options Zo Sa Cr St B C • unique • Ka sparse Cr H B C • 2d F • full text search (≥2.4)
  9. 9. Reading: Query Optimizer db.foo.find({  x:  10,  y:bar}) full scan xindex on x xindex on y remember
  10. 10. Writingdb.foo.insert({name:Georg,  surname:Ohm})
  11. 11. Writing: Write Concerns• Errors ignored (even network errors)• Unacknowledged (fire & forget)• Acknowledged (write accepted)• Journaled• Propagated to the replica set members
  12. 12. Writing: Isolationdb.foo.update(   {  field1  :  1  ,  $isolated  :  1  },   {  $inc  :  {  field2  :  1  }  }  , {  multi:  true  }  )
  13. 13. Storage Management{name:mongo,  type:DB}
  14. 14. Storage: Padding factor ... Padding Header BSON Data Padding Header ...
  15. 15. Storage: Directory Layout-­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl        64M  Jan  28  14:38  foo.0-­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl      128M  Jan  28  14:26  foo.1-­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl      256M  Jan  28  14:31  foo.2-­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl      512M  Jan  28  14:38  foo.3-­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl      1.0G  Jan  28  14:38  foo.4-­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl      2.0G  Jan  28  14:38  foo.5-­‐rw-­‐-­‐-­‐-­‐-­‐-­‐-­‐    1  trnl    trnl        16M  Jan  28  14:38  foo.ns • Separate files per database • Aggressive preallocation
  16. 16. Storage: Memory mapped files Virtual Memory foo.1 foo.2 foo.3 ... foo.n
  17. 17. Scaling{name:mongo,  type:DB}
  18. 18. Scaling: Replication Node 1 Node 2 Secondary Secondaryread Node 3 read Replication Primary Replication read write client
  19. 19. Scaling: Replication Replication Node 1 Node 2 Primary Secondaryread write Node 3 read Primary client
  20. 20. Scaling: Replication Replication Node 1 Node 2 Primary Secondary Replicationread write Node 3 read Secondary read client
  21. 21. Scaling: ShardingConfig ClientServersmongod mongos mongos ...mongodmongod Replica Set Replica Set Replica Set mongod mongod mongod mongod mongod mongod mongod mongod mongod Shards
  22. 22. MongoDB Drivers Team @ 10gen
  23. 23. Hosted Solutions• MongoLab.com• MongoHQ.com• HostedMongo.com• MongoMachine.com• ObjectRocket• etc
  24. 24. http://try.mongodb.org/ http://on.fb.me/bymongo/Thank you. Let’s ask.

×