SlideShare a Scribd company logo
MongoDB                	
 
      id:matsuou1
!  

!  

!  

!  

!  

!           Tips
!  
!   ID      matsuou1
!                 	
                 	
 
!  
      !  
      !  
      !      Oracle     PostgreSQL

!                           MongoDB Hadoop R
1. 

2. 

3. 

4. 
20110514 mongo dbチューニング
!  


!   RDBMS


!  
!  


!  
MongoDB         	
 
!  
      !               CPU

!  



      !   JOIN

!  
• 

     •    100         insert update    delete
     • 
     •                nscanned        10


• 
db/queryoptimizer.cpp
20110514 mongo dbチューニング
!                                          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" : {

               }
      }
cursor	
             BasicCursor	
                   	
 
                                       BasicCursor or BtreeCursor 	
 
nscanned	
           14
                                               	
 
nscannedObjects	
    14	
                                                 	
 
n	
                  14	
                            	
 
millis	
             9	
                                         ms 	
 
nYields	
            0
nChunkSkips	
        0	
              Chunk
                                                           	
 
isMultiKey	
         false	
 
indexOnly	
          false	
 
indexBounds	
 
scanAndOrder	
 
allPlans
(                                       )	
 
> 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" : {

          }
}
(                                      )	
 
> 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"
                 ]
           ]
     }
}
20110514 mongo dbチューニング
!  
      !     slowms
      !  
            ! db.setProfilingLevel(level,slowms)
      !  
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:1
command: { count: "logs", query: { path: "/index.html" }, fields: {} } reslen:64 3116ms
setProfilingLevel	
 
                                                    setProfilingLevel
     (level,slowms)                           	
 

	
  > db.setProfilingLevel(1,500);
  { "was" : 1, "slowms" : 100, "ok" : 1 }	


          	
                   	
 
    	
 
    	
                                                  100ms
setProfilingLevel	
 
              system.profile                                                            	
 

> db.system.profile.find();
{ "ts" : ISODate("2011-05-01T03:40:04.462Z"), "info" : "query logdb.logs reslen:192
nscanned:2669511 nquery: { uid: "b2kwyYCXn3b5Scpr" } nreturned:1 6686ms",
"millis" : 6686 }	

        	
                                    	
 
ts	
                                                      	
 
millis	
                                                        	
 
info	
 
                query	
 
                           query	
        query     	
 
                           nscanned	
                                       	
 
                           reslen	
                                   	
 
                           nreturned
db.currentOp                                                 	
 


        	
          	
 
opid	
                      ID    KillOp         	
 
op	
                      query   update   	
 
ns	
                                                               	
 
query	
 
lockType	
 
waitingForLock	
 
client	
 
desc
> 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"
                          }]}
slowms	
 
                                       	
 



db.setProfilingLevel	
    collection         system.profile   capped collection


                                 	
                                      	
 
db.currentOp	
                                                           	
 


                                       	
 




   MongoDB
Tips
!                                                                    	
 
  • 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}
hint	
 
!   hint


!  
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"
                                 ]
                       ]
           }
}
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"
                                 ]
                       ],
           ( )
           }
}
mongostat	
 
      mongostat
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
collection                                                   	
 
!   getIndexKeys()
                                     	
 

 > db.logs.getIndexKeys();
 [ { "_id" : 1 }, { "uid" : 1 }, { "uid" : 1, "path" : 1 } ]
!   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" }
!  

!  
      !   explain

!  
      !   slowms
      !   setProfilingLevel
      !   db.currentOP

!                     Tips
      !  
      !   Hint
      !   mongostat
20110514 mongo dbチューニング

More Related Content

What's hot (20)

PPTX
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
PPTX
Operational Intelligence with MongoDB Webinar
MongoDB
 
PDF
Elastic search 검색
HyeonSeok Choi
 
PDF
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB
 
PDF
Mongodb debugging-performance-problems
MongoDB
 
PPTX
MongoDB-SESSION03
Jainul Musani
 
PDF
MySQL flexible schema and JSON for Internet of Things
Alexander Rubin
 
PDF
MongoDB dla administratora
3camp
 
PPTX
MongoDB - Aggregation Pipeline
Jason Terpko
 
PDF
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
ODP
Mongo db dla administratora
Łukasz Jagiełło
 
PDF
MongoDB Performance Tuning
MongoDB
 
PDF
Optimizing Slow Queries with Indexes and Creativity
MongoDB
 
