Yapc asia 2011_zigorou

Toru Yamaguchi
Toru YamaguchiArchitect at DeNA
The case file of
Mobage Open Platform	
  Mobage
                    	
 Toru Yamaguchi <zigorou@cpan.org>
   http://d.hatena.ne.jp/ZIGOROu/
             DeNA co.,ltd.
              2011/10/14
            YAPC Asia 2011
! 
     ! 
     ! 

! 


     ! 
!   Wikipedia
     ! 



! 
     ! 

     !          (Cause Analysis)
     !          (Failure Prevention)
     !          (Knowledge Distribution)
(   )
1 DeadLock                                     	

!         API (T                 )                           Dead Lock

     !                   API
                                     Internal Server Error

     ! 


! 
     !   Internal Server Error
(1)	
!                   API   GET

     !    totalResults             OpenSearch

!             totalResults
     SQL_CALC_FOUND_ROWS
     !                           SELECT

! 
     totalResults
     !   INSERT, DELETE         TRIGGER
(2)	
!                    SHOW INNODB STATUS
     !   Dead Lock
     ! 


! 
     !                UPDATE

          !                                 UPDATE

     ! 
BEGIN;

SELECT id FROM somedata_group WHERE name = ?;

INSERT INTO somedata(id, group_id, data, published_on)
VALUES(?, ?, ?, ?);

UPDATE somedata_summary SET total_results = total_results
+ 1, updated_on = ? WHERE group_id = ?;

COMMIT;
(3)	
!   Group
     ! 
     ! 


! 
     ! 
                                    UPDATE
               increment
     !                                  MySQL
          Dead Lock
(4)	

        Transaction	
   group_id = 1	
           Transaction	




                        group_id = 2	


                        group_id = 3	
           Transaction	
group_id = 3
UPDATE
                        group_id = 4	


                        group_id = 5	
           Transaction
(1)	
! 
     !            UPDATE                          w
     !                       SELECT               totalResults

     !   INSERT                 incr/decr        QUEUE
                         UPDATE
     !                totalResults

     !                      xaicron
(2)	
/* API                */

BEGIN;

INSERT INTO somedata(id, group_id, data, published_on)
VALUES(?, ?, ?, ?);

INSERT INTO somedata_summary_queue(id, group_id,
affected_number, published_on);

COMMIT;
(3)	
/* Batch Worker       */

BEGIN;

SELECT id, group_id, affected_number FROM
somegroup_summary_queue ORDER BY published_on ASC LIMIT 100;

/* group                               UPDATE */

UPDATE somedata_summary SET total_results = ?, updated_on = ?
WHERE group_id = ?;

…

DELETE somegroup_summary_queue WHERE id IN (?, ?, …, ?);

COMMIT;
(1)	
! 
     ! 

     ! 

     !         InnoDB    QUEUE
                 (      ) UPDATE


          ! 
(2)	
! 
     !    InnoDB            QUEUE              INDEX

          !   INSERT, DELETE         enqueue

     !                      queue
          WHERE        id
          ! 
               FOR UPDATE
     ! 
Yapc asia 2011_zigorou
2 INSERT vs DELETE	

! 
     ! 

!          API (             T            )
     !          1            INSERT
     !        API
          purge
     !                            purge       (   )
                    INSERT

! 
     !       shard
(   )
Yapc asia 2011_zigorou
(1)	
!              purge
     !           MASTER      DELETE                 SLAVE            ww
          !   DELETE
          !                          redo             SLAVE

     !                       sleep          wait                 DB
                                                      wait

          !                          wait

!                      wait
     !   SLAVE          Seconds_Behind_Master                 wait
     !                               wait
Loop::Sustainable (1)	
! 
! https://github.com/zigorou/p5-loop-sustainable
! 
     ! 
     ! 
     ! 
                   wait
          ! 
          !               Seconds_Behind_Master

     !                      b ry
Loop::Sustainable (2)	
         process	
                 process	
                                               2sec	
         process	
                                   process	

         process	
                             2sec	

                                   process	
         process	
                                               2sec	

         process	
                 process	

                                               2sec	

Seconds_Behind_Master : 10 sec	
   process	

                                               2sec
(2)	
!                               w

!   SET SESSION sql_log_bin = 0

     !   MASTER      SLAVE             DELETE


!             DELETE

     !                                          prefork
                       DELETE
                  xaicron                   (        )
