SlideShare une entreprise Scribd logo
1  sur  43
Télécharger pour lire hors ligne
The Case for using
MongoDB in Social Game



            Masakazu Matsushita
                Cyberagent, Inc.
About Me
• Masakazu Matsushita
• @matsukaz
• Cyberagent, Inc. - SocialApps Division
  - Ameba Pico (2011/01∼)
  - Animal Land (2011/03∼)
• DevLOVE Staff
Agenda
• About Animal Land
• System Overview
• Why MongoDB ?
• Considered Points
• Troubles
• Current Problems
About
Animal Land
Demo




http://apps.facebook.com/animal-land/
Development Period
• Started on 2011/03
• First meeting was held on 3.11
• Released on 2011/12/09
Team Member
• Producer 2
• Designer 1
• Flash Developer   3
• Engineer 4
  +α
System
Overview
Using Cloud Services
• Amazon Web Services
  - EC2 (Instance Store + EBS)
  - S3
  - CloudFront
  - Route53
  - Elastic Load Balancing
• Google Apps
• Kontagent
System Relations

iframe           API Call             Callback for
                                      Payment API




                                                   Web
         HTML
                                                  Server
                            JSON


         Flash
                                                Command
                            AMF                  Server

                                   AMF : Actionscript Message Format
L    m1.large

                                      Servers                             XX

                                                                          EBS
                                                                                m2.2xlarge
                                                                                EBS
         ELB                         ELB
                                                                                    S3

 Web                L   3     Command        L    4                             CloudFront
        nginx                       nginx                                        Route 53
        Tomcat                      Tomcat
                                                                          バッチ               L
        mongos                      mongos
                                                                                 バッチ
                                                                                 MySQL
Shard                        5 MySQL         L    memcached       L   2
                                                                          monitor           L
 MongoDB           XX               MySQL             memcached
                              EBS                                                munin
        mongod
                              MySQL          L                                   nagios
 MongoDB           XX
                                    MySQL               admin         L   ビルド               L
        mongod                EBS
                                                            nginx               redmine
 MongoDB           XX         MongoDB        XX   3        Tomcat                jenkins
        mongod                      mongoc
EBS                           EBS                          mongos               Maven    SVN
                                                                          EBS
                 Secondary
Middleware
• nginx 1.0.x
• Tomcat 7.0.x
• MongoDB 2.0.1
• MySQL 5.5.x
• memcached 1.4.x
Framework / Libraries
• Spring Framework、Spring MVC
• BlazeDS、Spring Flex
• Spring Data - MongoDB 1.0.0 M4
• mongo-java-driver 2.6.5
• Ehcache
• spymemcached
• RestFB
• MyBatis
Why MongoDB ?
• Used in Ameba Pico




           http://apps.facebook.com/amebapico/
• I like MongoDB features !!
  - ReplicaSet
  - Auto-Sharding
  - Can handle complex data structures
  - Index, Advanced Queries
  - Developed actively
  - Quite easy to understand
• Fits in Animal Land requirements
  - Complex data structures (City s grid
   data, user/structure parameters, ...)
 - Most processes run sequencially and
   doesn t update same data at a time
 - Maintenance-less
   • Change data structures
     dynamically
   • Durability, Scalability
• Resolve MongoDB s weak points by
 other way
 - Some data are stored in other DB
   • Payments history needs reliability,
    so they are stored in MySQL
   • Temporary data are stored in
    memcached
 - Don t think of using transactions
Considered
  Points
Developing Application
• Define data without using transaction
  - User data are defined in 1 document
      and updated only once in block
                                                          User Data
{ facebookId : xxx,
                                                           Image
   status : { lv : 10, coin : 9999, ... },
   layerInfo : 1¦1¦0¦1¦2¦1¦1¦3¦1¦1¦4¦0... ,
   structure : {
         1¦1 : { id : xxxx, depth : 3, width : 3, aspect : 1, ... }, ...
  },
   inventory : [ { id : xxx, size : xxx, ... }, ... ],
   neighbor : [ { id : xxx, newFlg : false, ... }, ... ],
   animal : [ { id : xxx, color : 0, pos : 20¦20 , ... } ],
  ...
}
Developing Application
• Cutdown data size as possible
  - City s grid data are stored in 1 field
   (Expanded when application uses)
 - Data in design phase(500 KB)
       layerInfo : {
             1¦1 : 0,
             1¦2 : 1,
            ....
   }


 - Current data(50 KB)
       layerInfo : 1¦1¦0¦1¦2¦1¦1¦3¦1¦1¦4¦0...
Developing Application
• Careful not to define too many fields
  - It took more than 5 sec for find()
   when data contained more than
   20,000 fields (144x144 City s grid
   data)
 - Consider data size, and also for the
   time to parse BSON
Developing Application
• Shard Key is decided in following
 policy
 - Don t use low-cardinality key
 - Recent used data should be on
   memory, and data not used should
   not be
 - Frequently read/write data should be
   in each shard in nice balance
