Superficial mongo db

1,263 views

Published on

Published in: Technology, Business
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,263
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
22
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide

Superficial mongo db

  1. 1. Superficial MongoDB charsyam@naver.com
  2. 2. MongoDB NoSQLDocument BSON
  3. 3. Document-Oriented StorageFull Index SupportReplication & High AvailabilityAuto ShardingQueryingFast In-Place UpdatesMap/ReduceGridFS
  4. 4. Document-Oriented StorageFull Index SupportReplication & High AvailabilityAuto ShardingQueryingFast In-Place UpdatesMap/ReduceGridFS
  5. 5. Document-Oriented > db.users.insert( { _id : "alex", name: { first:"Alex", last:"Benisson" }, karma : 1.0 } )> db.posts.findOne() { _id : ObjectId("4e77bb3b8a3e000000004f7a"), when : Date("2011-09-19T02:10:11.3Z", author : "alex", title : "No Free Lunch", text : "This is the text of the post. It could be very long.", tags : [ "business", "ramblings" ], votes : 5, voters : [ "jane", "joe", "spencer", "phyllis", "li" ], comments : [ { who : "jane", when : Date("2011-09-19T04:00:10.112Z"), comment : "I agree." }, { who : "meghan", when : Date("2011-09-20T14:36:06.958Z"), comment : "You must be joking. etc etc ..." } ] }
  6. 6. Full-Index Support> db.things.ensureIndex({j:1});> db.things.ensureIndex({"address.city": 1})> db.things.ensureIndex({j:1, name:-1});> db.factories.insert( { name: "xyz", metro: { city: "New York", state: "NY" } } );> db.factories.ensureIndex( { metro : 1 } ); // this query can use the above index: >> db.factories.find( { metro: { city: "New York", state: "NY" } } );// this one too, as {city:"New York"} < {city:"New York",state:"NY"}> db.factories.find( { metro: { $gte : { city: "New York" } } } );// this query does not match the document because the order of fields is significant> db.factories.find( { metro: { state: "NY" , city: "New York" } } );
  7. 7. Replication Asynchronous Replication
  8. 8. HA & FailOverOnly Write to PrimaryCan read from SecondaryOp Ordinal:Increasing ordinal to represent each operationUsing Server ID + Op Ordinal
  9. 9. Picking Primary1. Get Max LocalOpOrdinal from each Server2. if a majority of servers are not up (fromthis servers POV), remain in Secondarymode and stop.3. if the last op time seems very old, stopand await human intervention.4. else, using a consensus protocol, pick theserver with the highest maxLocalOpOrdinalas the Primary.
  10. 10. TIPs.
  11. 11. Use 64bit MachineMongoDB Use Memory-Mapped FileIn 32bit. DB Size can’t over 2.5GBMongoDB is needed Big Memory
  12. 12. Use Replica SetUse Replica Set and Journaling
  13. 13. Use Lastest Version2.0.2 is better than 1.8.xMongoDB has global Lock1.8.x uses global Write Lock2.0.x uses write with yield.Not supports db or collection lock
  14. 14. Use Big MemoryDisk Op is slower than Memory Op
  15. 15. Shard
  16. 16. Shard Architecture
  17. 17. BasicData is split up into ChunksChunk: 64mb or 100,000 objects Replication unit is chunk. Chunk Count > 9
  18. 18. MongodData Store Replica Set(3 mongod)
  19. 19. MongosProxy StateLess Routing to Shard
  20. 20. Mongod configSvrmongodCan’t use Replica Set or M/A1(test) or 3(real)
  21. 21. Mongod configSvrChanges are made with 2PCIf any are down, meta datagoes read onlySystem is online as long as 1/3is up
  22. 22. Use Scale Up than ShardingDifficult to find good Shard Key.Not Support Data CenterawarenessAdd memory and hdd, ssd
  23. 23. Object Id_
  24. 24. Object Id_12 bytes
  25. 25. Replica Set
  26. 26. OperationsDefault: Write/read operationgoes to masterCan read from slaves.
  27. 27. Thank you!

×