PDF
San Francisco Java User Group
kchodorow
 
PDF
MongoDB: Replication,Sharding,MapReduce
Takahiro Inoue
 
KEY
PostgreSQLからMongoDBへ
Basuke Suzuki
 
PDF
Latinoware
kchodorow
 
KEY
CouchDB on Android
Sven Haiges
 
KEY
Mongo db presentation
Julie Sommerville
 
PDF
MongoDB: Optimising for Performance, Scale & Analytics
Server Density
 
Mythbusting: Understanding How We Measure the Performance of MongoDB
MongoDB
 
Operational Intelligence with MongoDB Webinar
MongoDB
 
Elastic search 검색
HyeonSeok Choi
 
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB
 
Mongodb debugging-performance-problems
MongoDB
 
MongoDB-SESSION03
Jainul Musani
 
MySQL flexible schema and JSON for Internet of Things
Alexander Rubin
 
MongoDB dla administratora
3camp
 
MongoDB - Aggregation Pipeline
Jason Terpko
 
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
Mongo db dla administratora
Łukasz Jagiełło
 
MongoDB Performance Tuning
MongoDB
 
Optimizing Slow Queries with Indexes and Creativity
MongoDB
 
San Francisco Java User Group
kchodorow
 
MongoDB: Replication,Sharding,MapReduce
Takahiro Inoue
 
PostgreSQLからMongoDBへ
Basuke Suzuki
 
Latinoware
kchodorow
 
CouchDB on Android
Sven Haiges
 
Mongo db presentation
Julie Sommerville
 
MongoDB: Optimising for Performance, Scale & Analytics
Server Density
 

Similar to 20110514 mongo dbチューニング (20)

KEY
Mongo scaling
Simon Maynard
 
PDF
FrozenRails Training
Mike Dirolf
 
PDF
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB
 
PPTX
MongoDB's index and query optimize
mysqlops
 
PPTX
Indexing and Query Optimizer (Aaron Staple)
MongoSF
 
PPTX
Indexing with MongoDB
MongoDB
 
PDF
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
MongoSF
 
PPTX
Performance Tuning and Optimization
MongoDB
 
KEY
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
Daniel Cousineau
 
PPTX
Indexing Strategies to Help You Scale
MongoDB
 
PPTX
Mongodb introduction and_internal(simple)
Kai Zhao
 
KEY
MongoDB Best Practices in AWS
Chris Harris
 
PDF
Mongo db improve the performance of your application codemotion2016
Juan Antonio Roy Couto
 
PPTX
Running Production MongoDB Lightning Talk
chrisckchang
 
PDF
MongoDB With Style
Gabriele Lana
 
PDF
MongoDB Days UK: Indexing and Performance Tuning
MongoDB
 
PDF
Mongodb in-anger-boston-rb-2011
bostonrb
 
KEY
2012 phoenix mug
Paul Pedersen
 
PPTX
Automated Slow Query Analysis: Dex the Index Robot
MongoDB
 
PDF
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
Mydbops
 
Mongo scaling
Simon Maynard
 
FrozenRails Training
Mike Dirolf
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB
 
MongoDB's index and query optimize
mysqlops
 
Indexing and Query Optimizer (Aaron Staple)
MongoSF
 
Indexing with MongoDB
MongoDB
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
MongoSF
 
Performance Tuning and Optimization
MongoDB
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
Daniel Cousineau
 
Indexing Strategies to Help You Scale
MongoDB
 
Mongodb introduction and_internal(simple)
Kai Zhao
 
MongoDB Best Practices in AWS
Chris Harris
 
Mongo db improve the performance of your application codemotion2016
Juan Antonio Roy Couto
 
Running Production MongoDB Lightning Talk
chrisckchang
 
MongoDB With Style
Gabriele Lana
 
MongoDB Days UK: Indexing and Performance Tuning
MongoDB
 
Mongodb in-anger-boston-rb-2011
bostonrb
 
2012 phoenix mug
Paul Pedersen
 
Automated Slow Query Analysis: Dex the Index Robot
MongoDB
 