(3)	
! 

!   DELETE

!   DELETE                    purge
     !    partitioning    API

!   STOP SLAVE       DB
    Master

     ! 
     ! 
(1)	
!                   DELETE
     !                                DELETE
     !   DELETE              SELECT

!                 MySQL
     ! 
          ! 
          !    RDBMS
     ! 

!   SET SESSION sql_log_bin=0
     !                           DELETE
(2)	
!              DELETE                       INSERT

     !               Partitioning

     !           Sharding


! 
     !    mysqldump –w      WHERE
(1)	
! 
     ! 

     ! 
     !   PRIMARY KEY

     ! 
     !                 ALTER TABLE some_table ADD
          KEY
     ! 
     !     M
(2)	
! 
     ! 
     !              DML

          !    incr/decr
     ! 

          ! 
Yapc asia 2011_zigorou
3                    	
! 
! 
! 

     API    Push   friend timeline

     !                               DB


!                             API
(1)	
! 
     ! 
     ! 
     ! 

!                                       count,
     startIndex (LIMIT/OFFSET      )

! 
SELECT friend_user_id FROM friends WHERE user_id = ?;
/*                       */
SELECT user_id FROM user_app WHERE app_id = ? AND
user_id IN (?, ?, …, ?);

/*                        */
SELECT SQL_CALC_FOUND_ROWS user_id, nickname
FROM users WHERE user_id IN(?, ?, …, ?) LIMIT 50
OFFSET 0;

SELECT FOUND_ROWS();
LIMIT 50
                                 valid users    OFFSET 0	
                                  500 users	
               installed users
                 750 users	
  friend
1000 users
(2)	
!   friends       n:m, user_app     1:n, users        1:1
!   friends                                                 (    1000
              )         user_app



!   users               SQL_CALC_FOUND_ROWS
                           LIMIT, OFFSET

!                         friends

     !            Temporary Table                     INSERT    users
          JOIN
(1)	
! 
     ! selectall_arrayref
     ! 

!   SQL_CALC_FOUND_ROWS
     !   LIMIT, OFFSET                         COUNT(*)

     ! 

!   Temporary Table
     ! 
     ! 
     !       user_id         user_id
             LIMIT, OFFSET
(2)	
!   prepare, fetchall_arrayref($max_rows)
     !   DBI::st   fetchall_arrayref($max_rows)       $max_rows

     ! 
     !                 friends           1000

!               1000             users                 user_app

     !   1000

!                                             1000
     users
     !             1000

! 
installed users                          valid users
  friend                         installed users         750 users	
                 750 users	
1000 users	
                       1000 users	

               installed users                          valid users
                 750 users	
                             750 users	
  friend                         installed users
1000 users	
                       1000 users	
         100 users	
               installed users
                 750 users	
     installed users
                                   250 users	
  friend
1000 users	



    end
 iteration
(3)	
! 


! 

!   Iterator::GroupedRange
     !   http://search.cpan.org/dist/Iterator-GroupedRange/

!                              List::MoreUtils   natatime
              I::GR       (fetchall_arrayref($max_rows)
          )
(4)	
! 

!   friends             DB                      1000
    memcached        get/set

!    user_app           mapping                memcached
         ( install                                  )

!                      iteration    DB
          DB                       iteration    set

!                                       3

     !                                                 xaicron
(1)	
! 

     ! 


! 
     ! 
          w

!             kazuho
Yapc asia 2011_zigorou
! 
     ! 
     ! 
     ! 

! 
     ! 
          xaicron
     ! 


! 

     ! 
1 of 42

Recommended

Control hypervisor via libvirt by
Control hypervisor via libvirtControl hypervisor via libvirt
Control hypervisor via libvirtSean Chang
654 views36 slides
[Kiwicon 2011] Post Memory Corruption Memory Analysis by
[Kiwicon 2011] Post Memory Corruption Memory Analysis[Kiwicon 2011] Post Memory Corruption Memory Analysis
[Kiwicon 2011] Post Memory Corruption Memory AnalysisMoabi.com
807 views84 slides
[HITB Malaysia 2011] Exploit Automation by
[HITB Malaysia 2011] Exploit Automation[HITB Malaysia 2011] Exploit Automation
[HITB Malaysia 2011] Exploit AutomationMoabi.com
1.2K views84 slides
The Ring programming language version 1.7 book - Part 193 of 196 by
The Ring programming language version 1.7 book - Part 193 of 196The Ring programming language version 1.7 book - Part 193 of 196
The Ring programming language version 1.7 book - Part 193 of 196Mahmoud Samir Fayed
16 views10 slides
JJUG CCC 2011 Spring by
JJUG CCC 2011 SpringJJUG CCC 2011 Spring
JJUG CCC 2011 SpringKiyotaka Oku
1.7K views85 slides
How History Justifies System Architecture (or Not) by
How History Justifies System Architecture (or Not)How History Justifies System Architecture (or Not)
How History Justifies System Architecture (or Not)Thomas Zimmermann
570 views22 slides

