SlideShare ist ein Scribd-Unternehmen logo
1 von 71
–                                 – 	

MongoDB                      
      	

  5   MongoDB          	

           (@nsega)	

      GCREST, Inc.
•                  (Age:28) (twitter: @nsega)	

•           	

     •                            	

     •                                        	

     •                                                      
                        (   SNS                      )	


•                                       	

     •    JavaEE
Agenda	

•                                        	

•  MongoDB                   	

•              	

•                                  	

•                          	

•                    	

• 
?
?	


                        -@games-	

      http://www.atgames.jp/	


                  290
MongoDB
MongoDB                                                 	

    SNS                                                       	

              
                                                  
(         )
•                  
     	

•          MySQL         	

• 
•          	

• 
MongoDB               	

•         
                	

•                           	



NoSQL
MongoDB                          	

l  NoSQL              MongoDB         

l  MongoDB JP
MongoDB
(   SNS          )	

•  Linux/CentOS v5.4 	

•  Apache v2.2.14	

•  MySQL v5.5(InnoDB)	

•  PostgreSQL v9.0.1	

•  MongoDB v1.8.2-rc3 NEW!!	

•  PHP v5.2 / symfony v1.2.9
  (MongoDriver/mongo.so) NEW!!
15 (Web/PC )
 3 (Web/Mobile )
 mongos                                    	


5 (MySQL)	

 1   :Master / 3 :Slave/ 1 :
3 (MongoDB) NEW!!	

•  CPU:Intel(R) Xeon(R) 2.13GHz 8core	

•  Memory:16GB 	

•  HDD: 550GB
   (xfs 400GB/mongo        )
Web Server	

                                       x 18 (PC/MB)
                          mongos	


Server1                Server2                   Server3
    CONFIG	

            CONFIG	

          CONFIG	


                          Sharding
   PRIMARY	

             PRIMARY	

        PRIMARY	

          ReplicaSet     ReplicaSet       ReplicaSet
 SECONDARY	

           SECONDARY	

      SECONDARY
MongoDB DataAccess
MongoDB                                       	

                                                     	

  (   ) (         ) (         )
l Shard Key         
    (      ID(    )) mod 100
    md       Shard Key            
	

l 100         (0~99) 3         Shard
l Chunk            (split             )
 /usr/local/mongodb/bin/mongo localhost/admin;	


db.runCommand({split:sns.footprints,middle:{md:0}});	

db.runCommand({split:sns.footprints,middle:{md:1}});
     :	

db.runCommand({split:sns.footprints,middle:{md:98}});	

db.runCommand({split:sns.footprints,middle:{md:99}});
l Chunk           (moveChunk                     )
db.runCommand({moveChunk:sns.footprints,
                  find:{md:0},to:”mongo01});	

db.runCommand({moveChunk:sns.footprints,
                  find:{md:1},to:”mongo02});
   :	

db.runCommand({moveChunk:sns.footprints,
                  find:{md:98},to:”mongo03});	

db.runCommand({moveChunk:sns.footprints,
                  find:{md:99},to:”mongo01});
MongoDB DataAccess
             	



•  Symfony(PHP) + MongoDB 	

• 
MongoDB DataAccess
                	


               Class MogoKeyValue    MongoDB         


Class                       Class 
DiaryEvalMongoKeyVale       FootprintsMongoKeyVale



     DAO
•          explain 
     	

• 
db.footprints.findOne();
{
_id : ObjectId(4e0967ac6978a9cf03000027),
md : 73,
                                                        	

fromId : 5439901,        md/           ID mod 100 	

toId” : 5484473,          fromId/ ID	

date : 1106281433,       toId/ ID	

                           date/       (YYMMDDHH24MISS)
”dataType : 0             dateType/
}
 db.footprints.count();                     (                )	

30282                                            30,000
explain                      	

db.footprints.find({fromId:5439901,”dateType:{$gt:0}})	

Ø  .sort({date:-1}).explain();	

{	

cursor : BasicCursor,	

         INDEX
nscanned : 30178,	

nscannedObjects : 30178,	

n : 54,	

scanAndOrder : true,	

millis : 31,	

nYields : 0,	

                                        	

nChunkSkips : 0,	

isMultiKey : false,	

indexOnly : false,	

indexBounds : {	

             }	

}
INDEX                                 	

 db.footprints.ensureIndex({fromId:1,dataType:1,date:-1});	

 db.footprints.getIndexes();
