Your SlideShare is downloading. ×
ココロもつながるオンラインゲーム–アットゲームズ–のMongoDB導入事例
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

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

4,987
views

Published on

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

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


0 Comments
17 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
4,987
On Slideshare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
0
Comments
0
Likes
17
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, INDEXnscanned : 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. explaindb.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. mongod
  • 42. mongod mongod(primary)
  • 43. mongod : [conn38666] JS Error: out of memory
  • 44. mongod l  mongod AP accept l  AP MongoDB l 
  • 45. server1 mongod(PRIMARY)ReplicaSet SECONDARY PRIMARY ( д )
  • 46. SECONDARY [rs Manager] replSet cant see a majority, will not try to elect self elect
  • 47. mongo1 mongo1 server2 SECONDARY
  • 48. mongo1 mongo1 server1 priority server2 (default 01)
  • 49. ReplicaSet SECONDARYpriority 1 PRIMARY SECONDARY (*´ ) ( д lll) ( )
  • 50. ( )
  • 51. slowms /usr/local/mongodb/bin/mongod --slowms 500 --logpath /var/log/mongodb/data.log 500ms
  • 52. 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 ( `д ´)
  • 53. printShardingSizes() 2 1 moveChunk()
  • 54. printShardingSizes() 7/26 (7/5) 3 2GB
  • 55. l  l MongoDB l  Map/Reduce
  • 56. MongoDBgroup Map/Reduce http://www.mongodb.org/pages/viewpage.action?pageId=6750296
  • 57. • RDBMS •  • 
  • 58. ( )