Use Performance Insights To Enhance MongoDB Performance - (Manosh Malai - Myd...
Mydbops
 
Ad

Recently uploaded (20)

PPTX
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
PDF
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
PDF
Blockchain Transactions Explained For Everyone
CIFDAQ
 
PDF
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
PDF
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
PDF
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
PDF
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
PDF
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
PDF
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
PDF
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
PDF
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
PDF
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
PDF
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
PDF
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
PPTX
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
PDF
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
PDF
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
PDF
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
PDF
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
PDF
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
MSP360 Backup Scheduling and Retention Best Practices.pptx
MSP360
 
Jak MŚP w Europie Środkowo-Wschodniej odnajdują się w świecie AI
dominikamizerska1
 
Blockchain Transactions Explained For Everyone
CIFDAQ
 
Smart Trailers 2025 Update with History and Overview
Paul Menig
 
CIFDAQ Token Spotlight for 9th July 2025
CIFDAQ
 
Windsurf Meetup Ottawa 2025-07-12 - Planning Mode at Reliza.pdf
Pavel Shukhman
 
How Startups Are Growing Faster with App Developers in Australia.pdf
India App Developer
 
NewMind AI Journal - Weekly Chronicles - July'25 Week II
NewMind AI
 
Wojciech Ciemski for Top Cyber News MAGAZINE. June 2025
Dr. Ludmila Morozova-Buss
 
Building Real-Time Digital Twins with IBM Maximo & ArcGIS Indoors
Safe Software
 
Persuasive AI: risks and opportunities in the age of digital debate
Speck&Tech
 
Empower Inclusion Through Accessible Java Applications
Ana-Maria Mihalceanu
 
NewMind AI - Journal 100 Insights After The 100th Issue
NewMind AI
 
Impact of IEEE Computer Society in Advancing Emerging Technologies including ...
Hironori Washizaki
 
Top iOS App Development Company in the USA for Innovative Apps
SynapseIndia
 
Chris Elwell Woburn, MA - Passionate About IT Innovation
Chris Elwell Woburn, MA
 
Predicting the unpredictable: re-engineering recommendation algorithms for fr...
Speck&Tech
 
HCIP-Data Center Facility Deployment V2.0 Training Material (Without Remarks ...
mcastillo49
 
LLMs.txt: Easily Control How AI Crawls Your Site
Keploy
 
Exolore The Essential AI Tools in 2025.pdf
Srinivasan M
 
Ad

20110514 mongo dbチューニング

  • 1. MongoDB id:matsuou1
  • 2. !   !   !   !   !   !   Tips !  
  • 3. !   ID matsuou1 !   !   !   !   !   Oracle PostgreSQL !   MongoDB Hadoop R
  • 6. !   !   RDBMS !  
  • 8. MongoDB !   !   CPU !   !   JOIN !  
  • 9. •  •  100 insert update delete •  •  nscanned 10 • 
  • 12. !   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" : { } }
  • 13. cursor BasicCursor BasicCursor or BtreeCursor nscanned 14 nscannedObjects 14 n 14 millis 9 ms nYields 0 nChunkSkips 0 Chunk isMultiKey false indexOnly false indexBounds scanAndOrder allPlans
  • 14. ( ) > 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" : { } }
  • 15. ( ) > 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" ] ] } }
  • 17. !   ! slowms !   ! db.setProfilingLevel(level,slowms) !  
  • 18. 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:1 command: { count: "logs", query: { path: "/index.html" }, fields: {} } reslen:64 3116ms
  • 19. setProfilingLevel setProfilingLevel (level,slowms) > db.setProfilingLevel(1,500); { "was" : 1, "slowms" : 100, "ok" : 1 } 100ms
  • 20. setProfilingLevel system.profile > db.system.profile.find(); { "ts" : ISODate("2011-05-01T03:40:04.462Z"), "info" : "query logdb.logs reslen:192 nscanned:2669511 nquery: { uid: "b2kwyYCXn3b5Scpr" } nreturned:1 6686ms", "millis" : 6686 } ts millis info query query query nscanned reslen nreturned
  • 21. db.currentOp opid ID KillOp op query update ns query lockType waitingForLock client desc
  • 22. > 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" }]}
  • 23. slowms db.setProfilingLevel collection system.profile capped collection db.currentOp MongoDB
  • 24. Tips
  • 25. !   • 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}
  • 26. hint !   hint !  
  • 27. 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" ] ] } }
  • 28. 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" ] ], ( ) } }
  • 29. mongostat mongostat
  • 30. 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
  • 31. collection !   getIndexKeys() > db.logs.getIndexKeys(); [ { "_id" : 1 }, { "uid" : 1 }, { "uid" : 1, "path" : 1 } ]
  • 32. !   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" }
  • 33. !   !   !   explain !   !   slowms !   setProfilingLevel !   db.currentOP !   Tips !   !   Hint !   mongostat