ããã«ã¡ã¯ãã¤ã³ãã©æ
å½æ°äººã® nob ã§ãã
ãµã¼ãã¼ç£è¦ãã¼ã«ã§ MySQL ãç£è¦ãã¦ããã®ã«ãã¼ã¿ãå¤ããã¦æ´»ç¨ãã¦ããªããã¨ããæ¹ã¯ãã¾ãããï¼ãã®è±å¯ãªãã¼ã¿ãããã©ã¼ãã³ã¹ã»ãã¥ã¼ãã³ã°ã«æ´»ç¨ããªãæã¯ããã¾ãããä»åã¯ãµã¼ãã¼ç£è¦ãã¼ã«ã®ã°ã©ããèªã¿è§£ããå®æ¦çµé¨ãå
ã«ããããã ãè¦ãã°å¤§ä¸å¤«ãã¨ãããããã¾ã¨ãã¦ã¿ã¾ããã
ããã ãè¦ãã°å¤§ä¸å¤«ï¼ãã¯ã¨ãªç·¨ãï¼ã¤ã®ã¤ã¼ã¨ï¼ã¤ã®ã°ã©ã
- ï¼ãã®ï¼ï¼ç£è¦ãã¼ã«ãä½ãè¦ã¦ããã®ãç¥ã
- ï¼ãã®ï¼ï¼ç£è¦ã®ãã¢ãã°ã©ãï¼ç¹ã»ãã (Questions, Lock Waits 㨠Transaction Handler)
- ï¼ãã®ï¼ï¼ã°ã©ãã§ãã§ãã¯ãã SQL ãã¥ã¼ãã³ã° ( Select Type 㨠Handler)
ã·ã³ãã«ã§ãå§ãããµã¼ãã¼ç£è¦ã°ã©ãåãã¼ã« Cacti
éç¨ãã¦ãããµã¼ãã¼ã«ã¯ãåç´ãªãããã¯ã¼ã¯ã®æ»æ´»ç£è¦ããå§ã¾ã£ã¦ã·ã¹ãã å
¨ä½ã®æ§è½ãç£è¦ããã¾ã§ãæ§ã
ãªãµã¼ãã¼ç£è¦ã®ã¤ã³ãã©ãå¿
è¦ã¨ãªãã¾ããæåã©ããã§ã¯ Nagios, Zabbix, Hinemos ãªã©ãããã¾ãããä»å使ã£ã¦ããã®ã¯ Cactiãhttp://www.cacti.net/ ã¨ãããµã¼ãã¼ããã©ã¼ãã³ã¹ã°ã©ãåãã¼ã«ã§ããç£è¦é
ç®ã®ã°ã©ã表示ã®ä»ããããå¤ãè¶
ããã¨ã¡ã¼ã«éç¥ããåºæ¬æ©è½ãåãã¦ãã¾ããã¾ããã³ãã¬ã¼ããèªä½ã好ã¿ã®é
ç®ãã°ã©ãã«ãããã¨ãåºæ¥ã¾ãããèªä½ãã³ãã¬ã¼ãã¯ããããããå
¥æåºæ¥ã¾ããæ©è½ãã·ã³ãã«ã§ãã®ã§ãã¤ã³ãã©ã»ã¨ã³ã¸ãã¢ã®å¥ã®ä»äºï¼éç¨ã®èªååã¨ãï¼ã«æµ®æ°ãããã¨ãªããMySQL ã®ããã©ã¼ãã³ã¹ã«éä¸åºæ¥ãã®ãããæã§ãã
ç§ã MySQL ã®ããã® Cacti ãã³ãã¬ã¼ãã¨ãã¦ä½¿ã£ãã®ã¯Â better-cacti-templates ã§ããå°å
¥ã«ã¤ãã¦ã¯ãã°ã°ãã«ã¹ http://ggrks.org/ã®è¨äºÂ cactiã®å°å
¥ã¨Apacheã¨ãMySQLã¨ãã®templateã®å°å
¥ ãªã©ãåèã«ãã¦ãã ããã
ï¼ãã®ï¼ï¼ç£è¦ãã¼ã«ãä½ãè¦ã¦ããã®ãç¥ã
ã°ã©ãã®ãã¼ã¿ãæ´»ç¨ããã«ã¯ããã¼ã¿ã®æå³ãã¤ã¾ããã¼ã¿ãã©ããã£ã¦æ¡éãã¦ããã®ã ç¥ãäºãéè¦ã§ããbetter-cacti-templates ãæ¡éãã¦ãã MySQL ãã¼ã¿ã¯ãSHOW STATUS ã³ãã³ãã§è¡¨ç¤ºããã MySQL ã®çµ±è¨æ å ±ã®é ç®ã¨ãSHOW ENGINE INNODB STATUS ã³ãã³ãã§è¡¨ç¤ºãããæç« ãå ã«ãããªãªã¸ãã«ãªé ç®ãã®ï¼æ¬ã ã¦ã§æ§æããã¦ãã¾ããCacti ã®ã°ã©ãã®æå³ãç¥ãã®ã¯
- SHOW STATUS ã®é ç®ã«åãååã®é ç®ãããããããã° MySQL ãªãã¡ã¬ã³ã¹ããã¥ã¢ã«ã§æå³ã調ã¹ã
- SHOW STATUS ã«ç¡ãå ´åã¯ãããã¯ãã³ãã¬ã¼ãã®ç¬èªé ç®ãªã®ã§ããã³ãã¬ã¼ãã®ã¹ã¯ãªããã解èªãã
ã¨ããæé ã«ãªãã¾ããbetter-cacti-templates ã®å ´åã¯ãã³ãã¬ã¼ãã®ã½ã¼ã¹ã® scripts/ss_get_mysql_stats.php ãè¦ãã¨ç¬èªé ç®ã®å 容ã®è©³ç´°ããããã¾ããä»åã®è¨äºã§åãä¸ããªãã£ã Cacti ã®ãã¼ã¿é ç®ãæ°ã«ãªã£ãæ¹ã¯ããã²ã½ã¼ã¹ã®è§£èªã«ææ¦ãã¦ã¿ã¦ä¸ããã
ï¼ãã®ï¼ï¼ç£è¦ã®ãã¢ãã°ã©ãï¼ç¹ã»ãã (Questions, Lock Waits 㨠Transaction Handler)
ã¾ãæåã¯ããã©ã¼ãã³ã¹ç£è¦ã®ãã¢ã§ããã°ã©ãã®ï¼ç¹ã»ããã§ãããã¥ã¼ãã³ã°ã¨ããããç£è¦ãç®çã®å ´åã®éè¦ãªã°ã©ãããã®ï¼ã¤ã§ããã¾ã㯠Questions ããè¦ã¦ããã¾ãã
SQL ã®ç¨®é¡ã®ã°ã©ã MySQL Command Counters
ãã®ã°ã©ãã¯ã©ããã種é¡ã® SQL æãå®è¡ããããã¾ã¨ãããã®ã§ããåä½ã¯ã¤ã³ã¿ã¼ãã«ï¼ããã©ã«ãï¼åï¼æ¯ã®åæ°ã§ãã  m ã¯ããªãã¤ã¾ã1/1000 åã§ããä¾ãã° 100 m  ã¨ããã®ã¯ãã®ï¼åéã§çºçããåæ°ã 0.1 åã¨ãããã¨ã§ã50åã§ï¼åçºçãããã¨ããäºã示ãã¦ãã¾ãã
Com 㯠Command ã®ç¥ã§ Com Select / Delete / Insert / Update / Replace ã¯ãã®ååã®ã¨ããã® SQL ã®å®è¡åæ°ã§ãã Com xxx Multi ã¨ä»ãã¦ããã®ã¯è¤æ°ãã¼ãã«ãä¸æ¬ã㦠Update ããMySQL ç¬ç¹ã®æ§æã§ããããã§æ³¨ç®ãã¹ãã¯Â Questions ã§ããMySQLãªãã¡ã¬ã³ã¹ããã¥ã¢ã«ã«ã¯ç°¡ç´ ã«ãMySQL ã¸ã®åãåããåæ°ãã¨è¨è¿°ããã¦ãã¾ãããªãã§ãã«ã¦ã³ããã¾ãããããã ãã«è¨ä¸ãããã®ã¯ SET ãªã©ã®è£å©çãªã³ãã³ãã¨ãã¨ã©ã¼å¿çã§ããSET ãæ¥ã«å¢ãããã¨ã¯ããã¾ããã®ã§ãä¸ã®ã°ã©ãã®ç¹ç·é¨ã®ããã«å¢å ããå ´åã¯ãä½ãã¨ã©ã¼ãå¢å ãã¦ãã¾ãã
ã¨ã©ã¼å
容ã®èª¿æ»ã«ã¯ã¢ããªã±ã¼ã·ã§ã³å´ã§ã®èª¿æ»ãå¿
è¦ã§ããã ã¨ãããã Questions ã ããå¢å ãã¦æ¥ãããä½ãã®æªãå
åã¨æã£ã¦ãã ããã
ããã¯å¾ ã¡æéãè¦ãã®ã«æé©Â InnoDB Current Lock Waits
ç£è¦ï¼ç¹ã»ããã®ï¼ç¹ç®ã¯ãã®ã°ã©ãã§ãããã¼ã¿ã®é
ç®ã¯Â Innodb Lock Wait Secs ã§ããããã®å¤ã¯Â SHOW ENGINE INNODB STATUS ã§è¡¨ç¤ºããããã©ã³ã¶ã¯ã·ã§ã³æ
å ±ã®ãã¡ã”TRX HAS BEEN WAITING n SEC FOR THIS LOCK TO BE GRANTED” ã® n ãã·ã¹ãã ã®ãã©ã³ã¶ã¯ã·ã§ã³å
¨é¨ã§åè¨ãããã®ã§ããããã§ããããã¯ã¯è¡ããã¯ããã¼ãã«ããã¯ã®åºå¥ã¯ããã¾ããããããã©ã¼ãã³ã¹ããã¿ãã°ããã¯å¾
ã¡ã®æéã¯ã¼ããè¯ãããã®å¤ãå¢å ãã¦ããã®ãæªãå
åã§ãã
ä¸ã®ã°ã©ãã§ã¯ãã¡ããã© Questions ã¨åãæé帯㧠Lock Waits ãä¸æãã¦ãã¾ãã表示ä¸ã®  k ã¯ããã1000 ã§ããï¼ã¤åãããã¨ã¨ã©ã¼ãå¢å ãã¦ããã¯ã®å¾
ã¡æéãå¢ãã¦ãããã¨ãªãã¾ããMySQL ã ã¨çã£å
ã«çãããã®ã¯ãããããã¯ã§ããããã®ä¾ã§ã¯ INNODB STATUS ãè¦ã¦ãè¨é²ããã¦ãã¾ããã§ããããã¦ã©ããããã®ãï¼ããã§çãã¦ããã®ã次ã®ï¼ç¹ç®ã®ã°ã©ãã§ãã
ãã©ã³ã¶ã¯ã·ã§ã³ç¶æ³ãä¸ç¥ãã MySQL Transaction Handler
ãã®ã°ã©ãã¯é
ç®ã®ååã©ããã«ã³ãããæ°ã¨ãã¼ã«ããã¯æ°ãã°ã©ãã«ãããã®ã§ããã°ã©ãç¹ç·é¨ã«ããã¾ã§ç¡ãã£ããã¼ã«ããã¯ãè¨é²ããã¦ãããã¨ããããã¾ãã
ãããããã¯ã§ã¯ãªãã¦ãä½ãã®ã¨ã©ã¼ã§ãã©ã³ã¶ã¯ã·ã§ã³ã ã¢ãã¼ããããã¨ãã¼ã«ããã¯ãçºçãã¾ãããå
ã®ã¯ã¨ãªã®ããã¯æéãï¼ãæ´æ°ãå·»ãæ»ãæéãï¼ãåå®è¡æéãããããã¨ããå
·åã«ç¡é§ã«å¦çãå¢ããããã¯ã®ç«¶å確çãããã¯å¾
ã¡ãå¢å ããã¬ã¹ãã³ã¹ãæªããªãã¾ãã
ã¨ããããã«ä»¥ä¸ï¼ç¹ã®ã°ã©ããè¦ãã°ã¯ã¨ãªã§ç°å¸¸ãçºçãã¦ããªããã©ããç£è¦ã§ãã¾ãã
ï¼ãã®ï¼ï¼ã°ã©ãã§ãã§ãã¯ãã SQL ãã¥ã¼ãã³ã° ( Select Type 㨠Handler)
MySQL ã§ã¯ã¹ãã¼ãã°ãæ´»ç¨ãã¦ãããã¡ã¤ãªã³ã°ããã®ãæå¹ã§ããã¨ããããã¼ã¿éãå°ãªãã·ã¹ãã éçºä¸ã«ã¯ã¯ã¨ãªã¯é«éã«åãã¦ãã¾ããã¹ãã¼ãã°ã«ã¯è¨é²ããã¾ãããããã§ããã« log_queries_not_using_indexes ãã»ãããã¦ãã¤ã³ããã¯ã¹ã使ã£ã¦ããªãã¯ã¨ãªãã¤ã³ããã¯ã¹ã使ã£ã¦ãã¦ãå
¨ä»¶æ¤ç´¢ãã¦ããã¯ã¨ãªãå
¨ã¦è¨é²ããããããã¥ã¼ãã³ã°ãã¾ããã¨ããããå°ãããã¼ãã«ã SELECT * FROM Table ãã¦ãããã®ã¨ããå
¨ä»¶ã³ãã¼ããããã« INSERT INTO .. SELECT … ããã£ã¦ãããã®ã¨ããããã£ã¦ã¦å
¨ä»¶æ¤ç´¢ãã¦ããã¯ã¨ãªãè¨é²ãããã®ã§ä»¶æ°ãããªãå¤ãè² è·ã«ãªãã¾ãããã®ãã log_queries_not_using_indexes ã¯æ¬çªç¨¼åæã«ã¯å¤ããããã¨ãå¤ãã§ãã
ãã¦ãéçºãæçµæ®µéã§ã¹ãã¼ãã°ã®è¨å®ãæ¬çªã¨åãã«ããã¨ãã¾ãããã¼ã¿ãå°ãªãä»ã¯ã¹ãã¼ãã°ã«ã¯ä½ãã²ã£ãããã¾ããããããã¤ã³ããã¯ã¹å¼µãå¿ããªã©ã®ãã¥ã¼ãã³ã°å¿ãã®ã¯ã¨ãªãæ®ã£ã¦ããã°ããã¼ã¿ã®å¢å å¾ã«é度ãä½ä¸ãã¦åãã¦æ°ãã¤ããã¨ã«ãªãã¾ããã¯ã¨ãªå
¨é¨ã« EXPLAIN ãå®è¡ãã¦æ¤æ»ããã¨ããã®ãç¾å®çã§ã¯ããã¾ãããåé¡ãçºçãã¦ããã§ã¯ãªããçºçããåã«æªç¶ã«å¯¾å¿ãããã¨ã¯åºæ¥ãªãã§ããããï¼ããããªã¨ãã«æ´»èºããã®ããµã¼ãã¼ç£è¦ã®ã°ã©ãã§ãã
SELECT ã®ä½¿ãæ¹ãç¥ã My SQL Select Types
ã¯ã¨ãªã®ãã¥ã¼ãã³ã°ã¯ã»ã¼ã¤ã³ã¼ã« SELECT ã®ã¿ã¤ããã¨ãããã¨ã«å°½ãã¾ããåå¥ã®ã¯ã¨ãªã«å¯¾ã㦠EXPLAIN ããããã¨ã§ã©ã®ãããªå®è¡è¨ç»ã使ã£ã¦ããã®ãç¥ãäºãåºæ¥ã¾ããããã®ã°ã©ããè¦ããã¨ã§ã·ã¹ãã åä½ã§ã©ãããã¿ã¤ãã®ãã®ãå®è¡ããã¦ããã®ãããã®å
¨ä½åãç¥ããã¨ãåºæ¥ã¾ãã
Select Scan ã¯ãã¼ãã«ï¼ã¾ãã¯ã¤ã³ããã¯ã¹ã§ãï¼ã®å
é è¡ããå
¨ä»¶æ¤ç´¢ï¼ã¹ãã£ã³ï¼ãããåæ°ã§ããSelect Range 㯠WHERE ãªã©ã®æå®ã«ãã£ã¦ç¯å²ãéå®ãããæ¢ç´¢ãè¡ã£ãåæ°ã§ããSQL ã®ãã¥ã¼ãã³ã°ã¨ãã¦ãã SELECT ã«ã¯ã¤ã³ããã¯ã¹ã使ç¨ãã¦æ¢ç´¢è¡æ°ãè¡ããã¯ã®ç¯å²ãå°ãªãããããã¨ããã®ãä¸è¬çã§ãããæå³çã«å
¨ä»¶åãåºãå¿
è¦æ§ãããã¾ããããã¹ãã£ã³ã¯ã¼ãã«ã¯ãªãã¾ãããããã§ã Select Range  >>>  Select Scan ã¨ããã®ããæã¾ããç¶æ
ã§ããä¸ã®ã°ã©ãä¾ã§ã¯å対㫠Select Scan ãå¤ããªã£ã¦ãã¾ããã¤ã³ããã¯ã¹ã使ãä½å°ã®ããã¯ã¨ãªãç¸å½æ°ãããã¨ããããã¾ãã
ããä¸ã¤ã®ãã¥ã¼ãã³ã°ã¨ãã¦ãJOIN ã¯ã¤ã³ããã¯ã¹ã§è¡ããã¨ãããã®ãããã¾ãããããã¡ããã¨å®ããã¦ãããã©ããã¯ã¤ã³ããã¯ã¹ã®ãªãã«ã©ã 㧠JOIN ããã¨è¨é²ããã Select Full Join ã¨ç¯å²æå®ã®å¹æã¯ããããã¯ãã¤ã³ããã¯ã¹ã¯ä½¿ãã JOIN ããæã®Â Select Full Range Join ï¼éã®ç¹ç·é¨ï¼ãã¿ãã¨ãããã¾ããä¸ã®ã°ã©ãã§ã¯ 139 ããªåã¨ããå°ããå¤ã§ãããããã¯ã¼ãã§ãããã¨ãç®æãã¦ããã®ã§ãè¦ããç¬éãï¼èª°ã ï¼ã¨ããå
·åã«æ°ãã¥ããã¨ãåºæ¥ã¾ãã
ã¯ã¨ãªã® I/O åä½ãç¥ããã¨ãåºæ¥ãã°ã©ã  MySQL Handlers
Handler ã¨ããã®ã¯ MySQL ã®ã¹ãã¬ã¼ã¸ã¨ã³ã¸ã³ã®ã¤ã³ã¿ã¼ãã§ã¼ã¹ã§ããã®ç¨®é¡ãè¦ããã¨ã§ InnoDB ããã¡ã¤ã« I/O ããã£ã¹ã¯ I/O ã«è¿ããã¼ã¬ãã«ã§ã©ãããä»äºããã¦ããã®ãè¦ããã¨ãåºæ¥ã¾ãã
Write, Update, Delete ã¯ååã®ã¨ããã®åä½ãªã®ã§å²æãã¦ããã¤ã³ãã¨ãªãã®ã¯ä»¥ä¸ã® Read ç³»ã®æä½ã§ãã
- Handler Read First ãã¼ãã«ãã¤ã³ããã¯ã¹ã®å ¨ä»¶æ¤ç´¢ï¼ã¹ãã£ã³ï¼ã®éã«ã¯ãã¾ãæåã«å é ã¬ã³ã¼ãã®åå¾ãè¡ãã¾ãããã®åæ°ã Read First ã§ãã
- Handler Read Key ã¤ã³ããã¯ã¹ã使ã£ã¦ããã«ç¯å²æå®ã®å¹æãå¹ãã¦ããå ´åããã¼å¤ã«åºã¥ãã¦ã¸ã£ã³ããã¦è¡ãèªã¿åãæä½ãè¡ãã¾ãããã®åæ°ã§ãã
- Handler Read Next ãã¼å¤ã«åºã¥ãã¦è¡ãç¹å®ããå¾ãå¾ç¶ã®è¡ãèªãã åæ°ã§ãã
- Handler Read Prev å 容ã¨ãã¦ã¯ Next  ã¨åæ§ã§ããã¼å¤ã§ãã¤ã³ãã決ããå¾ããã®åã®è¡ãåå¾ããæä½ã§ãã
- Handler Read Rnd InnoDB ã§ãã©ã¤ããªãã¼ã®å¤ãæå®ãã¦1è¡ãã¼ã¿ãèªã¿è¾¼ãå ´åããã£ã¹ã¯ã¸ã®ã¢ã¯ã»ã¹æ¹æ³ãã·ã¼ã±ã³ã·ã£ã«ã¢ã¯ã»ã¹ã§ã¯ãªãã©ã³ãã ã¢ã¯ã»ã¹ã¨ãããã¨ã§ãMySQL ã®ä¸çã§ã¯æ´å²çã« Random Read ã¨ããç¨èªã使ããã¦ãã¾ãããã® Handler Read Rnd ã¯ãã©ã¤ããªãã¼ãæå®ãã¦ãã³ãã¤ã³ãã«ï¼è¡èªã¿è¾¼ãã åæ°ã«ãªãã¾ãã
- Handler Read Rnd Next Read Rnd ã«ãã£ã¦ãã¤ã³ãã決ããå¾ãå¼ãç¶ãé£ç¶ãã¦è¡ãèªã¿åã£ãåæ°ã«ãªãã¾ããåç´ãªã¹ãã£ã³æä½ããã¦ãããã¨ã«ãªãã®ã§ãã¾ãå¬ãããªãåæ°ã§ãã
Handlerr Read First ã¯å
¨ä»¶æ¤ç´¢ãããï¼åããè¨ä¸ãããªãã®ã§èªã¿åãåæ°ã¨æ¯ã¹ãã¨å°ããã¦ã°ã©ãã§ã¯è¦ãã¾ããããæ°åãè¦ããã¨ã§å
¨ä»¶æ¤ç´¢ã®åæ°ã®å¾åãã¤ããã¾ããåæ§ã« Handler Read Rnd 㨠Handler Read Rnd Next ãè¦ããã¨ã§ãå
¨ä»¶æ¤ç´¢ã«ãã£ã¦èªã¿è¾¼ãã è¡æ°ããããã¾ãã
ä¸ã®ï¼ã¤ã®ã°ã©ããç·åããã¨ãå
¨ä»¶æ¤ç´¢ãã Select ã®å²åãå¤ããèªã¿è¾¼ãã è¡æ°ã®å²åã¯å°ãªãã£ããã¨ãããã¨ããããã¾ãããã®ãã¨ããããã¥ã¼ãã³ã°ããã¦ããªãã¯ã¨ãªãããªããããã®ã®ããã®æ®µéã§ã¯ãã¾ãå½±é¿ãåºã¦ããããä»å¾ãã¼ã¿éãå¢å ããã¨å½±é¿ãåºããããããªããã¨ãããã¨ã¾ã§ç¥ããã¨ãåºæ¥ã¾ãã
æå¾ã«
以ä¸ï¼ã¤ã®ããï¼ã¤ã®ã°ã©ããè¦ãã ãã§ãå®è¡ããã¦ãã SQL ã®æåãã¤ãã¿ããã©ã¼ãã³ã¹ãã¥ã¼ãã³ã°ã¸ã¨æ´»ãããã¨ãåºæ¥ã¾ãã®ã§ãã¿ãªãããæ¯éãæ´»ç¨ãã ããï¼
次åå¾ç·¨ã¯ãããã ãè¦ãã°å¤§ä¸å¤«ï¼ã¼MySQLããã©ã¼ãã³ã¹ç£è¦ã®ããï¼ã·ã¹ãã ç·¨ï¼ ãäºå®ãã¦ãã¾ãããæå¾
ãã ããï¼
ã¼ã¼ã¼ã¼
ã¤ã³ãã£ãããã«ã¼ãã§ã¯ããã°ã©ãã³ã°ãã¤ã³ãã©ã好ããã¨ããã¨ã³ã¸ãã¢ãåéãã¦ãã¾ãã詳ããã¯åéãã¼ã¸ãhttps://www.infiniteloop.co.jp/recruitment/ ã¾ã§