ã¯ããã«
XTechã°ã«ã¼ã Advent Calendar 2021ã®16æ¥ç®ã¯ãiXITæ ªå¼ä¼ç¤¾ ã¨ã³ã¸ãã¢ã®è¦åããéããã¾ãã
æè¿ããã£ã¦ãããã®ã¯é³æ¥½ç³»Vtuberã§ããVIRTUAFREAKè¯ãã£ãâ¦ã
æ¬é¡
ãã¼ã«ãªã©ãå°å
¥ããªãã¦ãSlowQueryã解æã§ããæ©è½ãMySQLã«ã¯åå¨ããã®ã§ãä»åã¯ãã®ä¸é¨ãç´¹ä»ãã¾ãã
ã¡ãªã¿ã«ç§ãéçºãã¦ãããµã¼ãã¹ã®MySQLãã¼ã¸ã§ã³ã¯5.6ã§ãã
1. mysqldumpslow
ä¸è¨ã§è¨ãã¨ã¹ãã¼ã¯ã¨ãªã¼ãã°ãã¡ã¤ã«ã解æãã¦å
容ã®ãµããªã¼ãåºåãã¦ãããæ©è½ã§ãã
åæã¨ãã¦ã¹ãã¼ã¯ã¨ãªã¼ãã°ãåºåãã¦ããå¿
è¦ãããã¾ãã
使ãæ¹
ã³ãã³ã
â»åè¨å®è¡æéãé·ãé ã«10件ã®SQLãåºåãã
mysqldumpslow -s at -t 10 /opt/fio1/slog/sp-prd-db1-slow.log
åºåä¾(1件):
Count: 23 Time=0.12s (2s) Lock=0.00s (0s) Rows=1.0 (23), host SELECT COUNT(*) FROM `user` WHERE user.STATUS=N AND (user.ACCESS_DATE>='S' AND user.ACCESS_DATE<='S')
æ¬å®¶ã®ããã¥ã¢ã«
å¼ãµã¼ãã¹ã§ã¯0.1ç§ä»¥ä¸ã®SQLãã¹ãã¼ã¯ã¨ãªã¼ãã°ã«åºåãã¦ããã
1æéæ¯ã®ãµããªã¼ãã¡ã¼ã«ã¨slackã«éããã¦ãã¾ãã
åºæ¬çã«ã¯mysqldumpslowã®åºåã«ããä¸ä½ã®SQLãããã¥ã¼ãã³ã°ãã¦ããã°ããã®ã§ãéå®ããã¨æãã¾ãã
2. performance_schema
ä¸è¨ã§è¨ãã¨ããã©ã¼ãã³ã¹ã¢ãã¿ãªã³ã°ç¨ã®ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã§ãã
MySQL5.6ã§å¼·åãããããã©ã«ãã§ä½¿ç¨ãããããã«ãªãã¾ããã
MySQL5.7ã§ãã£ã¨å¼·åãããã®ã§ãããæ®å¿µãªããå¼ãµã¼ãã¹ã®MySQLã®ãã¼ã¸ã§ã³ã¯5.6ã§ãã
performance_schemaã使ãã°SlowQueryã§ã¯å¯è¦åãããªã
- ãã©ã³ã¶ã¯ã·ã§ã³ã®å®è¡æé
- ä¸åã®å®è¡æéã¯çããã大éã«å®è¡ãã¦å¡µç©ã«ãªã£ã¦ãããã®
ãªã©ãåå¾ã§ãã¾ãã
使ãæ¹
MySQL5.5以ä¸ã使ç¨ãã¦ããã¨ãperformance_schemaã¨ãããã¼ã¿ãã¼ã¹ãåå¨ãããã¨æãã¾ãã
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | mysql | | performance_schema | | hoge | +--------------------+ 6 rows in set (0.00 sec)
mysql> show tables; +----------------------------------------------------+ | Tables_in_performance_schema | +----------------------------------------------------+ | accounts | | cond_instances | | events_stages_current | | events_stages_history | | events_stages_history_long | | events_stages_summary_by_account_by_event_name | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | table_io_waits_summary_by_index_usage | | table_io_waits_summary_by_table | | table_lock_waits_summary_by_table | | threads | | users | +----------------------------------------------------+ 52 rows in set (0.00 sec)
performance_schemaãã¼ã¿ãã¼ã¹å
ã«ã¯ãã¼ãã«ã大éã«ããã®ã§ããã
ããããã©ããªãã¼ãã«ãªã®ãã¯ä»¥ä¸ã®ããã¥ã¡ã³ããåç
§ãã¦ãã ããã
performance_schemaã¯ç§ããã¾ã触ãã¦ããªãã®ã§ãè¯ãããªè¨äºãããã¤ãç´¹ä»ãã¾ãã
æ¬å®¶ã®ããã¥ã¢ã«
æå¾ã«
ã©ã¡ããã¨ã£ã¤ããããã¯ãã«ã¤ãã§ããã
è¦ã¦ã¿ãã ãã§ãé¢ç½ãã¨æãã¾ãã®ã§ã
ç¥ããªãã£ãï¼ã¨ããæ¹ã¯ãã²ãèªèº«ã®ãµã¼ãã¹ã§éãã§ã¿ã¦ãã ããã