ãã§ã¤ã¹ããã¯æ¾ä¿¡ããã解説ï¼Facebookã¯ãã¼ã¿ãã¼ã¹ãInnoDBããMyRocksã¸ç§»è¡ä¸
ã2017å¹´6æ16æ¥ãã2æ¥éãã¤ã³ãµã¤ããã¯ããã¸ã¼ã¯db tech showcase OSS 2017ãéå¬ããã2æ¥ç®ã«ã¯ãã§ã¤ã¹ããã¯ã®æ¾ä¿¡åç¯æ°ãFacebookã§ç¨ãã¦ãããã¼ã¿ãã¼ã¹ã«ã¤ãã¦è§£èª¬ããã
ãä¸çä¸ã®ã¦ã¼ã¶ã¼ãããããæ å ±ãå ±æãã¦ããFacebookãã¦ã¼ã¶ã¼ã®æç¨¿ãããããï¼ããªã©ã®ã¢ã¯ãã£ããã£ã¯ã¡ã¤ã³ãã¼ã¿ãã¼ã¹ã®MySQLã«å»ã ã¨æ¸ãè¾¼ã¾ãã¦ãããå社ã¯ãã®MySQLããã³ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³InnoDBã«æ§è½ãé«ããããã®ç¬èªã®æ¹è¯ãå ããæ¥ã éç¨ãã¦ããã
ããµã¤ãã§ã¯å¸¸ã«å¤§éã®æ¸ãè¾¼ã¿ãçºçãã¦ãããã¼ã¿ã¯ãã¿ãã¤ãç´ãè¨å¤§ãªå¦çãã¾ããªãããã«å¤§éã®ãµã¼ãã¼ã§ã·ã£ã¼ãã£ã³ã°ï¼åæ£ï¼ããã¦ãããã¾ãMySQLãã¼ã¿ãã¼ã¹ã®åã«ãã£ãã·ã¥ãç½®ããå¤ãã®èªã¿è¾¼ã¿ã¯ãã£ãã·ã¥ã§ããããã¦ããå¿çãè¿ããããã«ãã¦ããã
ãã¡ã¤ã³ãã¼ã¿ãã¼ã¹ã®ã¹ãã¬ã¼ã¸ã«ã¯ãã©ãã·ã¥ã¹ãã¬ã¼ã¸ï¼SSDï¼ã使ç¨ãSSDã¯é«ãIOPSæ§è½ãåºãããã®ã®ãä¾¡æ ¼ã¯ãã¾ã ã«HDDãããé«ãããªã«ããå°æ°ãå端ãªãã®ã§ãã¹ãã¬ã¼ã¸ä½¿ç¨éï¼ã¹ãã¼ã¹ï¼ãå°ãã§ãæ¸ãããã¨ãã§ããã°ãã³ã¹ã忏ã«è²¢ç®ãããããã¯ãã§ã¤ã¹ããã¯ã«ããã¦é·å¹´åªå 度ãé«ã課é¡ã¨ãªã£ã¦ããã
ãããã¾ã§ã¯MySQLã®ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã¯InnoDBã§éç¨ãã¦ãããããããã¹ãã¬ã¼ã¸ä½¿ç¨ã«é¢ãã¦InnoDBãªãã§ã¯ã®èª²é¡ãæ±ãã¦ãããä¾ãã°èé害æ§ãé«ããããã«äºéã«æ¸ãè¾¼ãå¦çï¼Doublewriteï¼ããã¼ã¿ã®ãã©ã°ã¡ã³ãã¼ã·ã§ã³ï¼æçåï¼ããã¼ã¿å§ç¸®ã§ãã¼ã¿ãµã¤ãºã縮å°ãã¦ãã¾ã ã¹ãã¬ã¼ã¸ä½¿ç¨ã¹ãã¼ã¹ã«åé·ããæ®ããªã©ãInnoDBã§ã¯ã¹ãã¬ã¼ã¸ä½¿ç¨éãå¢ãã¦ãã¾ããã¡ãªæ§è³ªããã£ãã
RocksDBãå¹çããã¹ãã¬ã¼ã¸ã使ããçç±
ãããã§ãã§ã¤ã¹ããã¯ã§ã¯ã¹ãã¬ã¼ã¸å¹çãé«ãLevelDBã«ç®ãã¤ãããããã¯Googleãéçºããé層åããããã¼ããªã¥ã¼åNoSQLãã¼ã¿ãã¼ã¹ã§ãC++ã§æ¸ããã¦ããããã®LevelDBãFacebookã§ä½¿ããããã«æ¹è¯ããã®ãRocksDBãLevelDBããè¦ãã°ãã©ã¼ã¯ã¨ãªãã
ãããã«RocksDBãMySQLã®ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã¨ãã¦ä½¿ããããã«ããã®ãMyRocksï¼http://myrocks.io/ï¼ãã¹ãã¬ã¼ã¸å¹çã®é«ããæã¡ã¤ã¤ãSQLãã¬ããªã±ã¼ã·ã§ã³ãªã©MySQLã®æ©è½ãå©ç¨ã§ããããã§ã¤ã¹ããã¯ã¯MyRocksã2016å¹´ã«ãªã¼ãã³ã½ã¼ã¹ã¨ãã¦GitHubã§å ¬éããä»ã§ã¯æ¬çªã§ãä¸é¨éç¨ãã¦ããã
ãRocksDBã¯HBaseãCassandraã®ãããªLSMï¼Log Structured Mergeï¼æ§é ããã¦ãããæ§æè¦ç´ ã¨ãã¦ã¯ä¸»ã«MemTableãWALï¼Write Ahead Logï¼ãå§ç¸®ãã«ã©ã ãã¡ããªã¼ãããªããæ¸ãè¾¼ã¿ãã³ããããããã¨ãã¾ãã¯WALã«æ¸ãè¾¼ã¿ãæ¬¡ã«æ¸ãè¾¼ã¿ãä¿æããMemTableã«æ¸ãè¾¼ãã両æ¹ã«æ¸ãè¾¼ãããæ¸ãè¾¼ã¿æåãã¢ã¯ãã£ããªMemTableããã£ã±ãã«ãªãã¨MemTableã¨WALãæ°ããåãæ¿ãããMemTableãã¡ã¢ãªã«ä¸å®éãã¾ãã¨ããã¼ã¿ãã¡ã¤ã«ã«æ¸ãåºãï¼ãã©ãã·ã¥ããï¼ããã®ãã¼ã¿ãã¡ã¤ã«ã¯ããã«ä½æ®µéãå§ç¸®ãã¦å®¹éãæ¸ãããã¹ãã¬ã¼ã¸ã®ä½¿ç¨ã¹ãã¼ã¹ãæãã¦ããã
ãWALï¼ãã°ï¼ãMemTableãä¸å®éã«éããã¨æ¸ãåºããã¼ã¿ãã¡ã¤ã«ã¯SSTï¼Sorted String Tableï¼ã¨å¼ã°ãã使æã«ã½ã¼ãã¨å§ç¸®ãããããã®SSTãä¸å®éãã¾ãã¨ãã¼ã¸ãã¦ãã大ããªSSTãä½ãããã®æãå ¨ä½ã§ã½ã¼ãã¨å§ç¸®ãè¡ãããã
ãInnoDBã ã¨ãã¼ã¿ã¯16KBã®ãã¼ã¸åä½ã¨ãªããå§ç¸®ãã¦5KBã«ç¸®å°ã§ããã¨ãã¦ããå®éã«ã¹ãã¬ã¼ã¸ã§ä½¿ç¨ããã¹ãã¼ã¹ã¯8KBã«ãªããªã©ãéå¹çããããã䏿¹RocksDBã®SSTãã¡ã¤ã«ã¯32MBã64MBãªã©å¤§ããªãµã¤ãºã¨ãªããè¤æ°ã®SSTãã¡ã¤ã«ãã¾ã¨ãã¦å§ç¸®ãã¦ç¸®å°ãã¦æ¸ãè¾¼ãæã«ã¯OSã®ã»ã¯ã¿åä½ï¼4KBãªã©ï¼ã¨ãªãã®ã§ãInnoDBã»ã©åé·ã«ãªããªãããããå§ç¸®å¹çãããã¨ãããçç±ã ã
ãã¾ãRocksDBã§å¤§ããªç¹å¾´ã¨ãªãã®ãé層åã ãLevelDBã®ç±æ¥ã§ãããããã®é層åã¨ã¯å è¿°ããããã«ãSSTãã¡ã¤ã«ãã¾ã¨ããæ®µéã®ãããªãã®ãæåã«MemTableããSSTã使ããæï¼ã¬ãã«0ï¼ã¯ãã¾ã大ãããªãããã¾ã¨ããï¼ã¬ãã«1ï½ï¼ãã³ã«ç´10åã»ã©å·¨å¤§åããã
ãæ¸ãè¾¼ã¿å¹çã¯ãããã®ã®ãç¯å²æ¤ç´¢ã®ãããªèªã¿è¾¼ã¿ã§ã¯è¤æ°ã®ã¬ãã«ã«ãã¼ã¿ã忣ããå¯è½æ§ããããInnoDBã»ã©å¹çã¯ãããªããèªã¿è¾¼ã¿æã®éå¹çããé²ã対çã¨ãã¦ããã«ã¼ã ãã£ã«ã¿ã¼ãããããã«ã¼ã ãã£ã«ã¿ã¼ã¯æ¢ãã¦ãããã¼ã¿ãã©ã®ã¬ãã«ã«åå¨ãããè¦åããããããã«ãªã£ã¦ããã
ãç¹°ãè¿ãã«ãªãããRocksDBã¯ã¹ãã¬ã¼ã¸ã®ä½¿ç¨å¹çã¯åªãã¦ããï¼ãã¾ãã¹ãã¼ã¹ã使ããªãã¦ããï¼ããã ãèªã¿è¾¼ã¿æã¯å¤å°ä¸å©ã¨ããç¹å¾´ãããã