[	

           :	

                                          wkwk
     	

{	

     	

 	

_id : ObjectId(4e2c5aff4ab228594428620c),	

     	

 	

ns : sns.footprints,	

     	

 	

key : {	

     	

 	

 	

fromId : 1,	

     	

 	

 	

”dataType : 1,	

      INDEX
     	

 	

 	

date : -1	

     	

 	

},	

     	

 	

name : fromId_1_dataType_1_date_-1,	

     	

 	

v : 0	

     	

}	

]
explain
db.footprints.find({fr:5439901,ty:{$gt:0}}).sort({dt:-1}).explain();
{
cursor : BtreeCursor fromId_1_dataType_1_date_-1,
nscanned : 54,
nscannedObjects : 54,                                 INDEX 	

n : 54,
scanAndOrder : true,
millis : 1,
nYields : 0,                                       	

nChunkSkips : 0,
isMultiKey : false,                                          	

indexOnly : false,              (             )
indexBounds : {
:
AP
     DB
orz	

•  MongoDB                              	

•  PHP
db.diaryeval.findOne();	

{	

     	

_id : ObjectId(4e2afdc86978a9bb76000000),	

      md : 32,	

     	

diaryId : 2224,	

     	

fromId : 5472732,	

                                      	

     	

toId : 5439901,	

              md/ fromId mod 100
     	

”dataType : 1,	

                                          diaryId/ DiaryID	

     	

date : 2011/07/24 01:58:48	

}	

                                      fromId/         ID	

                                          toId/        ID	

                                          dateType/            	

                                          date/
                                               (YYYY/MM/DD HH24:MI:SS)
NG   OK   /
(   Д )   !!
DB
                 	


          



(perl)
DB
                    	

            perl          	





2011/6/24
DB
                                                    	





db.footprints.find({”dataType:0,date:{$lt:110624000000}})
 .count();
359832                                36
DB
                                                	


perl remove.ashiato.over.one.month.pl	

[2011-06-24 14:28:45] TARGET  110624	

[2011-06-24 14:28:45] END $VAR1 = 1;


              36                               	

                                        !
DB
                                                    	

                                         	

db.footprints.find({”dataType:0,date:{$lt:110624000000}})
 .count();
359832

                                                    orz
DB
                                                      	

              (   ´    ) (´        )(           )(          )



db.footprints.find({”dataType:0,date:{$lt:110624000000}})
 .count();
 0
                                              DB                
                                          (        )
/ (     )
mongod
mongod                           	


         mongod(primary)
mongod                       	

   	

     :	





[conn38666] JS Error: out of memory
mongod                             	


l             mongod            AP
                        accept             
	

l         AP MongoDB

	

l 
server1 mongod(PRIMARY)

ReplicaSet                 SECONDARY	

     PRIMARY


        (      д )
SECONDARY




  [rs Manager] replSet can't see a majority, will not try to elect self

 elect
mongo1
                            	

         mongo1




                  server2
                                  SECONDARY
mongo1

         mongo1




                  server1         priority
                                                      
                  server2         (default   01)
ReplicaSet SECONDARY
priority            1
              PRIMARY 
                	

SECONDARY
                        (*´   )
           ( д lll)      (        )
(           )
slowms
                                  	


/usr/local/mongodb/bin/mongod --slowms 500 
--logpath /var/log/mongodb/data.log 	

	

500ms
Fri Jul 22 15:48:24 [conn171] query sns.$cmd ntoreturn:
1 command: { count: footprints,
   query: { toId:       , $where: this.dataType  0 } } reslen:64 607ms
	

Fri Jul 22 17:53:00 [conn33887] query sns.$cmd ntoreturn:
1 command: { count: footprints,
   query: { toId:       , $where: this.dataType  0 } } reslen:64 527ms	


                                               	

                                               ( `д ´)
printShardingSizes()
                             	

      2    1           moveChunk()
printShardingSizes()

                                                    	




       	
7/26        (7/5)           3

            2GB
l 
                       
	

l MongoDB       
                                   
	

l           Map/Reduce
MongoDB

group                       Map/Reduce 	

                                       	

	

http://www.mongodb.org/pages/viewpage.action?pageId=6750296
• RDBMS                       
          	

•                                               
                	

• 
(   )
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例

Weitere ähnliche Inhalte

Was ist angesagt?

MongoDB Performance Debugging
MongoDB Performance DebuggingMongoDB Performance Debugging
MongoDB Performance Debugging
MongoDB
 
How Signpost uses MongoDB for Tracking and Analytics
How Signpost uses MongoDB for Tracking and AnalyticsHow Signpost uses MongoDB for Tracking and Analytics
How Signpost uses MongoDB for Tracking and Analytics
mattinsler
 
Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDB
Jeff Yemin
 
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
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
MongoDB
 

Was ist angesagt? (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
 
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
 
2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB2011 Mongo FR - Indexing in MongoDB
2011 Mongo FR - Indexing in MongoDB
 
MongoDB Performance Debugging
MongoDB Performance DebuggingMongoDB Performance Debugging
MongoDB Performance Debugging
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
Mongodb index 讀書心得
Mongodb index 讀書心得Mongodb index 讀書心得
Mongodb index 讀書心得
 
How Signpost uses MongoDB for Tracking and Analytics
How Signpost uses MongoDB for Tracking and AnalyticsHow Signpost uses MongoDB for Tracking and Analytics
How Signpost uses MongoDB for Tracking and Analytics
 
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!
 
Ajax cheat sheet
Ajax cheat sheetAjax cheat sheet
Ajax cheat sheet
 
Reducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQLReducing Development Time with MongoDB vs. SQL
Reducing Development Time with MongoDB vs. SQL
 
The rise of json in rdbms land jab17
The rise of json in rdbms land jab17The rise of json in rdbms land jab17
The rise of json in rdbms land jab17
 
Building Apps with MongoDB
Building Apps with MongoDBBuilding Apps with MongoDB
Building Apps with MongoDB
 
Morphia: Simplifying Persistence for Java and MongoDB
Morphia:  Simplifying Persistence for Java and MongoDBMorphia:  Simplifying Persistence for Java and MongoDB
Morphia: Simplifying Persistence for Java and MongoDB
 
Mongo or Die: How MongoDB Powers Doodle or Die
Mongo or Die: How MongoDB Powers Doodle or DieMongo or Die: How MongoDB Powers Doodle or Die
Mongo or Die: How MongoDB Powers Doodle or Die
 
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
 
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDB
 
Mining legal texts with Python
Mining legal texts with PythonMining legal texts with Python
Mining legal texts with Python
 
Java Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDBJava Persistence Frameworks for MongoDB
Java Persistence Frameworks for MongoDB
 
Mongodb debugging-performance-problems
Mongodb debugging-performance-problemsMongodb debugging-performance-problems
Mongodb debugging-performance-problems
 

Ähnlich wie ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例

Social Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDBSocial Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDB
Takahiro Inoue
 
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
 

Ähnlich wie ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例 (20)

Mongo db dla administratora
Mongo db dla administratoraMongo db dla administratora
Mongo db dla administratora
 
Social Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDBSocial Data and Log Analysis Using MongoDB
Social Data and Log Analysis Using MongoDB
 
MongoDB dla administratora
MongoDB dla administratora MongoDB dla administratora
MongoDB dla administratora
 
MongoDB Basics Unileon
MongoDB Basics UnileonMongoDB Basics Unileon
MongoDB Basics Unileon
 
MongoDB at ZPUGDC
MongoDB at ZPUGDCMongoDB at ZPUGDC
MongoDB at ZPUGDC
 
mongodb tutorial
mongodb tutorialmongodb tutorial
mongodb tutorial
 
MongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overviewMongoDB: a gentle, friendly overview
MongoDB: a gentle, friendly overview
 
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...
 
MongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & AnalyticsMongoDB: Optimising for Performance, Scale & Analytics
MongoDB: Optimising for Performance, Scale & Analytics
 
Mongo scaling
Mongo scalingMongo scaling
Mongo scaling
 
视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)视觉中国的MongoDB应用实践(QConBeijing2011)
视觉中国的MongoDB应用实践(QConBeijing2011)
 
PostgreSQLからMongoDBへ
PostgreSQLからMongoDBへPostgreSQLからMongoDBへ
PostgreSQLからMongoDBへ
 
MongoDB: Intro & Application for Big Data
MongoDB: Intro & Application  for Big DataMongoDB: Intro & Application  for Big Data
MongoDB: Intro & Application for Big Data
 
MongoDB at Scale
MongoDB at ScaleMongoDB at Scale
MongoDB at Scale
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDB
 
MongoDB.pdf
MongoDB.pdfMongoDB.pdf
MongoDB.pdf
 
Streaming Data Pipelines with MongoDB and Kafka at ao.com
Streaming Data Pipelines with MongoDB and Kafka at ao.comStreaming Data Pipelines with MongoDB and Kafka at ao.com
Streaming Data Pipelines with MongoDB and Kafka at ao.com
 
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
 
How to use MongoDB with CakePHP
How to use MongoDB with CakePHPHow to use MongoDB with CakePHP
How to use MongoDB with CakePHP
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRails
 

Kürzlich hochgeladen

Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
vu2urc
 

Kürzlich hochgeladen (20)

Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
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...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
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
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Histor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slideHistor y of HAM Radio presentation slide
Histor y of HAM Radio presentation slide
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.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
 
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
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
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
 

ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例

  • 1. – MongoDB 5 MongoDB (@nsega) GCREST, Inc.
  • 2. •  (Age:28) (twitter: @nsega) •  •  •  •  ( SNS ) •  •  JavaEE
  • 3. Agenda •  •  MongoDB •  •  •  •  • 
  • 4. ?
  • 5. ? -@games- http://www.atgames.jp/ 290
  • 7. MongoDB SNS ( )
  • 8. •  •  MySQL • 
  • 9. •  • 
  • 10.
  • 11. MongoDB •  •  NoSQL
  • 12. MongoDB l  NoSQL MongoDB l  MongoDB JP
  • 13.
  • 14.
  • 16.
  • 17. ( SNS ) •  Linux/CentOS v5.4 •  Apache v2.2.14 •  MySQL v5.5(InnoDB) •  PostgreSQL v9.0.1 •  MongoDB v1.8.2-rc3 NEW!! •  PHP v5.2 / symfony v1.2.9 (MongoDriver/mongo.so) NEW!!
  • 18. 15 (Web/PC ) 3 (Web/Mobile ) mongos 5 (MySQL) 1 :Master / 3 :Slave/ 1 :
  • 19. 3 (MongoDB) NEW!! •  CPU:Intel(R) Xeon(R) 2.13GHz 8core •  Memory:16GB •  HDD: 550GB (xfs 400GB/mongo )
  • 20. Web Server x 18 (PC/MB) mongos Server1 Server2 Server3 CONFIG CONFIG CONFIG Sharding PRIMARY PRIMARY PRIMARY ReplicaSet ReplicaSet ReplicaSet SECONDARY SECONDARY SECONDARY
  • 21.
  • 23. MongoDB ( ) ( ) ( )
  • 24. l Shard Key ( ID( )) mod 100 md Shard Key l 100 (0~99) 3 Shard
  • 25. l Chunk (split ) /usr/local/mongodb/bin/mongo localhost/admin; db.runCommand({split:sns.footprints,middle:{md:0}}); db.runCommand({split:sns.footprints,middle:{md:1}}); : db.runCommand({split:sns.footprints,middle:{md:98}}); db.runCommand({split:sns.footprints,middle:{md:99}});
  • 26. l Chunk (moveChunk ) db.runCommand({moveChunk:sns.footprints, find:{md:0},to:”mongo01}); db.runCommand({moveChunk:sns.footprints, find:{md:1},to:”mongo02}); : db.runCommand({moveChunk:sns.footprints, find:{md:98},to:”mongo03}); db.runCommand({moveChunk:sns.footprints, find:{md:99},to:”mongo01});
  • 27. MongoDB DataAccess •  Symfony(PHP) + MongoDB • 
  • 28. MongoDB DataAccess Class MogoKeyValue MongoDB Class Class DiaryEvalMongoKeyVale FootprintsMongoKeyVale DAO
  • 29. •  explain • 
  • 30. db.footprints.findOne(); { _id : ObjectId(4e0967ac6978a9cf03000027), md : 73, fromId : 5439901, md/ ID mod 100 toId” : 5484473, fromId/ ID date : 1106281433, toId/ ID date/ (YYMMDDHH24MISS) ”dataType : 0 dateType/ } db.footprints.count(); ( ) 30282 30,000
  • 31. explain db.footprints.find({fromId:5439901,”dateType:{$gt:0}}) Ø  .sort({date:-1}).explain(); { cursor : BasicCursor, INDEX nscanned : 30178, nscannedObjects : 30178, n : 54, scanAndOrder : true, millis : 31, nYields : 0, nChunkSkips : 0, isMultiKey : false, indexOnly : false, indexBounds : { } }
  • 32. INDEX db.footprints.ensureIndex({fromId:1,dataType:1,date:-1}); db.footprints.getIndexes(); [ : wkwk { _id : ObjectId(4e2c5aff4ab228594428620c), ns : sns.footprints, key : { fromId : 1, ”dataType : 1, INDEX date : -1 }, name : fromId_1_dataType_1_date_-1, v : 0 } ]
  • 33. explain db.footprints.find({fr:5439901,ty:{$gt:0}}).sort({dt:-1}).explain(); { cursor : BtreeCursor fromId_1_dataType_1_date_-1, nscanned : 54, nscannedObjects : 54, INDEX n : 54, scanAndOrder : true, millis : 1, nYields : 0, nChunkSkips : 0, isMultiKey : false, indexOnly : false, ( ) indexBounds : { :
  • 34.
  • 35. AP DB
  • 36. orz •  MongoDB •  PHP
  • 37. db.diaryeval.findOne(); { _id : ObjectId(4e2afdc86978a9bb76000000), md : 32, diaryId : 2224, fromId : 5472732, toId : 5439901, md/ fromId mod 100 ”dataType : 1, diaryId/ DiaryID date : 2011/07/24 01:58:48 } fromId/ ID toId/ ID dateType/ date/ (YYYY/MM/DD HH24:MI:SS)
  • 38. NG OK /
  • 39. ( Д ) !!
  • 40. DB (perl)
  • 41. DB perl 2011/6/24
  • 42. DB db.footprints.find({”dataType:0,date:{$lt:110624000000}}) .count(); 359832 36
  • 43. DB perl remove.ashiato.over.one.month.pl [2011-06-24 14:28:45] TARGET 110624 [2011-06-24 14:28:45] END $VAR1 = 1; 36 !
  • 44. DB db.footprints.find({”dataType:0,date:{$lt:110624000000}}) .count(); 359832 orz
  • 45. DB ( ´ ) (´ )( )( ) db.footprints.find({”dataType:0,date:{$lt:110624000000}}) .count(); 0 DB ( )
  • 46. / ( )
  • 48. mongod mongod(primary)
  • 49. mongod : [conn38666] JS Error: out of memory
  • 50. mongod l  mongod AP accept l  AP MongoDB l 
  • 51. server1 mongod(PRIMARY) ReplicaSet SECONDARY PRIMARY ( д )
  • 52. SECONDARY [rs Manager] replSet can't see a majority, will not try to elect self elect
  • 53. mongo1 mongo1 server2 SECONDARY
  • 54. mongo1 mongo1 server1 priority server2 (default 01)
  • 55. ReplicaSet SECONDARY priority 1 PRIMARY SECONDARY (*´ ) ( д lll) ( )
  • 56. ( )
  • 57. slowms /usr/local/mongodb/bin/mongod --slowms 500 --logpath /var/log/mongodb/data.log 500ms
  • 58. Fri Jul 22 15:48:24 [conn171] query sns.$cmd ntoreturn: 1 command: { count: footprints, query: { toId: , $where: this.dataType 0 } } reslen:64 607ms Fri Jul 22 17:53:00 [conn33887] query sns.$cmd ntoreturn: 1 command: { count: footprints, query: { toId: , $where: this.dataType 0 } } reslen:64 527ms ( `д ´)
  • 59. printShardingSizes() 2 1 moveChunk()
  • 60. printShardingSizes() 7/26 (7/5) 3 2GB
  • 61.
  • 62. l  l MongoDB l  Map/Reduce
  • 63. MongoDB group Map/Reduce http://www.mongodb.org/pages/viewpage.action?pageId=6750296
  • 64.
  • 65. • RDBMS •  • 
  • 66.
  • 67. ( )