Developing Application
• Use targeted operation as possible
  - Use Shard Key
  - Use index for non Shard Key op
                   Operation                      Type
 db.foo.find({ShardKey : 1})                    Targeted
 db.foo.find({ShardKey : 1, NonShardKey : 1})   Targeted
 db.foo.find({NonShardKey : 1})                 Global
 db.foo.find()                                  Global
 db.foo.insert(<object>)                       Targeted
 db.foo.update({ShardKey : 1}, <object>)       Targeted
 db.foo.remove({ShardKey : 1})
 db.foo.update({NonShardKey : 1}, <object>)    Global
 db.foo.remove({NonShardKey : 1})
Developing Application
• Decrease update frequency
  - Store master data in memory
  - Queue mechanism in Flash
  - User operations are processed in
   block (once per 5 sec)
 • Server processes sequencially
                                                        Processes
     User op.                   Stored in
                                                        Sequencially
                                 Queue
                        Queue
                                                     Command
                Flash
                                                      Server
                                     Send in Block
                                    once per 5 sec
Developing Application
• Develop efficiently using O/R Mapper
  - Spring Data - MongoDB and
   Wrapper classes
   @Autowired
   protected MongoTemplate mongoTemplate;

   public void insert(T entity) {
         mongoTemplate.save(entity);
   }

 - Can use any serializable object
 - Maybe easier to deal with than RDB
   O/R Mapper
Developing Application
• Implements without expecting rollback
  - Give up for some inconsistent data
  - Careful not to inflict disadvantages
   to user
Constructing Infrastructure
• Estimate same as other DBs
 - Data size/user (50 KB)
 - Expected user (DAU 70万)
 - Update frequency
 - Each servers max connections
 - Number of servers, specs, costs
 - Consider when to scale servers
  according to user growth
Constructing Infrastructure
• Performance Verification
  - Bandwith (EC2 is about 350Mbps)
  - Verify MongoDB (MongoDB 2.0.1、
   2Shard with Replica Set、enable
   journaling)
   • READ/WRITE performance
   • Performance during migration
   • Performance through Java Driver
 - Performance through application
Constructing Infrastructure
• Prepare for troubles
  - When mongod dies ...
    • SECONDARY becomes PRIMARY ?
    • Data synchronize when it restart ?
    • Safe when SECONDARY dies ?
  - When mongoc dies ...
    • Nothing happens ?
  - Succeed to restore from backup ?
                            → no problem
Constructing Infrastructure
• ReplicaSet and Shard Construction
  - Use large memory size
  - Use high speed I/O disk
  - Place mongoc independent from
   mongod
 - Use EBS to raise reliability (run only
   as SECONDARY)
• Enable Journaling
• Set oplogsize as 10GB
Constructing Infrastructure
• Create index in advance
  - Index blocks all operation ...
  - Took about 2 min to create index for
   200,000 data (each about 50KB)
 - Create index during maintanance
   time or in background for running
   services
Constructing Infrastructure
• Connection Pool Tuning
  ※ connnection pool is for mongos
         property               description     value
 connectionsPerHost       number of connections 100
 threadsAllowedToBlockFor wait threads per
                                                4
 ConnectionMultiplier     connection

 - set the value with nginx worker and
   Tomcat thread size in mind
 - Careful with Out of Semaphores
   errors. Above case would be
      100 + (100 * 4) = 500
In Operation
• Check chunk balance routinely
  - Move chunk manually if needed

• Careful when adding new Collections
  - Primary Shard might be overloaded
   because new collection data will be
   placed there
Troubles
mongod & mongoc died..
• Caused by virtual server host for EC2
 instance. Nothing to do with MongoDB
• There was NO impact for service !!
• Recovered just starting mongod and
 mongoc processes
Current
Problems
Online Backup
• Difficult to backup for running services
• Backup while in maintenance mode
• Thinking of doing backup from
 SECONDARY as follows, but need
 some verification ...
 1. set balancer off
 2. write lock SECONDARY and backup
 3. set balance on
Upgrade
• Upgrade is also difficult for the timing
• Need to do following steps
 1. Stop Arbiter, upgrade, run
 2. Stop SECONDARY, upgrade, run
 3. Stop PRIMARY, upgrade, run
Adding Shards
• It s possible to add shards later on,
 but have to consider it s performance
 for balancing
 - Pico is adding shards while in
   maintenance mode for safety
Best Chunksize
• Migration frequently occurs, because
 user data was too large and chunksize
 was small (default 64MB)
• Need to adjust chunksize according to
 it s data size


Maybe nice if you can set the chunksize
for each collections ...
Analyzing Data
• Hard to analyze user data, because we
 handle the data in 1 document
• Creating index if necessary
  - Tested MapReduce, but some
   performance problems occured. Not
   using it right now