More Related Content

Similar to Yapc asia 2011_zigorou

"Mobage DBA Fight against Big Data" - NHN TE by
"Mobage DBA Fight against Big Data" - NHN TE"Mobage DBA Fight against Big Data" - NHN TE
"Mobage DBA Fight against Big Data" - NHN TERyosuke IWANAGA
13.8K views46 slides
20th.陈晓鸣 百度海量日志分析架构及处理经验分享 by
20th.陈晓鸣 百度海量日志分析架构及处理经验分享20th.陈晓鸣 百度海量日志分析架构及处理经验分享
20th.陈晓鸣 百度海量日志分析架构及处理经验分享elevenma
1.8K views44 slides
Big Data @ Orange - Dev Day 2013 - part 2 by
Big Data @ Orange - Dev Day 2013 - part 2Big Data @ Orange - Dev Day 2013 - part 2
Big Data @ Orange - Dev Day 2013 - part 2ovarene
1.1K views56 slides
Javascript engine performance by
Javascript engine performanceJavascript engine performance
Javascript engine performanceDuoyi Wu
8.1K views90 slides
Virtual machine and javascript engine by
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engineDuoyi Wu
50.9K views135 slides
Introduction aux Macros by
Introduction aux MacrosIntroduction aux Macros
Introduction aux Macrosunivalence
893 views19 slides

Similar to Yapc asia 2011_zigorou(20)

"Mobage DBA Fight against Big Data" - NHN TE by Ryosuke IWANAGA
"Mobage DBA Fight against Big Data" - NHN TE"Mobage DBA Fight against Big Data" - NHN TE
"Mobage DBA Fight against Big Data" - NHN TE
Ryosuke IWANAGA13.8K views
20th.陈晓鸣 百度海量日志分析架构及处理经验分享 by elevenma
20th.陈晓鸣 百度海量日志分析架构及处理经验分享20th.陈晓鸣 百度海量日志分析架构及处理经验分享
20th.陈晓鸣 百度海量日志分析架构及处理经验分享
elevenma1.8K views
Big Data @ Orange - Dev Day 2013 - part 2 by ovarene
Big Data @ Orange - Dev Day 2013 - part 2Big Data @ Orange - Dev Day 2013 - part 2
Big Data @ Orange - Dev Day 2013 - part 2
ovarene1.1K views
Javascript engine performance by Duoyi Wu
Javascript engine performanceJavascript engine performance
Javascript engine performance
Duoyi Wu8.1K views
Virtual machine and javascript engine by Duoyi Wu
Virtual machine and javascript engineVirtual machine and javascript engine
Virtual machine and javascript engine
Duoyi Wu50.9K views
Introduction aux Macros by univalence
Introduction aux MacrosIntroduction aux Macros
Introduction aux Macros
univalence 893 views
Origins of Elixir programming language by Pivorak MeetUp
Origins of Elixir programming languageOrigins of Elixir programming language
Origins of Elixir programming language
Pivorak MeetUp731 views
[Ruxcon 2011] Post Memory Corruption Memory Analysis by Moabi.com
[Ruxcon 2011] Post Memory Corruption Memory Analysis[Ruxcon 2011] Post Memory Corruption Memory Analysis
[Ruxcon 2011] Post Memory Corruption Memory Analysis
Moabi.com793 views
การเขียนโปรแกรมด้วยภาษา C by C Omputer R Oom
การเขียนโปรแกรมด้วยภาษา Cการเขียนโปรแกรมด้วยภาษา C
การเขียนโปรแกรมด้วยภาษา C
C Omputer R Oom288 views
การเขียนโปรแกรมด้วยภาษา C by C Omputer R Oom
การเขียนโปรแกรมด้วยภาษา Cการเขียนโปรแกรมด้วยภาษา C
การเขียนโปรแกรมด้วยภาษา C
C Omputer R Oom281 views
การเขียนโปรแกรมด้วยภาษา C by C Omputer R Oom
การเขียนโปรแกรมด้วยภาษา Cการเขียนโปรแกรมด้วยภาษา C
การเขียนโปรแกรมด้วยภาษา C
C Omputer R Oom622 views
การเขียนโปรแกรมด้วยภาษา C by C Omputer R Oom
การเขียนโปรแกรมด้วยภาษา Cการเขียนโปรแกรมด้วยภาษา C
การเขียนโปรแกรมด้วยภาษา C
C Omputer R Oom287 views
Introduction to Linux Exploit Development by johndegruyter
Introduction to Linux Exploit DevelopmentIntroduction to Linux Exploit Development
Introduction to Linux Exploit Development
johndegruyter5.3K views
MongoDB: Replication,Sharding,MapReduce by Takahiro Inoue
MongoDB: Replication,Sharding,MapReduceMongoDB: Replication,Sharding,MapReduce
MongoDB: Replication,Sharding,MapReduce
Takahiro Inoue2.2K views
Madrid Spark Big Data Bluemix Meetup - Spark Versus Hadoop @ 100 TB Daytona G... by Chris Fregly
Madrid Spark Big Data Bluemix Meetup - Spark Versus Hadoop @ 100 TB Daytona G...Madrid Spark Big Data Bluemix Meetup - Spark Versus Hadoop @ 100 TB Daytona G...
Madrid Spark Big Data Bluemix Meetup - Spark Versus Hadoop @ 100 TB Daytona G...
Chris Fregly1.2K views
[CCC-28c3] Post Memory Corruption Memory Analysis by Moabi.com
[CCC-28c3] Post Memory Corruption Memory Analysis[CCC-28c3] Post Memory Corruption Memory Analysis
[CCC-28c3] Post Memory Corruption Memory Analysis
Moabi.com2.5K views
参考書選びと迷った時の勉強法。 #antama_ws by Takahiro Yoshimura
参考書選びと迷った時の勉強法。 #antama_ws参考書選びと迷った時の勉強法。 #antama_ws
参考書選びと迷った時の勉強法。 #antama_ws
Takahiro Yoshimura642 views

