Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
MongoDB                	       id:matsuou1
!  !  !  !  !  !           Tips!  
!   ID      matsuou1!                 	                 	 !        !        !        !      Oracle     PostgreSQL!        ...
1. 2. 3. 4. 
!  !   RDBMS!  
!  !  
MongoDB         	 !        !               CPU!        !   JOIN!  
•      •    100         insert update    delete     •      •                nscanned        10• 
db/queryoptimizer.cpp
!                                          explain                 	       > db.logs.find({uid:"a10Sty5jqqiyxxxx2"}).expla...
cursor	             BasicCursor	                   	                                        BasicCursor or BtreeCursor 	 n...
(                                       )	 > db.logs.find({uid:"a10Sty5jqqiyxxxx2"}).explain();{           "cursor" : "Bas...
(                                      )	 > db.logs.find({uid:"b3iVxMGIEc3xxxxY"}).explain();{     "cursor" : "BtreeCursor...
!        !     slowms      !              ! db.setProfilingLevel(level,slowms)      !  
slowms                                                	 !   mongod                          slowms                        ...
setProfilingLevel	                                                     setProfilingLevel     (level,slowms)               ...
setProfilingLevel	               system.profile                                                            	 > db.system.p...
db.currentOp                                                 	         	          	 opid	                      ID    KillO...
> db.currentOp();{           "inprog" : [                          {                                   "opid" : 272,      ...
slowms	                                        	 db.setProfilingLevel	    collection         system.profile   capped colle...
Tips
!                                                                    	   • db.c.find( {x:10,y:20} ), using index {x:1,y:1}...
hint	 !   hint!  
hint	 > db.logs.find({uid:"f2RNwtj34m3xxxxB" , path : "/index.html"}).hint({uid:1}).explain();{           "cursor" : "Btre...
hint	 > db.logs.find({uid:"f2RNwtj34m3xxxxB" , path : "/index.html"}).hint({uid:1 , path:1}).explain();{           "cursor...
mongostat	       mongostat                                                   	          	                            	    ...
mongostat                                                       	          	          	 inserts	      insert /        	 qu...
collection                                                   	 !   getIndexKeys()                                     	  >...
!   db.currentOp              opid                   db.killOp(opid)                                 	  > db.currentOp(); ...
!  !        !   explain!        !   slowms      !   setProfilingLevel      !   db.currentOP!                     Tips     ...
20110514 mongo dbチューニング
20110514 mongo dbチューニング
20110514 mongo dbチューニング
20110514 mongo dbチューニング
Upcoming SlideShare
Loading in …5
×

20110514 mongo dbチューニング

50,898 views

Published on

第3回MongoDB勉強会の発表資料です。

Published in: Technology, Business
  • DOWNLOAD THAT BOOKS INTO AVAILABLE FORMAT (2019 Update) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ................................................................................................................................... eBook is an electronic version of a traditional print book that can be read by using a personal computer or by using an eBook reader. (An eBook reader can be a software application for use on a computer such as Microsoft's free Reader application, or a book-sized computer that is used solely as a reading device such as Nuvomedia's Rocket eBook.) Users can purchase an eBook on diskette or CD, but the most popular method of getting an eBook is to purchase a downloadable file of the eBook (or other reading material) from a Web site (such as Barnes and Noble) to be read from the user's computer or reading device. Generally, an eBook can be downloaded in five minutes or less ......................................................................................................................... .............. Browse by Genre Available eBooks .............................................................................................................................. Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, ......................................................................................................................... ......................................................................................................................... .....BEST SELLER FOR EBOOK RECOMMEND............................................................. ......................................................................................................................... Blowout: Corrupted Democracy, Rogue State Russia, and the Richest, Most Destructive Industry on Earth,-- The Ride of a Lifetime: Lessons Learned from 15 Years as CEO of the Walt Disney Company,-- Call Sign Chaos: Learning to Lead,-- StrengthsFinder 2.0,-- Stillness Is the Key,-- She Said: Breaking the Sexual Harassment Story That Helped Ignite a Movement,-- Atomic Habits: An Easy & Proven Way to Build Good Habits & Break Bad Ones,-- Everything Is Figureoutable,-- What It Takes: Lessons in the Pursuit of Excellence,-- Rich Dad Poor Dad: What the Rich Teach Their Kids About Money That the Poor and Middle Class Do Not!,-- The Total Money Makeover: Classic Edition: A Proven Plan for Financial Fitness,-- Shut Up and Listen!: Hard Business Truths that Will Help You Succeed, ......................................................................................................................... .........................................................................................................................
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

20110514 mongo dbチューニング

  1. 1. MongoDB id:matsuou1
  2. 2. !  !  !  !  !  !   Tips!  
  3. 3. !   ID matsuou1!   !   !   !   !   Oracle PostgreSQL!   MongoDB Hadoop R
  4. 4. 1. 2. 3. 4. 
  5. 5. !  !   RDBMS!  
  6. 6. !  !  
  7. 7. MongoDB !   !   CPU!   !   JOIN!  
  8. 8. •  •  100 insert update delete •  •  nscanned 10• 
  9. 9. db/queryoptimizer.cpp
  10. 10. !   explain > db.logs.find({uid:"a10Sty5jqqiyxxxx2"}).explain(); { "cursor" : "BasicCursor", "nscanned" : 2669511, "nscannedObjects" : 2669511, "n" : 3, "millis" : 6100, "nYields" : 0, "nChunkSkips" : 0, "isMultiKey" : false, "indexOnly" : false, "indexBounds" : { } }
  11. 11. cursor BasicCursor BasicCursor or BtreeCursor nscanned 14 nscannedObjects 14 n 14 millis 9 ms nYields 0nChunkSkips 0 Chunk isMultiKey false indexOnly false indexBounds scanAndOrder allPlans
  12. 12. ( ) > db.logs.find({uid:"a10Sty5jqqiyxxxx2"}).explain();{ "cursor" : "BasicCursor", "nscanned" : 2669511, "nscannedObjects" : 2669511, "n" : 3, "millis" : 6100, "nYields" : 0, 6100ms "nChunkSkips" : 0, 3 266 "isMultiKey" : false, "indexOnly" : false, "indexBounds" : { }}
  13. 13. ( ) > db.logs.find({uid:"b3iVxMGIEc3xxxxY"}).explain();{ "cursor" : "BtreeCursor uid_1", "nscanned" : 3, "nscannedObjects" : 3, "n" : 3, "millis" : 6, ”uid_1” "nYields" : 0, 6ms "nChunkSkips" : 0, 3 3 "isMultiKey" : false, "indexOnly" : false, "indexBounds" : { "uid" : [ [ "b3iVxMGIEc3xxxxY", "b3iVxMGIEc3xxxxY" ] ] }}
  14. 14. !   ! slowms !   ! db.setProfilingLevel(level,slowms) !  
  15. 15. slowms !   mongod slowms ms mongod mongod --logpath=/var/log/mongodb/mongodb.log --logappend –slowms 500 Sat May 14 02:25:53 [conn16] query logdb.$cmd ntoreturn:1command: { count: "logs", query: { path: "/index.html" }, fields: {} } reslen:64 3116ms
  16. 16. setProfilingLevel setProfilingLevel (level,slowms) > db.setProfilingLevel(1,500); { "was" : 1, "slowms" : 100, "ok" : 1 } 100ms
  17. 17. setProfilingLevel system.profile > db.system.profile.find();{ "ts" : ISODate("2011-05-01T03:40:04.462Z"), "info" : "query logdb.logs reslen:192nscanned:2669511 nquery: { uid: "b2kwyYCXn3b5Scpr" } nreturned:1 6686ms","millis" : 6686 } ts millis info query query query nscanned reslen nreturned
  18. 18. db.currentOp opid ID KillOp op query update ns query lockType waitingForLock client desc
  19. 19. > db.currentOp();{ "inprog" : [ { "opid" : 272, "active" : true, "lockType" : "read", "waitingForLock" : false, "secs_running" : 20, "op" : "query", "ns" : "logdb.logs", "query" : { "count" : "logs", "query" : { "month" : "2010/02" }, "fields" : { } }, "client" : "127.0.0.1:59394", "desc" : "conn" }]}
  20. 20. slowms db.setProfilingLevel collection system.profile capped collection db.currentOp MongoDB
  21. 21. Tips
  22. 22. !   • db.c.find( {x:10,y:20} ), using index {x:1,y:1} • db.c.find( {x:10,y:20} ), using index {x:1,y:-1} • db.c.find( {x:{$in:[10,20]},y:20} ), using index {x:1,y:1} • db.c.find().sort( {x:1,y:1} ), using index {x:1,y:1} • db.c.find().sort( {x:-1,y:1} ), using index {x:1,y:-1} • db.c.find( {x:10} ).sort( {y:1} ), using index {x: 1,y:1}
  23. 23. hint !   hint!  
  24. 24. hint > db.logs.find({uid:"f2RNwtj34m3xxxxB" , path : "/index.html"}).hint({uid:1}).explain();{ "cursor" : "BtreeCursor uid_1", "nscanned" : 95, "nscannedObjects" : 95, "n" : 35, "millis" : 3, "nYields" : 0, "nChunkSkips" : 0, "isMultiKey" : false, "indexOnly" : false, "indexBounds" : { "uid" : [ [ "f2RNwtj34m3xxxxB", "f2RNwtj34m3xxxxB" ] ] }}
  25. 25. hint > db.logs.find({uid:"f2RNwtj34m3xxxxB" , path : "/index.html"}).hint({uid:1 , path:1}).explain();{ "cursor" : "BtreeCursor uid_1_path_1", "nscanned" : 35, "nscannedObjects" : 35, "n" : 35, "millis" : 0, "nYields" : 0, "nChunkSkips" : 0, "isMultiKey" : false, "indexOnly" : false, "indexBounds" : { "uid" : [ [ "f2RNwtj34m3xxxxB", "f2RNwtj34m3xxxxB" ] ], ( ) }}
  26. 26. mongostat mongostat
  27. 27. mongostat inserts insert / query query / update update / delete delete / getmore getmore / command command / flushes fsync flush / mapped Map MB visze MB res MB faults / locked Idx miss qr|qw read | write ar|aw read | write netIn In bits netOut Out bits conn
  28. 28. collection !   getIndexKeys() > db.logs.getIndexKeys(); [ { "_id" : 1 }, { "uid" : 1 }, { "uid" : 1, "path" : 1 } ]
  29. 29. !   db.currentOp opid db.killOp(opid) > db.currentOp(); { "inprog" : [ { "opid" : 308, "active" : true, "lockType" : "read", "waitingForLock" : false, "secs_running" : 11, "op" : "query", "ns" : "logdb.logs", ( ) } ] } > db.killOp(308); { "info" : "attempting to kill op" }
  30. 30. !  !   !   explain!   !   slowms !   setProfilingLevel !   db.currentOP!   Tips !   !   Hint !   mongostat

×