Thank you !
Please enjoy Animal Land !!




        http://apps.facebook.com/animal-land/

Contenu connexe

En vedette

Flash-cards--Colors
Flash-cards--ColorsFlash-cards--Colors
Flash-cards--Colorsbraskasmom
 
Flash cards animals 1
Flash cards   animals 1Flash cards   animals 1
Flash cards animals 1deepsingh0303
 
Flashcards--Numbers
Flashcards--NumbersFlashcards--Numbers
Flashcards--Numbersbraskasmom
 
Лекция. Параметры Хофштеде
Лекция. Параметры ХофштедеЛекция. Параметры Хофштеде
Лекция. Параметры Хофштедеguest222ea06
 
Animals game junior 3 draft (1)
Animals game junior 3   draft (1)Animals game junior 3   draft (1)
Animals game junior 3 draft (1)colegiolascumbres
 
Bingo numbers 1 10
Bingo numbers 1 10Bingo numbers 1 10
Bingo numbers 1 10Maripg18
 
後悔しないもんごもんごの使い方 〜アプリ編〜
後悔しないもんごもんごの使い方 〜アプリ編〜後悔しないもんごもんごの使い方 〜アプリ編〜
後悔しないもんごもんごの使い方 〜アプリ編〜Masakazu Matsushita
 
MongoDB at eBay
MongoDB at eBayMongoDB at eBay
MongoDB at eBayMongoDB
 
Brain Dots at dots. - Brain Dotsのアーキテクチャ -
Brain Dots at dots. - Brain Dotsのアーキテクチャ -Brain Dots at dots. - Brain Dotsのアーキテクチャ -
Brain Dots at dots. - Brain Dotsのアーキテクチャ -Masakazu Matsushita
 
Middle School RIASEC Career Test
Middle School RIASEC Career TestMiddle School RIASEC Career Test
Middle School RIASEC Career TestDr. Mary Askew
 
カジュアルにMongo dbのbackup機能説明
カジュアルにMongo dbのbackup機能説明カジュアルにMongo dbのbackup機能説明
カジュアルにMongo dbのbackup機能説明Masakazu Matsushita
 
TranslimitにおけるAWS活用術
TranslimitにおけるAWS活用術TranslimitにおけるAWS活用術
TranslimitにおけるAWS活用術Masakazu Matsushita
 
Flash Cards Numbers And Colours
Flash Cards  Numbers And ColoursFlash Cards  Numbers And Colours
Flash Cards Numbers And ColoursGraciela Bilat
 
BrainWarsを支えるAWSサービスたち
BrainWarsを支えるAWSサービスたちBrainWarsを支えるAWSサービスたち
BrainWarsを支えるAWSサービスたちMasakazu Matsushita
 
Flash cards with letter sound-picture
Flash cards with letter sound-pictureFlash cards with letter sound-picture
Flash cards with letter sound-picturemboldeniii
 
Flashcards-plain A to Z, 1-10
Flashcards-plain A to Z, 1-10Flashcards-plain A to Z, 1-10
Flashcards-plain A to Z, 1-10braskasmom
 
140611だいたいわかるGit
140611だいたいわかるGit140611だいたいわかるGit
140611だいたいわかるGitMasashi Tsuru
 
TranslimitのChatOps事情と愉快なbotたち
TranslimitのChatOps事情と愉快なbotたちTranslimitのChatOps事情と愉快なbotたち
TranslimitのChatOps事情と愉快なbotたちMasakazu Matsushita
 
Sparkle box flash cards
Sparkle box flash cardsSparkle box flash cards
Sparkle box flash cardsAyee Yayee
 

En vedette (20)

Flash-cards--Colors
Flash-cards--ColorsFlash-cards--Colors
Flash-cards--Colors
 
Flash cards animals 1
Flash cards   animals 1Flash cards   animals 1
Flash cards animals 1
 
Flashcards--Numbers
Flashcards--NumbersFlashcards--Numbers
Flashcards--Numbers
 
Лекция. Параметры Хофштеде
Лекция. Параметры ХофштедеЛекция. Параметры Хофштеде
Лекция. Параметры Хофштеде
 
Animals game junior 3 draft (1)
Animals game junior 3   draft (1)Animals game junior 3   draft (1)
Animals game junior 3 draft (1)
 
Bingo numbers 1 10
Bingo numbers 1 10Bingo numbers 1 10
Bingo numbers 1 10
 
Colours game
Colours gameColours game
Colours game
 
後悔しないもんごもんごの使い方 〜アプリ編〜
後悔しないもんごもんごの使い方 〜アプリ編〜後悔しないもんごもんごの使い方 〜アプリ編〜
後悔しないもんごもんごの使い方 〜アプリ編〜
 
MongoDB at eBay
MongoDB at eBayMongoDB at eBay
MongoDB at eBay
 