More from Toru Yamaguchi

これからの Microservices by
これからの Microservicesこれからの Microservices
これからの MicroservicesToru Yamaguchi
34.5K views77 slides
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015 by
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015Toru Yamaguchi
4.8K views35 slides
Mobage Connect と Identity 関連技術への取り組み - OpenID Summit Tokyo 2015 by
Mobage Connect と Identity 関連技術への取り組み - OpenID Summit Tokyo 2015Mobage Connect と Identity 関連技術への取り組み - OpenID Summit Tokyo 2015
Mobage Connect と Identity 関連技術への取り組み - OpenID Summit Tokyo 2015Toru Yamaguchi
3.8K views29 slides
革新的ブラウザゲームを支えるプラットフォーム技術 by
革新的ブラウザゲームを支えるプラットフォーム技術革新的ブラウザゲームを支えるプラットフォーム技術
革新的ブラウザゲームを支えるプラットフォーム技術Toru Yamaguchi
4K views41 slides
技術選択とアーキテクトの役割 (要約版) by
技術選択とアーキテクトの役割 (要約版)技術選択とアーキテクトの役割 (要約版)
技術選択とアーキテクトの役割 (要約版)Toru Yamaguchi
5K views16 slides
技術選択とアーキテクトの役割 by
技術選択とアーキテクトの役割技術選択とアーキテクトの役割
技術選択とアーキテクトの役割Toru Yamaguchi
42K views90 slides

More from Toru Yamaguchi(20)

