SlideShare a Scribd company logo
–                                 – 	

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導入事例
MongoDB               	

•         
                	

•                           	



NoSQL
MongoDB                          	

l  NoSQL              MongoDB         

l  MongoDB JP
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
MongoDB
ココロもつながるオンラインゲーム–アットゲームズ–の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導入事例
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 : {
:
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
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
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
l 
                       
	

l MongoDB       
                                   
	

l           Map/Reduce
MongoDB

group                       Map/Reduce 	

                                       	

	

http://www.mongodb.org/pages/viewpage.action?pageId=6750296
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
• RDBMS                       
          	

•                                               
                	

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

More Related Content

PDF
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
PDF
MongoDB Europe 2016 - Debugging MongoDB Performance
PDF
Di web tech mail (no subject)
PDF
Map/Confused? A practical approach to Map/Reduce with MongoDB
PPTX
MongoDB Live Hacking
PDF
Mobile Web 5.0
PPTX
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
KEY
Schema design
MongoDB Europe 2016 - Enabling the Internet of Things at Proximus - Belgium's...
MongoDB Europe 2016 - Debugging MongoDB Performance
Di web tech mail (no subject)
Map/Confused? A practical approach to Map/Reduce with MongoDB
MongoDB Live Hacking
Mobile Web 5.0
MongoDB San Francisco 2013: Hash-based Sharding in MongoDB 2.4 presented by B...
Schema design

What's hot (20)

PPTX
Mythbusting: Understanding How We Measure the Performance of MongoDB
PPTX
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
ODP
2011 Mongo FR - Indexing in MongoDB
PDF
MongoDB Performance Debugging
PPT
Fast querying indexing for performance (4)
PDF
Mongodb index 讀書心得
KEY
How Signpost uses MongoDB for Tracking and Analytics
KEY
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
PDF
Ajax cheat sheet
PPTX
Reducing Development Time with MongoDB vs. SQL
PPTX
The rise of json in rdbms land jab17
PDF
Building Apps with MongoDB
PPTX
Morphia: Simplifying Persistence for Java and MongoDB
PPTX
Mongo or Die: How MongoDB Powers Doodle or Die
PDF
Optimizing Slow Queries with Indexes and Creativity
PDF
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
KEY
Schema Design with MongoDB
PDF
Mining legal texts with Python
PDF
Java Persistence Frameworks for MongoDB
PDF
Mongodb debugging-performance-problems
Mythbusting: Understanding How We Measure the Performance of MongoDB
Webinaire 2 de la série « Retour aux fondamentaux » : Votre première applicat...
2011 Mongo FR - Indexing in MongoDB
MongoDB Performance Debugging
Fast querying indexing for performance (4)
Mongodb index 讀書心得
How Signpost uses MongoDB for Tracking and Analytics
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
Ajax cheat sheet
Reducing Development Time with MongoDB vs. SQL
The rise of json in rdbms land jab17
Building Apps with MongoDB
Morphia: Simplifying Persistence for Java and MongoDB
Mongo or Die: How MongoDB Powers Doodle or Die
Optimizing Slow Queries with Indexes and Creativity
Java/Scala Lab: Борис Трофимов - Обжигающая Big Data.
Schema Design with MongoDB
Mining legal texts with Python
Java Persistence Frameworks for MongoDB
Mongodb debugging-performance-problems
Ad

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

ODP
Mongo db dla administratora
PDF
Social Data and Log Analysis Using MongoDB
PDF
MongoDB dla administratora
PDF
MongoDB Basics Unileon
KEY
MongoDB at ZPUGDC
PDF
mongodb tutorial
PDF
MongoDB: a gentle, friendly overview
PDF
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
PDF
MongoDB: Optimising for Performance, Scale & Analytics
KEY
Mongo scaling
PDF
视觉中国的MongoDB应用实践(QConBeijing2011)
KEY
PostgreSQLからMongoDBへ
PDF
MongoDB: Intro & Application for Big Data
PPTX
MongoDB at Scale
PPTX
Back to Basics, webinar 2: La tua prima applicazione MongoDB
PDF
MongoDB.pdf
PPTX
Streaming Data Pipelines with MongoDB and Kafka at ao.com
PPTX
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
PDF
How to use MongoDB with CakePHP
PDF
MongoDB at FrozenRails
Mongo db dla administratora
Social Data and Log Analysis Using MongoDB
MongoDB dla administratora
MongoDB Basics Unileon
MongoDB at ZPUGDC
mongodb tutorial
MongoDB: a gentle, friendly overview
Ensuring High Availability for Real-time Analytics featuring Boxed Ice / Serv...
MongoDB: Optimising for Performance, Scale & Analytics
Mongo scaling
视觉中国的MongoDB应用实践(QConBeijing2011)
PostgreSQLからMongoDBへ
MongoDB: Intro & Application for Big Data
MongoDB at Scale
Back to Basics, webinar 2: La tua prima applicazione MongoDB
MongoDB.pdf
Streaming Data Pipelines with MongoDB and Kafka at ao.com
MongoDB.local DC 2018: Ch-Ch-Ch-Ch-Changes: Taking Your MongoDB Stitch Applic...
How to use MongoDB with CakePHP
MongoDB at FrozenRails
Ad

Recently uploaded (20)

PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Approach and Philosophy of On baking technology
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Empathic Computing: Creating Shared Understanding
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PDF
KodekX | Application Modernization Development
The Rise and Fall of 3GPP – Time for a Sabbatical?
Approach and Philosophy of On baking technology
“AI and Expert System Decision Support & Business Intelligence Systems”
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
MIND Revenue Release Quarter 2 2025 Press Release
Reach Out and Touch Someone: Haptics and Empathic Computing
Empathic Computing: Creating Shared Understanding
Chapter 3 Spatial Domain Image Processing.pdf
Programs and apps: productivity, graphics, security and other tools
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Network Security Unit 5.pdf for BCA BBA.
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
VMware vSphere Foundation How to Sell Presentation-Ver1.4-2-14-2024.pptx
MYSQL Presentation for SQL database connectivity
Agricultural_Statistics_at_a_Glance_2022_0.pdf
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
KodekX | Application Modernization Development

ココロもつながるオンラインゲーム–アットゲームズ–の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. •  • 
  • 11. MongoDB •  •  NoSQL
  • 12. MongoDB l  NoSQL MongoDB l  MongoDB JP
  • 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
  • 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 : { :
  • 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
  • 62. l  l MongoDB l  Map/Reduce
  • 63. MongoDB group Map/Reduce http://www.mongodb.org/pages/viewpage.action?pageId=6750296
  • 65. • RDBMS •  • 
  • 67. ( )