Brain Dots at dots. - Brain Dotsのアーキテクチャ -
Brain Dots at dots. - Brain Dotsのアーキテクチャ -Brain Dots at dots. - Brain Dotsのアーキテクチャ -
Brain Dots at dots. - Brain Dotsのアーキテクチャ -
 
Middle School RIASEC Career Test
Middle School RIASEC Career TestMiddle School RIASEC Career Test
Middle School RIASEC Career Test
 
カジュアルにMongo dbのbackup機能説明
カジュアルにMongo dbのbackup機能説明カジュアルにMongo dbのbackup機能説明
カジュアルにMongo dbのbackup機能説明
 
TranslimitにおけるAWS活用術
TranslimitにおけるAWS活用術TranslimitにおけるAWS活用術
TranslimitにおけるAWS活用術
 
Flash Cards Numbers And Colours
Flash Cards  Numbers And ColoursFlash Cards  Numbers And Colours
Flash Cards Numbers And Colours
 
BrainWarsを支えるAWSサービスたち
BrainWarsを支えるAWSサービスたちBrainWarsを支えるAWSサービスたち
BrainWarsを支えるAWSサービスたち
 
Flash cards with letter sound-picture
Flash cards with letter sound-pictureFlash cards with letter sound-picture
Flash cards with letter sound-picture
 
Flashcards-plain A to Z, 1-10
Flashcards-plain A to Z, 1-10Flashcards-plain A to Z, 1-10
Flashcards-plain A to Z, 1-10
 
140611だいたいわかるGit
140611だいたいわかるGit140611だいたいわかるGit
140611だいたいわかるGit
 
TranslimitのChatOps事情と愉快なbotたち
TranslimitのChatOps事情と愉快なbotたちTranslimitのChatOps事情と愉快なbotたち
TranslimitのChatOps事情と愉快なbotたち
 
Sparkle box flash cards
Sparkle box flash cardsSparkle box flash cards
Sparkle box flash cards
 

Similaire à The Case for using MongoDB in Social Game - Animal Land

Scalable XQuery Processing with Zorba on top of MongoDB
Scalable XQuery Processing with Zorba on top of MongoDBScalable XQuery Processing with Zorba on top of MongoDB
Scalable XQuery Processing with Zorba on top of MongoDBWilliam Candillon
 
Q con london2011-matthewwall-whyichosemongodbforguardiancouk
Q con london2011-matthewwall-whyichosemongodbforguardiancoukQ con london2011-matthewwall-whyichosemongodbforguardiancouk
Q con london2011-matthewwall-whyichosemongodbforguardiancoukRoger Xia
 
Gotszling mogo db-membase
Gotszling mogo db-membaseGotszling mogo db-membase
Gotszling mogo db-membaseGiltTech
 
Meandre 2.0 Alpha Preview
Meandre 2.0 Alpha PreviewMeandre 2.0 Alpha Preview
Meandre 2.0 Alpha PreviewXavier Llorà
 
Scaling a MeteorJS SaaS app on AWS
Scaling a MeteorJS SaaS app on AWSScaling a MeteorJS SaaS app on AWS
Scaling a MeteorJS SaaS app on AWSBrett McLain
 
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...Flink Forward
 
Webinar: Adobe Experience Manager Clustering Made Easy on MongoDB
Webinar: Adobe Experience Manager Clustering Made Easy on MongoDB Webinar: Adobe Experience Manager Clustering Made Easy on MongoDB
Webinar: Adobe Experience Manager Clustering Made Easy on MongoDB MongoDB
 
AmebaPico 裏側の技術やAWSの利用について
AmebaPico 裏側の技術やAWSの利用についてAmebaPico 裏側の技術やAWSの利用について
AmebaPico 裏側の技術やAWSの利用についてKohei Morino
 
Isomorphic JavaScript with Nashorn
Isomorphic JavaScript with NashornIsomorphic JavaScript with Nashorn
Isomorphic JavaScript with NashornMaxime Najim
 
Alexander Sergeev presentation
Alexander Sergeev presentationAlexander Sergeev presentation
Alexander Sergeev presentationalexander_sergeev
 
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...Antonio Garrote Hernández
 
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB Rakuten Group, Inc.
 
Sharded By Business Line: Migrating to a Core Database using MongoDB and Solr
Sharded By Business Line: Migrating to a Core Database using MongoDB and SolrSharded By Business Line: Migrating to a Core Database using MongoDB and Solr
Sharded By Business Line: Migrating to a Core Database using MongoDB and SolrMongoDB
 
Mongo la search platform - january 2013
Mongo la   search platform - january 2013Mongo la   search platform - january 2013
Mongo la search platform - january 2013MongoDB
 
MongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and Kafka
MongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and KafkaMongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and Kafka
MongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and KafkaMongoDB
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRailsMike Dirolf
 
Vm13 vnx mixed workloads
Vm13 vnx mixed workloadsVm13 vnx mixed workloads
Vm13 vnx mixed workloadspittmantony
 

