SlideShare a Scribd company logo
1 of 34
Download to read offline
MongoDB                	
 
      id:matsuou1
!  

!  

!  

!  

!  

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

!                           MongoDB Hadoop R
1. 

2. 

3. 

4. 
!  


!   RDBMS


!  
!  


!  
MongoDB         	
 
!  
      !               CPU

!  



      !   JOIN

!  
• 

     •    100         insert update    delete
     • 
     •                nscanned        10


• 
db/queryoptimizer.cpp
!                                          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"
                 ]
           ]
     }
}
!  
      !     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

Operational Intelligence with MongoDB Webinar
Operational Intelligence with MongoDB WebinarOperational Intelligence with MongoDB Webinar
Operational Intelligence with MongoDB Webinar
MongoDB
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
Night Sailer
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
MongoDB
 
Optimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityOptimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and Creativity
MongoDB
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
kchodorow
 
MongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduceMongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduce
Takahiro Inoue
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
Sven Haiges
 

What's hot (20)

Mythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDBMythbusting: Understanding How We Measure the Performance of MongoDB
Mythbusting: Understanding How We Measure the Performance of MongoDB
 
Operational Intelligence with MongoDB Webinar
Operational Intelligence with MongoDB WebinarOperational Intelligence with MongoDB Webinar
Operational Intelligence with MongoDB Webinar
 
Elastic search 검색
Elastic search 검색Elastic search 검색
Elastic search 검색
 
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
 
Mongodb debugging-performance-problems
Mongodb debugging-performance-problemsMongodb debugging-performance-problems
Mongodb debugging-performance-problems
 
MongoDB-SESSION03
MongoDB-SESSION03MongoDB-SESSION03
MongoDB-SESSION03
 
MySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of ThingsMySQL flexible schema and JSON for Internet of Things
MySQL flexible schema and JSON for Internet of Things
 
MongoDB dla administratora
MongoDB dla administratora MongoDB dla administratora
MongoDB dla administratora
 
MongoDB - Aggregation Pipeline
MongoDB - Aggregation PipelineMongoDB - Aggregation Pipeline
MongoDB - Aggregation Pipeline
 
From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)From mysql to MongoDB(MongoDB2011北京交流会)
From mysql to MongoDB(MongoDB2011北京交流会)
 
Mongo db dla administratora
Mongo db dla administratoraMongo db dla administratora
Mongo db dla administratora
 
MongoDB Performance Tuning
MongoDB Performance TuningMongoDB Performance Tuning
MongoDB Performance Tuning
 
Optimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and CreativityOptimizing Slow Queries with Indexes and Creativity
Optimizing Slow Queries with Indexes and Creativity
 
San Francisco Java User Group
San Francisco Java User GroupSan Francisco Java User Group
San Francisco Java User Group
 
MongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduceMongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduce
 
PostgreSQLからMongoDBへ
PostgreSQLからMongoDBへPostgreSQLからMongoDBへ
PostgreSQLからMongoDBへ
 
Latinoware
LatinowareLatinoware
Latinoware
 
CouchDB on Android
CouchDB on AndroidCouchDB on Android
CouchDB on Android
 
Mongo db presentation
Mongo db presentationMongo db presentation
Mongo db presentation
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
 

Similar to 20110514 mongo dbチューニング

MongoDB: Intro & Application for Big Data
MongoDB: Intro & Application  for Big DataMongoDB: Intro & Application  for Big Data
MongoDB: Intro & Application for Big Data
Takahiro Inoue
 
Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...
Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...
Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...
Lucidworks
 
第一回MongoDBソースコードリーディング
第一回MongoDBソースコードリーディング第一回MongoDBソースコードリーディング
第一回MongoDBソースコードリーディング
nobu_k
 
Riak Meetup Stockholm 1/11/2012
Riak Meetup Stockholm 1/11/2012Riak Meetup Stockholm 1/11/2012
Riak Meetup Stockholm 1/11/2012
Bip Thelin
 
Shell Tips & Tricks
Shell Tips & TricksShell Tips & Tricks
Shell Tips & Tricks
MongoDB
 

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

Mongo scaling
Mongo scalingMongo scaling
Mongo scaling
 
Running Production MongoDB Lightning Talk
Running Production MongoDB Lightning TalkRunning Production MongoDB Lightning Talk
Running Production MongoDB Lightning Talk
 
MongoDB Live Hacking
MongoDB Live HackingMongoDB Live Hacking
MongoDB Live Hacking
 
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB PerformanceMongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB Europe 2016 - Debugging MongoDB Performance
 
MongoDB + node.js で作るソーシャルゲーム
MongoDB + node.js で作るソーシャルゲームMongoDB + node.js で作るソーシャルゲーム
MongoDB + node.js で作るソーシャルゲーム
 
MongoDB: Intro & Application for Big Data
MongoDB: Intro & Application  for Big DataMongoDB: Intro & Application  for Big Data
MongoDB: Intro & Application for Big Data
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
 
Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...
Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...
Distributed Search in Riak - Integrating Search in a NoSQL Database: Presente...
 
rsyslog v8: more than just syslog!
rsyslog v8: more than just syslog!rsyslog v8: more than just syslog!
rsyslog v8: more than just syslog!
 
MongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB Days Silicon Valley: MongoDB and the Hadoop ConnectorMongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
MongoDB Days Silicon Valley: MongoDB and the Hadoop Connector
 
MongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and MergingMongoDB Chunks - Distribution, Splitting, and Merging
MongoDB Chunks - Distribution, Splitting, and Merging
 
第一回MongoDBソースコードリーディング
第一回MongoDBソースコードリーディング第一回MongoDBソースコードリーディング
第一回MongoDBソースコードリーディング
 
Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1Elastic Search Training#1 (brief tutorial)-ESCC#1
Elastic Search Training#1 (brief tutorial)-ESCC#1
 
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
 
Riak Meetup Stockholm 1/11/2012
Riak Meetup Stockholm 1/11/2012Riak Meetup Stockholm 1/11/2012
Riak Meetup Stockholm 1/11/2012
 
10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators  10 Key MongoDB Performance Indicators
10 Key MongoDB Performance Indicators
 
Apache CouchDB Presentation @ Sept. 2104 GTALUG Meeting
Apache CouchDB Presentation @ Sept. 2104 GTALUG MeetingApache CouchDB Presentation @ Sept. 2104 GTALUG Meeting
Apache CouchDB Presentation @ Sept. 2104 GTALUG Meeting
 
Shell Tips & Tricks
Shell Tips & TricksShell Tips & Tricks
Shell Tips & Tricks
 

Recently uploaded

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
Enterprise Knowledge
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
Earley Information Science
 

Recently uploaded (20)

IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdfThe Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
The Role of Taxonomy and Ontology in Semantic Layers - Heather Hedden.pdf
 
Evaluating the top large language models.pdf
Evaluating the top large language models.pdfEvaluating the top large language models.pdf
Evaluating the top large language models.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 

20110514 mongo dbチューニング

  • 1. MongoDB id:matsuou1
  • 2. !   !   !   !   !   !   Tips !  
  • 3. !   ID matsuou1 !   !   !   !   !   Oracle PostgreSQL !   MongoDB Hadoop R
  • 5.
  • 6. !   !   RDBMS !  
  • 8. MongoDB !   !   CPU !   !   JOIN !  
  • 9. •  •  100 insert update delete •  •  nscanned 10 • 
  • 11.
  • 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" ] ] } }
  • 16.
  • 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