2010-08-26-mongodb-step-by-step-by-hexnova

3,001 views
2,911 views

Published on

A lecture about the way to deep inside mongodb.
2010-08-26 shanghai

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
3,001
On SlideShare
0
From Embeds
0
Number of Embeds
207
Actions
Shares
0
Downloads
74
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

2010-08-26-mongodb-step-by-step-by-hexnova

  1. 1. Step by Step<br />{author: “Daisy Li.“, mail: “daisy.li1989@gmail.com”, knowmore: “hexnova.org” } <br />
  2. 2. mongoDB<br />{name: “mongo”, type: “DB”}<br />Got it name from?<br />humongous (very big, [= enormous])<br />Document-oriented storage ?<br />JSON-style documents.(BSON)<br />Dynamic schemas.<br />Scalable, High availability.<br />mongos: automatic sharding<br />replica set: automatic failover<br />Open source<br />GNU Affero General Public License<br />Full Index Support<br />Compound Keys Indexes<br />Background Index Building<br />
  3. 3. Learn mongoDB<br />Try mongoDB<br />Use mongoDB<br />Your mongoDB<br />
  4. 4. Try mongoDB: A Simple Way<br />Using Tiny mongoDB Brower Shell<br />Visit www.mongodb.org => TRY IT OUT<br />
  5. 5. Try mongoDB: Shell Example<br />MongoDB browser shell version: 0.1.0<br />connecting to random database<br />type "help" for help<br />type "tutorial" to start the tutorial<br />> a = {name: "mongo", type: "DB"}<br />{ "name" : "mongo", "type" : "DB" }<br />> db.mycollection.save(a);<br />"ok"<br />> db.mycollection.update({name: "mongo"}, {$set: {license: "AGPL"}});<br />"ok"<br />> db.mycollection.find();[   {   "name" : "mongo",   "license" : "AGPL",   "type" : "DB",   "_id" : {   "$oid" : "4c665f61cc937415bd001308"   }   }]<br />><br />
  6. 6. Use mongoDB: Strong Side<br />Schemaless<br />No need to backup SQL script<br />Available when started<br />Full Index Support<br />RDBMS-style indexes<br />Background index building<br />High Performance<br />Cache disk file<br />
  7. 7. Use mongoDB: Feature<br />Comparatively Consumptive<br />Memory (BSON)<br />Bandwidth (BSON)<br />Disk (BSON)<br />No Transaction Support<br />Consistency cannot be achieved<br />No transaction isolation<br />
  8. 8. Use mongoDB: BSON in Brief<br />{“hello”: “world”}<br />x16x00x00x00  length<br />x02  property type<br />hellox00  property name<br />x06x00x00x00worldx00<br /> property value<br />x00  a EOF<br />
  9. 9. Use mongoDB: In mongoDB<br />> hexdump –C test.0<br />00003610 b4 12 73 64 69 64 00 1a 00 00 00 00 00 00 00 12 |..sdid..........|<br />00003620 66 73 64 69 64 00 b0 8a 23 ee f4 5d 10 a2 12 67 |fsdid...#..]...g|<br />00003630 72 6f 75 70 49 64 00 e4 4c 6a 09 fe 66 5c 1e 12 |roupId..Lj..f..|<br />00003640 63 72 65 61 74 65 54 69 6d 65 00 4c 0f 7d 84 6a |createTime.L.}.j|<br />00003650 75 f9 3a 12 6c 61 73 74 4d 6f 64 69 66 79 54 69 |u.:.lastModifyTi|<br />00003660 6d 65 00 4b 81 97 39 14 b0 e6 18 10 64 65 6c 46 |me.K..9.....delF|<br />00003670 6c 61 67 00 2a d8 25 11 10 67 72 6f 75 70 54 79 |lag.*.%..groupTy|<br />00003680 70 65 00 6a 1d fc 3b 00 9c 00 00 00 00 26 00 00 |pe.j..;......&..|<br />00003690 24 37 00 00 ec 35 00 00 8c 00 00 00 07 5f 69 64 |$7...5......._id|<br />000036a0 00 4c 74 dd 0a a2 77 3d 23 70 c7 3f b4 12 73 64 |.Lt...w=#p.?..sd|<br />000036b0 69 64 00 1b 00 00 00 00 00 00 00 12 66 73 64 69 |id..........fsdi|<br />000036c0 64 00 32 b0 15 e8 a8 0d 4f 07 12 67 72 6f 75 70 |d.2.....O..group|<br />000036d0 49 64 00 e6 2c c8 c0 f6 b2 d4 7f 12 63 72 65 61 |Id..,.......crea|<br />000036e0 74 65 54 69 6d 65 00 d9 13 13 e5 98 05 1c 01 12 |teTime..........|<br />000036f0 6c 61 73 74 4d 6f 64 69 66 79 54 69 6d 65 00 7d |lastModifyTime.}|<br />00003700 07 b9 d0 32 f8 46 f2 10 64 65 6c 46 6c 61 67 00 |...2.F..delFlag.|<br />00003710 25 5a 9e 20 10 67 72 6f 75 70 54 79 70 65 00 5e |%Z. .groupType.^|<br />00003720 48 ba 3a 00 9c 00 00 00 00 26 00 00 c0 37 00 00 |H.:......&...7..|<br />00003730 88 36 00 00 8c 00 00 00 07 5f 69 64 00 4c 74 dd |.6......._id.Lt.|<br />00003740 0a a2 77 3d 23 71 c7 3f b4 12 73 64 69 64 00 1c |..w=#q.?..sdid..|<br />
  10. 10. Use mongoDB: HA & Scalable<br />
  11. 11. Use mongoDB: Attention<br />Manipulation result not returned<br />Get last error after every operation<br />Server-side cursor<br />If used, read till the last record of a query result or kill the cursor.<br />Take whole control of cursor.<br />
  12. 12. Your mongoDB: Capacity Planning<br />How about the performance of your server? (memorycpuandwidthdisk…)<br />The size of your record? (not your origin object size, but the BSON object size)<br />How much records do you want to hold on single server? (now? future?)<br />TPS under different operations? (insertselect…)<br />
  13. 13. Your mongoDB: Code Tuning<br />Learn to use several tools (SConstructVS2010Emacs…).<br />Analyze source code. <br />Debug it.<br />Find the bottleneck and the codes related.<br />Modify as less as possible.<br />Recompile and retest.<br />
  14. 14. Your mongoDB: Amoeba for mongoDB<br />mongos’ssharding is based on chunk. A chunk represent a range of records. In most cases, IDs cannot be sharded horizontally in this way.<br />8298701<br />149809762<br />1987093<br />0<br />4032987<br />7298610<br />11098726<br />DB1<br />DB2<br />DB3<br />
  15. 15. Your mongoDB: Amoeba for mongoDB<br />Like Amoeba for MySQL, Amoeba for mongoDB will provide full control of sharding rules.(by hash angefunction… horizontally vertically)<br />Better failover. Write multiple copy of data to several nodes. (instead of replication)<br />
  16. 16. Step by Step<br />Thank you!<br />{author: “Daisy Li.“, mail: “daisy.li1989@gmail.com”, knowmore: “hexnova.org” } <br />

×