Similaire à The Case for using MongoDB in Social Game - Animal Land (20)

Scalable XQuery Processing with Zorba on top of MongoDB
Scalable XQuery Processing with Zorba on top of MongoDBScalable XQuery Processing with Zorba on top of MongoDB
Scalable XQuery Processing with Zorba on top of MongoDB
 
Q con london2011-matthewwall-whyichosemongodbforguardiancouk
Q con london2011-matthewwall-whyichosemongodbforguardiancoukQ con london2011-matthewwall-whyichosemongodbforguardiancouk
Q con london2011-matthewwall-whyichosemongodbforguardiancouk
 
Silver Light1.0
Silver Light1.0Silver Light1.0
Silver Light1.0
 
Gotszling mogo db-membase
Gotszling mogo db-membaseGotszling mogo db-membase
Gotszling mogo db-membase
 
Meandre 2.0 Alpha Preview
Meandre 2.0 Alpha PreviewMeandre 2.0 Alpha Preview
Meandre 2.0 Alpha Preview
 
Scaling a MeteorJS SaaS app on AWS
Scaling a MeteorJS SaaS app on AWSScaling a MeteorJS SaaS app on AWS
Scaling a MeteorJS SaaS app on AWS
 
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
Flink Forward Berlin 2017: Robert Metzger - Keep it going - How to reliably a...
 
Webinar: Adobe Experience Manager Clustering Made Easy on MongoDB
Webinar: Adobe Experience Manager Clustering Made Easy on MongoDB Webinar: Adobe Experience Manager Clustering Made Easy on MongoDB
Webinar: Adobe Experience Manager Clustering Made Easy on MongoDB
 
AmebaPico 裏側の技術やAWSの利用について
AmebaPico 裏側の技術やAWSの利用についてAmebaPico 裏側の技術やAWSの利用について
AmebaPico 裏側の技術やAWSの利用について
 
Isomorphic JavaScript with Nashorn
Isomorphic JavaScript with NashornIsomorphic JavaScript with Nashorn
Isomorphic JavaScript with Nashorn
 
Alexander Sergeev presentation
Alexander Sergeev presentationAlexander Sergeev presentation
Alexander Sergeev presentation
 
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
4th European Lisp Symposium: Jobim: an Actors Library for the Clojure Program...
 
NoSQL with MySQL
NoSQL with MySQLNoSQL with MySQL
NoSQL with MySQL
 
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
KVSの性能、RDBMSのインデックス、更にMapReduceを併せ持つAll-in-One NoSQL: MongoDB
 
Sharded By Business Line: Migrating to a Core Database using MongoDB and Solr
Sharded By Business Line: Migrating to a Core Database using MongoDB and SolrSharded By Business Line: Migrating to a Core Database using MongoDB and Solr
Sharded By Business Line: Migrating to a Core Database using MongoDB and Solr
 
Mongo la search platform - january 2013
Mongo la   search platform - january 2013Mongo la   search platform - january 2013
Mongo la search platform - january 2013
 
MongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and Kafka
MongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and KafkaMongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and Kafka
MongoDB Europe 2016 - Powering Microservices with Docker, Kubernetes, and Kafka
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRails
 
Offline Html5 3days
Offline Html5 3daysOffline Html5 3days
Offline Html5 3days
 
Vm13 vnx mixed workloads
Vm13 vnx mixed workloadsVm13 vnx mixed workloads
Vm13 vnx mixed workloads
 

Plus de Masakazu Matsushita

It's up to you 〜 楽しさドリブンで歩んだ道 〜
It's up to you 〜 楽しさドリブンで歩んだ道 〜It's up to you 〜 楽しさドリブンで歩んだ道 〜
It's up to you 〜 楽しさドリブンで歩んだ道 〜Masakazu Matsushita
 
スタートアップで培ったアーキテクチャ設計ノウハウ
スタートアップで培ったアーキテクチャ設計ノウハウスタートアップで培ったアーキテクチャ設計ノウハウ
スタートアップで培ったアーキテクチャ設計ノウハウMasakazu Matsushita
 
全世界6,500万DL突破!ヒットゲームを作り上げたチームの道のり
全世界6,500万DL突破!ヒットゲームを作り上げたチームの道のり全世界6,500万DL突破!ヒットゲームを作り上げたチームの道のり
全世界6,500万DL突破!ヒットゲームを作り上げたチームの道のりMasakazu Matsushita
 
EFS利用事例 -Craft Warriorsのバトルを支える仕組み-
EFS利用事例 -Craft Warriorsのバトルを支える仕組み-EFS利用事例 -Craft Warriorsのバトルを支える仕組み-
EFS利用事例 -Craft Warriorsのバトルを支える仕組み-Masakazu Matsushita
 
