MySQLã§ã¹ã¬ã¼ããè¤æ°å°ä¸¦ã¹ã¦ããã
è² è·å¢å ããµã¼ãé害ã§æ°è¦ã¹ã¬ã¼ãã追å ãããã
ã§ãæ§ç¯ããã°ããã®MySQLã¹ã¬ã¼ãããããªããµã¼ãã¹ã«çªã£è¾¼ãã¨ã©ããªããã
ãããªãã®è¦æ¨¡ã®ãµã¼ãã¹ã§ããã°ãbuffer_poolã空ã£ã½ã®DBã ã¨IOãã¤ã¾ã£ã¦å¿çé
延ãçºçãã¾ãã
ã¨ããããã§ãµã¼ãã¹æå
¥åã«buffer_poolã®ã¦ã©ã¼ã ã¢ãããå¿
è¦ã§ãæ¹æ³ã¨ãã¦ã¯ããã¤ãèãããã¾ãã
åºæ¬çã«ãµã¼ãã¹æå
¥åã®å®ç§ãªã¦ã©ã¼ã ã¢ããã¯ç¡çã²ã¼ãªã®ã§ã
æ®æ®µã¯ä¸»è¦ãã¼ãã«ã®Indexãèªã¿è¾¼ãã§ãããä½ãæ¯ãåãæ¯çã§ãµã¼ãã¹æå
¥ããã£ã¹ã¯IOè¦ãªããå¾ã
ã«æ¯ãåãæ¯çãä¸ãã¦ãããã¨ãããã¨ããã¦ãã¾ããã
ããããã°ããåã«ã¨ããã¨ã³ã¸ãã¢ããã稼åä¸DBã§dumpããib_buffer_poolãæ°è¦DBã§loadãããã¨ããããªãã³ã£ãããªã¦ã©ã¼ã ã¢ããæé ãèãã¾ããã
ã©ããããã¨ãã¨ããã¨ãMySQL5.6ãã使ãã以ä¸ã®è¨å®ã¯ããç¥ããã¦ãã¦ã
innodb_buffer_pool_load_at_startup = 1
innodb_buffer_pool_dump_at_shutdown = 1
#innodb_buffer_pool_dump_pct = 100
ãã®è¨å®ãããã¨MySQLåæ¢æã«ãããã¡ãã¼ã«ã®ç¶æ
ããã³ãããèµ·åæã«ãããèªã¿è¾¼ããã¨ã§ãããã¡ãã¼ã«ã®ç¶æ
ã復æ§åºæ¥ã¾ãã
ãã®ãã³ããã¡ã¤ã«(ib_buffer_pool)ã¯ç¨¼åä¸ã®DBã§ãåå¾å¯è½ãªã®ã§ããããæ°è¦æ§ç¯ããDBã§èªã¿è¾¼ãã°ãããã¡ãã¼ã«ãæ¬çªç¨¼åä¸ã®æ¢åDBã¨åãç¶æ
ã«åºæ¥ãã¨ã
ããã¯ãªããªãæªããæé ã§ãã
ãã³ããã¡ã¤ã«ã«å
¥ã£ã¦ããã®ã¯ã主ãã¼å¤ãªã©ã§ã¯ãªãtablespace ID and page ID
ã§ãç´°ãããã¨ããããã£ã¦ãªãã§ããåå¾ããDBã¨ã¯å¥ã®DBã§ããã使ãã®ã¯ããªãä¹±æ´ãªæ°ã¯ãã¾ãã
ãã ä»èªåã主ã«ä½¿ã£ã¦ããç°å¢ã§ã¯ãããã¯ã¢ããDBããã£ã¦ãæ°è¦ã¹ã¬ã¼ãã®ãã¼ã¿ã¯å
¨ã¦ãã®DBã®EBSã®ã¹ãããã·ã§ããããä½ã£ã¦ãã¾ãã
ã¤ã¾ãå
ãã¼ã¿ã¯å®å
¨ã«åããã®ã§ããã®å¾ã®æ´æ°ã¯ã¨ãªãåããã®ã
ãªããããããããªæ°ãããã»ã»ã»
ã¾ãã¨ãããã試ãã¦ã¿ãããã¨ãããã¨ã§ãã£ã¦ã¿ã¾ããã
ã¦ã©ã¼ã ã¢ããæé
稼åä¸ã®ã¹ã¬ã¼ãã§dumpãåãã
> SET GLOBAL innodb_buffer_pool_dump_now = 1;
以ä¸ã®ã³ãã³ããå®è¡ãã¦completedã«ãªã£ã¦ãã°å®äºã
ããã¯ãã£ã¨ããéã«å®äºãã¦ããµã¼ãã¹å½±é¿ã¯å
¨ãç¡ãããã
ãã³ããã¡ã¤ã«ããããå°ããã§ãã
> SHOW STATUS LIKE 'innodb_buffer_pool_dump_status';
+--------------------------------+--------------------------------------------------+
| Variable_name | Value |
+--------------------------------+--------------------------------------------------+
| Innodb_buffer_pool_dump_status | Buffer pool(s) dump completed at 150723 15:22:44 |
+--------------------------------+--------------------------------------------------+
åºåããããã³ããã¡ã¤ã«ãæ°è¦DBã«ã³ãã¼ããã
$ ls -lh /var/lib/mysql/ib_buffer_pool
-rw-rw---- 1 mysql mysql 28M Jul 23 15:22 /var/lib/mysql/ib_buffer_pool
innodb_buffer_pool_load_at_startup =1ãè¨å®ããã¦ããã°ãmysqlãèµ·åããã ãã§ãã³ããã¡ã¤ã«ã®èªã¿è¾¼ã¿ãå§ã¾ãã¾ãã
# service mysql start
æ¢ã«mysqlãèµ·åæ¸ã¿ã§ããã°ä»¥ä¸ã®ã³ãã³ãã§loadãéå§ãã¦ãOKã
â»å¥ã®loadãèµ°ã£ã¦ããinnodb_buffer_pool_load_abort=1ã§æ¢ãã¦ããã®ã»ããããããã
> SET GLOBAL innodb_buffer_pool_load_now = 1;
以ä¸ã®ã³ãã³ãã§completedã«ãªãã°å®äºã
> SHOW STATUS LIKE 'innodb_buffer_pool_load_status';
+--------------------------------+---------------------------+
| Variable_name | Value |
+--------------------------------+---------------------------+
| Innodb_buffer_pool_load_status | Loaded 1537/2679699 pages |
+--------------------------------+---------------------------+
> SHOW STATUS LIKE 'innodb_buffer_pool_load_status';
+--------------------------------+--------------------------------------------------+
| Variable_name | Value |
+--------------------------------+--------------------------------------------------+
| Innodb_buffer_pool_load_status | Buffer pool(s) load completed at 150723 18:51:30 |
+--------------------------------+--------------------------------------------------+
æ¤è¨¼
ã¨ããæ¬çªç°å¢ã§ãã£ããå¹æãæ¤è¨¼ãã¦ã¿ã¾ããã
ã©ããç°å¢ä¾åããã«ã¤ã®ã§ç´°ãããã¨ã¯ç½®ãã¨ãã¦ã1åãã¤ã ãã¦ã©ã¼ã ã¢ããæéããµã³ãã«ã¯ã¨ãªã®å®è¡æéã測å®ãã¾ããã
- r3.2xlarge (EBSæé©åãªãã·ã§ã³ã¤ãå¿ãã¦ã)
- MySQL 5.6
- buffer_pool_size = 45G
- mysqlç¨EBS : gp2 600Gãå
¨é¨åãã¹ãããã·ã§ããããä½æ
ãµã³ãã«ã¯ã¨ãªã¯æ¬çªãµã¼ãã§tcpdumpãã¦ã¨ã£ã50ä¸è¡ã®SELECTã§ãã
$ egrep '^SELECT' /tmp/select.sql | wc -l
504316
å®è¡æéã¯åç´ã«1並åã§æµãè¾¼ãã§æ¸¬å®ãã¾ããã
$ time mysql -uxxx -p'xxxx' db_name < /tmp/select.sql > /dev/null
æ¯è¼ã¨ãã¦ããã¤ããã£ã¦ã主è¦ãã¼ãã«ã®Indexã®èªã¿è¾¼ã¿ã¦ã©ã¼ã ã¢ãããåããã¦å®æ½ãã¾ãã
$ innodb-warmer -u xxx -p 'xxxxx' -d db_name -t comments,articles,...
innodb-warmerã³ãã³ãã¯@songmuããã®MySQL::Warmerã@sgwr_dtsãããrubyã§æ¸ããªããããã®ã§ããå
¬éããã¦ãã£ããªã»ã»ã»
çµæ
warmupæ¸ã¿ã®EBSã§æ¤è¨¼ãã¦ã¿ãã¨ãããªæãã
|
ã¦ã©ã¼ã ã¢ãã |
ãµã³ãã«ã¯ã¨ãªå®è¡ |
æ¢å稼åä¸ãµã¼ããæ¯ãåãå¤ã㦠|
- |
2m36s |
ã¦ã©ã¼ã ã¢ããç¡ã |
0 |
8m42s |
innodb-warmerã§ä¸»è¦ãã¼ãã«ã温ãã |
66m14s |
4m15s |
å¥ãµã¼ãããbuffer_poolãdumpãã¦load |
33m ã¨å°ã
(dump&scp) |
2m38s |
å¥ãµã¼ãããbuffer_poolãdumpãã¦loadããå ´åã®ã¦ã©ã¼ã ã¢ããæéã¯30åå¼·ã§ãæ¤è¨¼ã¯ã¨ãªã®å®è¡æéã¯æ¬çªç¨¼åä¸ã®ãµã¼ãã¨åç¨åº¦ã«éãã£ãã§ãã
ã©ã¡ããIndexèªã¿è¾¼ã¿æ¹å¼ã«æ¯ã¹ãã¨ããªãåªç§ã
wamupç¡ãã®EBSã ã¨ã©ããªãã
|
ã¦ã©ã¼ã ã¢ãã |
ãµã³ãã«ã¯ã¨ãªå®è¡ |
innodb-warmerã§ä¸»è¦ãã¼ãã«ã温ãã |
4h9m |
24m41s |
å¥ãµã¼ãããbuffer_poolãdumpãã¦load |
7h37m |
2m49s |
ã¦ã©ã¼ã ã¢ããã®æéããã®ããããããã»ã»ã»
ãã®ç¶æ
ã®DBãå®éã«ãµã¼ãã¹ã«æå
¥ãã¦ã¿ã¾ãã
ã¬ããªã±ã¼ãåãã¤ã¤ã»ãã®å°ãã¯ã¨ãªæµããã¨ããããã50%->100%ã¨æ¯ãåãã«å
¥ãã¦ããã¨ã
èªã¿è¾¼ã¿ã®IOPSã¯ãããªãã
éããµã¼ãã¹ç¨¼åä¸ã®æ¢åDBã赤ããinnodb-warmerã§ä¸»è¦ãã¼ãã«ã温ãããã®ãã¤ãç·ããå¥ãµã¼ãããbuffer_poolãdumpãã¦loadãã
ç·ã®ãã£ã¹ã¯èªã¿è¾¼ã¿ãçæéã§æ¬çªDBã¨åç¨åº¦ã«ãªãã®ã«å¯¾ãã赤ã¯ã ãã¶æéãããã£ã¦ãã¾ãã
ãã¼ããã£ã¡ã®çµæã¯EBSã®ã¦ã©ã¼ã ã¢ããã¯ããã¸ãã ãªã¨ããæå³ãããªãããªã
EBSã®ã¦ã©ã¼ã ã¢ãããããã¡ãã£ã¨ãªãã¨ããªããªãããªãã»ã»ã»
ã¾ã¨ã
æ¤è¨¼ããæ¡ä»¶ã§ã¯ãib_buffer_poolãå¥ãµã¼ãããæã£ã¦ãã¦loadããã®ã¯InnnoDBã®ã¦ã©ã¼ã ã¢ããæé ã¨ãã¦ãªããªãåªç§ãªããã«è¦ããã®ã§ãç¶æ³ã«å¿ãã¦ä½¿ã£ã¦ãããã¨æãã¾ãã
ãã ãã®æ¹æ³ãæ±ç¨çã«ä½¿ããã®ãã¨ããã¨çåãããã®ã§ãããã³ããå¥ã®æ¤è¨¼çµæãããã°ãã²è¦ããã§ãã