これからの Microservices by Toru Yamaguchi
これからの Microservicesこれからの Microservices
これからの Microservices
Toru Yamaguchi34.5K views
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015 by Toru Yamaguchi
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015
OAuth 2.0 Web Messaging Response Mode - OpenID Summit Tokyo 2015
Toru Yamaguchi4.8K views
Mobage Connect と Identity 関連技術への取り組み - OpenID Summit Tokyo 2015 by Toru Yamaguchi
Mobage Connect と Identity 関連技術への取り組み - OpenID Summit Tokyo 2015Mobage Connect と Identity 関連技術への取り組み - OpenID Summit Tokyo 2015
Mobage Connect と Identity 関連技術への取り組み - OpenID Summit Tokyo 2015
Toru Yamaguchi3.8K views
革新的ブラウザゲームを支えるプラットフォーム技術 by Toru Yamaguchi
革新的ブラウザゲームを支えるプラットフォーム技術革新的ブラウザゲームを支えるプラットフォーム技術
革新的ブラウザゲームを支えるプラットフォーム技術
Toru Yamaguchi4K views
技術選択とアーキテクトの役割 (要約版) by Toru Yamaguchi
技術選択とアーキテクトの役割 (要約版)技術選択とアーキテクトの役割 (要約版)
技術選択とアーキテクトの役割 (要約版)
Toru Yamaguchi5K views
技術選択とアーキテクトの役割 by Toru Yamaguchi
技術選択とアーキテクトの役割技術選択とアーキテクトの役割
技術選択とアーキテクトの役割
Toru Yamaguchi42K views
How to bake delicious cookie (RESTful Meetup #03) by Toru Yamaguchi
How to bake delicious cookie (RESTful Meetup #03)How to bake delicious cookie (RESTful Meetup #03)
How to bake delicious cookie (RESTful Meetup #03)
Toru Yamaguchi7.8K views
ngCore engine for mobage platform by Toru Yamaguchi
ngCore engine for mobage platformngCore engine for mobage platform
ngCore engine for mobage platform
Toru Yamaguchi9.8K views
mbga Open Platform and Perl by Toru Yamaguchi
mbga Open Platform and Perlmbga Open Platform and Perl
mbga Open Platform and Perl
Toru Yamaguchi1.4K views
Inside mbga Open Platform API architecture by Toru Yamaguchi
Inside mbga Open Platform API architectureInside mbga Open Platform API architecture
Inside mbga Open Platform API architecture
Toru Yamaguchi1.6K views
Introduction OpenID Authentication 2.0 Revival by Toru Yamaguchi
Introduction OpenID Authentication 2.0 RevivalIntroduction OpenID Authentication 2.0 Revival
Introduction OpenID Authentication 2.0 Revival
Toru Yamaguchi1.9K views
Introduction OpenID Authentication 2.0 by Toru Yamaguchi
Introduction OpenID Authentication 2.0Introduction OpenID Authentication 2.0
Introduction OpenID Authentication 2.0
Toru Yamaguchi1.4K views
The Security of OpenID Authentication 2.0 by Toru Yamaguchi
The Security of OpenID Authentication 2.0The Security of OpenID Authentication 2.0
The Security of OpenID Authentication 2.0
Toru Yamaguchi2.7K views
Customization of DBIC::Schema::Loader by Toru Yamaguchi
Customization of DBIC::Schema::LoaderCustomization of DBIC::Schema::Loader
Customization of DBIC::Schema::Loader
Toru Yamaguchi987 views

Recently uploaded

Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesShapeBlue
119 views15 slides
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院IttrainingIttraining
80 views8 slides
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...ShapeBlue
74 views18 slides
20231123_Camunda Meetup Vienna.pdf by
20231123_Camunda Meetup Vienna.pdf20231123_Camunda Meetup Vienna.pdf
20231123_Camunda Meetup Vienna.pdfPhactum Softwareentwicklung GmbH
46 views73 slides
Ransomware is Knocking your Door_Final.pdf by
Ransomware is Knocking your Door_Final.pdfRansomware is Knocking your Door_Final.pdf
Ransomware is Knocking your Door_Final.pdfSecurity Bootcamp
76 views46 slides
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...ShapeBlue
82 views62 slides

Recently uploaded(20)

Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates by ShapeBlue
Keynote Talk: Open Source is Not Dead - Charles Schulz - VatesKeynote Talk: Open Source is Not Dead - Charles Schulz - Vates
Keynote Talk: Open Source is Not Dead - Charles Schulz - Vates
ShapeBlue119 views
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院 by IttrainingIttraining
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
【USB韌體設計課程】精選講義節錄-USB的列舉過程_艾鍗學院
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha... by ShapeBlue
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
Mitigating Common CloudStack Instance Deployment Failures - Jithin Raju - Sha...
ShapeBlue74 views
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P... by ShapeBlue
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
Developments to CloudStack’s SDN ecosystem: Integration with VMWare NSX 4 - P...
ShapeBlue82 views
Why and How CloudStack at weSystems - Stephan Bienek - weSystems by ShapeBlue
Why and How CloudStack at weSystems - Stephan Bienek - weSystemsWhy and How CloudStack at weSystems - Stephan Bienek - weSystems
Why and How CloudStack at weSystems - Stephan Bienek - weSystems
ShapeBlue111 views
Data Integrity for Banking and Financial Services by Precisely
Data Integrity for Banking and Financial ServicesData Integrity for Banking and Financial Services
Data Integrity for Banking and Financial Services
Precisely56 views
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue by ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlueMigrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
Migrating VMware Infra to KVM Using CloudStack - Nicolas Vazquez - ShapeBlue
ShapeBlue96 views
Igniting Next Level Productivity with AI-Infused Data Integration Workflows by Safe Software
Igniting Next Level Productivity with AI-Infused Data Integration Workflows Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Igniting Next Level Productivity with AI-Infused Data Integration Workflows
Safe Software344 views
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti... by ShapeBlue
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
DRaaS using Snapshot copy and destination selection (DRaaS) - Alexandre Matti...
ShapeBlue46 views
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit... by ShapeBlue
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
Transitioning from VMware vCloud to Apache CloudStack: A Path to Profitabilit...
ShapeBlue57 views
State of the Union - Rohit Yadav - Apache CloudStack by ShapeBlue
State of the Union - Rohit Yadav - Apache CloudStackState of the Union - Rohit Yadav - Apache CloudStack
State of the Union - Rohit Yadav - Apache CloudStack
ShapeBlue145 views
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online by ShapeBlue
KVM Security Groups Under the Hood - Wido den Hollander - Your.OnlineKVM Security Groups Under the Hood - Wido den Hollander - Your.Online
KVM Security Groups Under the Hood - Wido den Hollander - Your.Online
ShapeBlue102 views
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De... by Moses Kemibaro
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Don’t Make A Human Do A Robot’s Job! : 6 Reasons Why AI Will Save Us & Not De...
Moses Kemibaro29 views
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N... by James Anderson
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
GDG Cloud Southlake 28 Brad Taylor and Shawn Augenstein Old Problems in the N...
James Anderson133 views
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava... by ShapeBlue
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
Centralized Logging Feature in CloudStack using ELK and Grafana - Kiran Chava...
ShapeBlue48 views
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f... by TrustArc
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc Webinar - Managing Online Tracking Technology Vendors_ A Checklist f...
TrustArc77 views

Yapc asia 2011_zigorou

  • 1. The case file of Mobage Open Platform Mobage Toru Yamaguchi <zigorou@cpan.org> http://d.hatena.ne.jp/ZIGOROu/ DeNA co.,ltd. 2011/10/14 YAPC Asia 2011
  • 2. !  !  !  !  ! 
  • 3. !   Wikipedia !  !  !  !  (Cause Analysis) !  (Failure Prevention) !  (Knowledge Distribution)
  • 4. ( )
  • 5. 1 DeadLock !  API (T ) Dead Lock !  API Internal Server Error !  !  !   Internal Server Error
  • 6. (1) !  API GET ! totalResults OpenSearch !  totalResults SQL_CALC_FOUND_ROWS !  SELECT !  totalResults !   INSERT, DELETE TRIGGER
  • 7. (2) !  SHOW INNODB STATUS !   Dead Lock !  !  !  UPDATE !  UPDATE ! 
  • 8. BEGIN; SELECT id FROM somedata_group WHERE name = ?; INSERT INTO somedata(id, group_id, data, published_on) VALUES(?, ?, ?, ?); UPDATE somedata_summary SET total_results = total_results + 1, updated_on = ? WHERE group_id = ?; COMMIT;
  • 9. (3) !   Group !  !  !  !  UPDATE increment !  MySQL Dead Lock
  • 10. (4) Transaction group_id = 1 Transaction group_id = 2 group_id = 3 Transaction group_id = 3 UPDATE group_id = 4 group_id = 5 Transaction
  • 11. (1) !  !  UPDATE w !  SELECT totalResults !   INSERT incr/decr QUEUE UPDATE !  totalResults !  xaicron
  • 12. (2) /* API */ BEGIN; INSERT INTO somedata(id, group_id, data, published_on) VALUES(?, ?, ?, ?); INSERT INTO somedata_summary_queue(id, group_id, affected_number, published_on); COMMIT;
  • 13. (3) /* Batch Worker */ BEGIN; SELECT id, group_id, affected_number FROM somegroup_summary_queue ORDER BY published_on ASC LIMIT 100; /* group UPDATE */ UPDATE somedata_summary SET total_results = ?, updated_on = ? WHERE group_id = ?; … DELETE somegroup_summary_queue WHERE id IN (?, ?, …, ?); COMMIT;
  • 14. (1) !  !  !  !  InnoDB QUEUE ( ) UPDATE ! 
  • 15. (2) !  ! InnoDB QUEUE INDEX !   INSERT, DELETE enqueue !  queue WHERE id !  FOR UPDATE ! 
  • 17. 2 INSERT vs DELETE !  !  !  API ( T ) !  1 INSERT !  API purge !  purge ( ) INSERT !  !  shard
  • 18. ( )
  • 20. (1) !  purge !  MASTER DELETE SLAVE ww !   DELETE !  redo SLAVE !  sleep wait DB wait !  wait !  wait !   SLAVE Seconds_Behind_Master wait !  wait
  • 21. Loop::Sustainable (1) !  ! https://github.com/zigorou/p5-loop-sustainable !  !  !  !  wait !  !  Seconds_Behind_Master !  b ry
  • 22. Loop::Sustainable (2) process process 2sec process process process 2sec process process 2sec process process 2sec Seconds_Behind_Master : 10 sec process 2sec
  • 23. (2) !  w !   SET SESSION sql_log_bin = 0 !   MASTER SLAVE DELETE !  DELETE !  prefork DELETE xaicron ( )
  • 24. (3) !  !   DELETE !   DELETE purge !  partitioning API !   STOP SLAVE DB Master !  ! 
  • 25. (1) !  DELETE !  DELETE !   DELETE SELECT !  MySQL !  !  !  RDBMS !  !   SET SESSION sql_log_bin=0 !  DELETE
  • 26. (2) !  DELETE INSERT !  Partitioning !  Sharding !  ! mysqldump –w WHERE
  • 27. (1) !  !  !  !   PRIMARY KEY !  !  ALTER TABLE some_table ADD KEY !  !  M
  • 28. (2) !  !  !  DML !  incr/decr !  ! 
  • 30. 3 !  !  !  API Push friend timeline !  DB !  API
  • 31. (1) !  !  !  !  !  count, startIndex (LIMIT/OFFSET ) ! 
  • 32. SELECT friend_user_id FROM friends WHERE user_id = ?; /* */ SELECT user_id FROM user_app WHERE app_id = ? AND user_id IN (?, ?, …, ?); /* */ SELECT SQL_CALC_FOUND_ROWS user_id, nickname FROM users WHERE user_id IN(?, ?, …, ?) LIMIT 50 OFFSET 0; SELECT FOUND_ROWS();
  • 33. LIMIT 50 valid users OFFSET 0 500 users installed users 750 users friend 1000 users
  • 34. (2) !   friends n:m, user_app 1:n, users 1:1 !   friends ( 1000 ) user_app !   users SQL_CALC_FOUND_ROWS LIMIT, OFFSET !  friends !  Temporary Table INSERT users JOIN
  • 35. (1) !  ! selectall_arrayref !  !   SQL_CALC_FOUND_ROWS !   LIMIT, OFFSET COUNT(*) !  !   Temporary Table !  !  !  user_id user_id LIMIT, OFFSET
  • 36. (2) !   prepare, fetchall_arrayref($max_rows) !   DBI::st fetchall_arrayref($max_rows) $max_rows !  !  friends 1000 !  1000 users user_app !   1000 !  1000 users !  1000 ! 
  • 37. installed users valid users friend installed users 750 users 750 users 1000 users 1000 users installed users valid users 750 users 750 users friend installed users 1000 users 1000 users 100 users installed users 750 users installed users 250 users friend 1000 users end iteration
  • 38. (3) !  !  !   Iterator::GroupedRange ! http://search.cpan.org/dist/Iterator-GroupedRange/ !  List::MoreUtils natatime I::GR (fetchall_arrayref($max_rows) )
  • 39. (4) !  !   friends DB 1000 memcached get/set ! user_app mapping memcached ( install ) !  iteration DB DB iteration set !  3 !  xaicron
  • 40. (1) !  !  !  !  w !  kazuho
  • 42. !  !  !  !  !  !  xaicron !  !  !