Interactive buttonsを利用したbotをつくってみた
Interactive buttonsを利用したbotをつくってみたInteractive buttonsを利用したbotをつくってみた
Interactive buttonsを利用したbotをつくってみたMasakazu Matsushita
 
BrainWarsのアーキテクチャ(OpsWorks & DynamoDB編)
BrainWarsのアーキテクチャ(OpsWorks & DynamoDB編)BrainWarsのアーキテクチャ(OpsWorks & DynamoDB編)
BrainWarsのアーキテクチャ(OpsWorks & DynamoDB編)Masakazu Matsushita
 
1000万DL突破!BrainWarsのアーキテクチャ
1000万DL突破!BrainWarsのアーキテクチャ1000万DL突破!BrainWarsのアーキテクチャ
1000万DL突破!BrainWarsのアーキテクチャMasakazu Matsushita
 
いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0Masakazu Matsushita
 
ソーシャルゲームにおけるAWS/MongoDB利用事例
ソーシャルゲームにおけるAWS/MongoDB利用事例ソーシャルゲームにおけるAWS/MongoDB利用事例
ソーシャルゲームにおけるAWS/MongoDB利用事例Masakazu Matsushita
 
海外向けサービスの苦労話
海外向けサービスの苦労話海外向けサービスの苦労話
海外向けサービスの苦労話Masakazu Matsushita
 
ソーシャルゲームにおけるMongoDB適用事例 - Animal Land
ソーシャルゲームにおけるMongoDB適用事例 - Animal LandソーシャルゲームにおけるMongoDB適用事例 - Animal Land
ソーシャルゲームにおけるMongoDB適用事例 - Animal LandMasakazu Matsushita
 
Mongo DBを半年運用してみた
Mongo DBを半年運用してみたMongo DBを半年運用してみた
Mongo DBを半年運用してみたMasakazu Matsushita
 

Plus de Masakazu Matsushita (20)

It's up to you 〜 楽しさドリブンで歩んだ道 〜
It's up to you 〜 楽しさドリブンで歩んだ道 〜It's up to you 〜 楽しさドリブンで歩んだ道 〜
It's up to you 〜 楽しさドリブンで歩んだ道 〜
 
スタートアップで培ったアーキテクチャ設計ノウハウ
スタートアップで培ったアーキテクチャ設計ノウハウスタートアップで培ったアーキテクチャ設計ノウハウ
スタートアップで培ったアーキテクチャ設計ノウハウ
 
全世界6,500万DL突破!ヒットゲームを作り上げたチームの道のり
全世界6,500万DL突破!ヒットゲームを作り上げたチームの道のり全世界6,500万DL突破!ヒットゲームを作り上げたチームの道のり
全世界6,500万DL突破!ヒットゲームを作り上げたチームの道のり
 
EFS利用事例 -Craft Warriorsのバトルを支える仕組み-
EFS利用事例 -Craft Warriorsのバトルを支える仕組み-EFS利用事例 -Craft Warriorsのバトルを支える仕組み-
EFS利用事例 -Craft Warriorsのバトルを支える仕組み-
 
Interactive buttonsを利用したbotをつくってみた
Interactive buttonsを利用したbotをつくってみたInteractive buttonsを利用したbotをつくってみた
Interactive buttonsを利用したbotをつくってみた
 
ダブルCTO
ダブルCTOダブルCTO
ダブルCTO
 
BrainWarsのアーキテクチャ(OpsWorks & DynamoDB編)
BrainWarsのアーキテクチャ(OpsWorks & DynamoDB編)BrainWarsのアーキテクチャ(OpsWorks & DynamoDB編)
BrainWarsのアーキテクチャ(OpsWorks & DynamoDB編)
 
1000万DL突破!BrainWarsのアーキテクチャ
1000万DL突破!BrainWarsのアーキテクチャ1000万DL突破!BrainWarsのアーキテクチャ
1000万DL突破!BrainWarsのアーキテクチャ
 
いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0いつやるの?Git入門 v1.1.0
いつやるの?Git入門 v1.1.0
 
いつやるの?Git入門
いつやるの?Git入門いつやるの?Git入門
いつやるの?Git入門
 
ソーシャルゲームにおけるAWS/MongoDB利用事例
ソーシャルゲームにおけるAWS/MongoDB利用事例ソーシャルゲームにおけるAWS/MongoDB利用事例
ソーシャルゲームにおけるAWS/MongoDB利用事例
 
海外向けサービスの苦労話
海外向けサービスの苦労話海外向けサービスの苦労話
海外向けサービスの苦労話
 
ソーシャルゲームにおけるMongoDB適用事例 - Animal Land
ソーシャルゲームにおけるMongoDB適用事例 - Animal LandソーシャルゲームにおけるMongoDB適用事例 - Animal Land
ソーシャルゲームにおけるMongoDB適用事例 - Animal Land
 
Mongo DBを半年運用してみた
Mongo DBを半年運用してみたMongo DBを半年運用してみた
Mongo DBを半年運用してみた
 
