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

  • 4,865 views
Uploaded on

2011/07/30(土)、第五回MongoDB勉強会の発表資料。要旨は、次の通りです。オンラインゲームポータルサイト – アットゲームズ – で、大規模リニューアルを7月上旬に行いました。その際LAMP環境で構築されているサイト内のSNS機能にMongoDBを導入した機能拡張を行いました。その時の開発の事例についてご紹介いたします。

2011/07/30(土)、第五回MongoDB勉強会の発表資料。要旨は、次の通りです。オンラインゲームポータルサイト – アットゲームズ – で、大規模リニューアルを7月上旬に行いました。その際LAMP環境で構築されているサイト内のSNS機能にMongoDBを導入した機能拡張を行いました。その時の開発の事例についてご紹介いたします。

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,865
On Slideshare
0
From Embeds
0
Number of Embeds
4

Actions

Shares
Downloads
0
Comments
0
Likes
16

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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
  • 6. MongoDB
  • 7. MongoDB SNS  ( )  
  • 8. •   •  MySQL • 
  • 9. •  •  
  • 10. MongoDB •   •  NoSQL
  • 11. MongoDB l  NoSQL MongoDB l  MongoDB JP
  • 12. MongoDB
  • 13. ( 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!!
  • 14. 15 (Web/PC ) 3 (Web/Mobile ) mongos 5 (MySQL) 1 :Master / 3 :Slave/ 1 :
  • 15. 3 (MongoDB) NEW!! •  CPU:Intel(R) Xeon(R) 2.13GHz 8core •  Memory:16GB •  HDD: 550GB (xfs 400GB/mongo )
  • 16. Web Server x 18 (PC/MB) mongos Server1 Server2 Server3 CONFIG CONFIG CONFIG Sharding PRIMARY PRIMARY PRIMARY ReplicaSet ReplicaSet ReplicaSet SECONDARY SECONDARY SECONDARY
  • 17. MongoDB DataAccess
  • 18.   MongoDB ( ) ( ) ( )
  • 19.  l Shard Key  ( ID( )) mod 100 md Shard Key  l 100 (0~99) 3 Shard  
  • 20.  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}});
  • 21.  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"});
  • 22. MongoDB DataAccess •  Symfony(PHP) + MongoDB • 
  • 23. MongoDB DataAccess Class MogoKeyValue MongoDB Class Class DiaryEvalMongoKeyVale FootprintsMongoKeyVale DAO
  • 24. •  explain  • 
  • 25. > 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
  • 26. 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" : { } }
  • 27. 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 } ]
  • 28. 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" : {:
  • 29.  AP DB
  • 30.  orz •  MongoDB •  PHP 
  • 31.  > 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)
  • 32. NG OK /
  • 33. ( Д ) !!
  • 34. DB (perl)
  • 35. DB perl 2011/6/24
  • 36. DB >db.footprints.find({”dataType":0,"date":{$lt:110624000000}}) .count();359832 36
  • 37. 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 !
  • 38. DB >db.footprints.find({”dataType":0,"date":{$lt:110624000000}}) .count();359832 orz
  • 39. DB ( ´ ) (´ )( )( )>db.footprints.find({”dataType":0,"date":{$lt:110624000000}}) .count(); 0 DB  ( )
  • 40. 
  • 41. / ( )  
  • 42. 
  • 43. mongod
  • 44. mongod mongod(primary)
  • 45. mongod : [conn38666] JS Error: out of memory
  • 46. mongod l  mongod AP accept  l  AP MongoDB l 
  • 47. server1 mongod(PRIMARY)ReplicaSet SECONDARY PRIMARY ( д )
  • 48. SECONDARY [rs Manager] replSet cant see a majority, will not try to elect self elect
  • 49. mongo1 mongo1 server2 SECONDARY
  • 50. mongo1 mongo1 server1 priority  server2 (default 01)
  • 51. ReplicaSet SECONDARYpriority 1 PRIMARY  SECONDARY (*´ ) ( д lll) ( )
  • 52.   ( )
  • 53.  slowms >/usr/local/mongodb/bin/mongod --slowms 500 --logpath /var/log/mongodb/data.log 500ms
  • 54.  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 ( `д ´)
  • 55.  printShardingSizes() 2 1 moveChunk() 
  • 56.  printShardingSizes() 7/26 (7/5) 3 2GB
  • 57. l   l MongoDB   l  Map/Reduce
  • 58. MongoDBgroup Map/Reduce http://www.mongodb.org/pages/viewpage.action?pageId=6750296
  • 59. • RDBMS  •   •   
  • 60. ( )
  • 61.