ニコカレでLife hacks
ニコカレでLife hacksニコカレでLife hacks
ニコカレでLife hacks
 
DevLOVEのDevってなんだ?
DevLOVEのDevってなんだ?DevLOVEのDevってなんだ?
DevLOVEのDevってなんだ?
 
スマフォな生活
スマフォな生活スマフォな生活
スマフォな生活
 
It's up to you
It's up to youIt's up to you
It's up to you
 
JavaScript再入門
JavaScript再入門JavaScript再入門
JavaScript再入門
 
Spring Framework勉強会
Spring  Framework勉強会Spring  Framework勉強会
Spring Framework勉強会
 

Dernier

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesZilliz
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfRankYa
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsRizwan Syed
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 

Dernier (20)

Vector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector DatabasesVector Databases 101 - An introduction to the world of Vector Databases
Vector Databases 101 - An introduction to the world of Vector Databases
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Search Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdfSearch Engine Optimization SEO PDF for 2024.pdf
Search Engine Optimization SEO PDF for 2024.pdf
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Scanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL CertsScanning the Internet for External Cloud Exposures via SSL Certs
Scanning the Internet for External Cloud Exposures via SSL Certs
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 

The Case for using MongoDB in Social Game - Animal Land

  • 1. The Case for using MongoDB in Social Game Masakazu Matsushita Cyberagent, Inc.
  • 2. About Me • Masakazu Matsushita • @matsukaz • Cyberagent, Inc. - SocialApps Division - Ameba Pico (2011/01∼) - Animal Land (2011/03∼) • DevLOVE Staff
  • 3. Agenda • About Animal Land • System Overview • Why MongoDB ? • Considered Points • Troubles • Current Problems
  • 6. Development Period • Started on 2011/03 • First meeting was held on 3.11 • Released on 2011/12/09
  • 7. Team Member • Producer 2 • Designer 1 • Flash Developer 3 • Engineer 4 +α
  • 9. Using Cloud Services • Amazon Web Services - EC2 (Instance Store + EBS) - S3 - CloudFront - Route53 - Elastic Load Balancing • Google Apps • Kontagent
  • 10. System Relations iframe API Call Callback for Payment API Web HTML Server JSON Flash Command AMF Server AMF : Actionscript Message Format
  • 11. L m1.large Servers XX EBS m2.2xlarge EBS ELB ELB S3 Web L 3 Command L 4 CloudFront nginx nginx Route 53 Tomcat Tomcat バッチ L mongos mongos バッチ MySQL Shard 5 MySQL L memcached L 2 monitor L MongoDB XX MySQL memcached EBS munin mongod MySQL L nagios MongoDB XX MySQL admin L ビルド L mongod EBS nginx redmine MongoDB XX MongoDB XX 3 Tomcat jenkins mongod mongoc EBS EBS mongos Maven SVN EBS Secondary
  • 12. Middleware • nginx 1.0.x • Tomcat 7.0.x • MongoDB 2.0.1 • MySQL 5.5.x • memcached 1.4.x
  • 13. Framework / Libraries • Spring Framework、Spring MVC • BlazeDS、Spring Flex • Spring Data - MongoDB 1.0.0 M4 • mongo-java-driver 2.6.5 • Ehcache • spymemcached • RestFB • MyBatis
  • 15. • Used in Ameba Pico http://apps.facebook.com/amebapico/
  • 16. • I like MongoDB features !! - ReplicaSet - Auto-Sharding - Can handle complex data structures - Index, Advanced Queries - Developed actively - Quite easy to understand
  • 17. • Fits in Animal Land requirements - Complex data structures (City s grid data, user/structure parameters, ...) - Most processes run sequencially and doesn t update same data at a time - Maintenance-less • Change data structures dynamically • Durability, Scalability
  • 18. • Resolve MongoDB s weak points by other way - Some data are stored in other DB • Payments history needs reliability, so they are stored in MySQL • Temporary data are stored in memcached - Don t think of using transactions
  • 20. Developing Application • Define data without using transaction - User data are defined in 1 document and updated only once in block User Data { facebookId : xxx, Image status : { lv : 10, coin : 9999, ... }, layerInfo : 1¦1¦0¦1¦2¦1¦1¦3¦1¦1¦4¦0... , structure : { 1¦1 : { id : xxxx, depth : 3, width : 3, aspect : 1, ... }, ... }, inventory : [ { id : xxx, size : xxx, ... }, ... ], neighbor : [ { id : xxx, newFlg : false, ... }, ... ], animal : [ { id : xxx, color : 0, pos : 20¦20 , ... } ], ... }
  • 21. Developing Application • Cutdown data size as possible - City s grid data are stored in 1 field (Expanded when application uses) - Data in design phase(500 KB) layerInfo : { 1¦1 : 0, 1¦2 : 1, .... } - Current data(50 KB) layerInfo : 1¦1¦0¦1¦2¦1¦1¦3¦1¦1¦4¦0...
  • 22. Developing Application • Careful not to define too many fields - It took more than 5 sec for find() when data contained more than 20,000 fields (144x144 City s grid data) - Consider data size, and also for the time to parse BSON
  • 23. Developing Application • Shard Key is decided in following policy - Don t use low-cardinality key - Recent used data should be on memory, and data not used should not be - Frequently read/write data should be in each shard in nice balance
  • 24. Developing Application • Use targeted operation as possible - Use Shard Key - Use index for non Shard Key op Operation Type db.foo.find({ShardKey : 1}) Targeted db.foo.find({ShardKey : 1, NonShardKey : 1}) Targeted db.foo.find({NonShardKey : 1}) Global db.foo.find() Global db.foo.insert(<object>) Targeted db.foo.update({ShardKey : 1}, <object>) Targeted db.foo.remove({ShardKey : 1}) db.foo.update({NonShardKey : 1}, <object>) Global db.foo.remove({NonShardKey : 1})
  • 25. Developing Application • Decrease update frequency - Store master data in memory - Queue mechanism in Flash - User operations are processed in block (once per 5 sec) • Server processes sequencially Processes User op. Stored in Sequencially Queue Queue Command Flash Server Send in Block once per 5 sec
  • 26. Developing Application • Develop efficiently using O/R Mapper - Spring Data - MongoDB and Wrapper classes @Autowired protected MongoTemplate mongoTemplate; public void insert(T entity) { mongoTemplate.save(entity); } - Can use any serializable object - Maybe easier to deal with than RDB O/R Mapper
  • 27. Developing Application • Implements without expecting rollback - Give up for some inconsistent data - Careful not to inflict disadvantages to user
  • 28. Constructing Infrastructure • Estimate same as other DBs - Data size/user (50 KB) - Expected user (DAU 70万) - Update frequency - Each servers max connections - Number of servers, specs, costs - Consider when to scale servers according to user growth
  • 29. Constructing Infrastructure • Performance Verification - Bandwith (EC2 is about 350Mbps) - Verify MongoDB (MongoDB 2.0.1、 2Shard with Replica Set、enable journaling) • READ/WRITE performance • Performance during migration • Performance through Java Driver - Performance through application
  • 30. Constructing Infrastructure • Prepare for troubles - When mongod dies ... • SECONDARY becomes PRIMARY ? • Data synchronize when it restart ? • Safe when SECONDARY dies ? - When mongoc dies ... • Nothing happens ? - Succeed to restore from backup ? → no problem
  • 31. Constructing Infrastructure • ReplicaSet and Shard Construction - Use large memory size - Use high speed I/O disk - Place mongoc independent from mongod - Use EBS to raise reliability (run only as SECONDARY) • Enable Journaling • Set oplogsize as 10GB
  • 32. Constructing Infrastructure • Create index in advance - Index blocks all operation ... - Took about 2 min to create index for 200,000 data (each about 50KB) - Create index during maintanance time or in background for running services
  • 33. Constructing Infrastructure • Connection Pool Tuning ※ connnection pool is for mongos property description value connectionsPerHost number of connections 100 threadsAllowedToBlockFor wait threads per 4 ConnectionMultiplier connection - set the value with nginx worker and Tomcat thread size in mind - Careful with Out of Semaphores errors. Above case would be 100 + (100 * 4) = 500
  • 34. In Operation • Check chunk balance routinely - Move chunk manually if needed • Careful when adding new Collections - Primary Shard might be overloaded because new collection data will be placed there
  • 36. mongod & mongoc died.. • Caused by virtual server host for EC2 instance. Nothing to do with MongoDB • There was NO impact for service !! • Recovered just starting mongod and mongoc processes
  • 38. Online Backup • Difficult to backup for running services • Backup while in maintenance mode • Thinking of doing backup from SECONDARY as follows, but need some verification ... 1. set balancer off 2. write lock SECONDARY and backup 3. set balance on
  • 39. Upgrade • Upgrade is also difficult for the timing • Need to do following steps 1. Stop Arbiter, upgrade, run 2. Stop SECONDARY, upgrade, run 3. Stop PRIMARY, upgrade, run
  • 40. Adding Shards • It s possible to add shards later on, but have to consider it s performance for balancing - Pico is adding shards while in maintenance mode for safety
  • 41. Best Chunksize • Migration frequently occurs, because user data was too large and chunksize was small (default 64MB) • Need to adjust chunksize according to it s data size Maybe nice if you can set the chunksize for each collections ...
  • 42. Analyzing Data • Hard to analyze user data, because we handle the data in 1 document • Creating index if necessary - Tested MapReduce, but some performance problems occured. Not using it right now
  • 43. Thank you ! Please enjoy Animal Land !! http://apps.facebook.com/animal-land/