ã«ã¸ã¥ã¢ã«ï¼(æ¨æ¶)
ãã®ã¨ã³ããªã¯ MySQL Casual Advent Calendar 2011 ã®18æ¥ç®ã®è¨äºã§ãã
æãå°ã PostgreSQL ã使ã£ã¦ããé ãMySQL ã®ã¯ã¨ãªãã£ãã·ã¥ã£ã¦ç°¡åã«æ§è½ä¸ãããã¿ããã ã羨ã¾ãããªããã¨æã£ã¦ãã¾ããããã®ããã1å¹´ã»ã©åããæ¥å㧠MySQL ã使ãããã«ãªã£ã¦ããã¯ã¨ãªãã£ãã·ã¥ã¯å½ç¶ã®ãã¨ãæå¹ã«ãã¦ããã¾ããã
ã¨ãããå æ¥ DSAS開発者の部屋:クエリキャッシュは切ったほうがいいんじゃなイカ? ã¨ããã¨ã³ããªãèªã¿ã¾ãã¦ãã¯ã¨ãªãã£ãã·ã¥ã¯ã°ãã¼ãã«ããã¯ãç²å¾ããã¨ã®ãã¨ãããã¯ã¡ãã£ã¨æ¤è¨¼ãã¦ã¿ãªããã°ãªãã¾ããã¨ãããã¨ã§ãã³ããã¼ã¯ããã¦ã¿ã¾ããã
ãã³ããã¼ã¯çµæ
ãã£ããã¨èª¬æãã¾ãã¨ã
- å¹³å 260 byte/è¡ã100ä¸è¡ã® InnoDB ãã¼ãã«ã«å¯¾ãã¦
- 主ãã¼ã«ãã 1è¡ selectãã»ã«ã³ããªã¤ã³ããã¯ã¹ã«ããå¹³å16è¡ã® select (light query)
- ä¸è¨ã«10%ã®å²åã§ãã»ã«ã³ããªã¤ã³ããã¯ã¹ã§ã® 6ä¸è¡ count(*) ãæ··ãã (heavy query)
ãå®è¡ããå ´åã® qps (query per second) ãã¹ã³ã¢ã¨ãã¾ããã¡ãªã¿ã« InnoDB buffer pool 2GB ã§ããã¼ã¿ã¯å ¨ã¦ buffer pool ã«ä¹ãåã£ã¦ããç¶æ ã§ãã
ãã©ã¡ã¼ã¿ã¯ä»¥ä¸ã§ãã
- ã¯ã¨ãªãã£ãã·ã¥ : æå¹ | ç¡å¹
- ã¯ã©ã¤ã¢ã³ãæ° : 4 | 8 | 16 | 32 | 64
- åæã«ãã¼ãã«ã«æ´æ° : æããªã | 0.1ç§ãã¨ã«1è¡update
èå¯
çµæãè¦ã¦ããã¾ãã
ã¤ã³ããã¯ã¹ã使ã£ã¦å°æ°ã®è¡ã select ããã ãã®å ´åã(light query)
ã¯ã¨ãªãã£ãã·ã¥æå¹ã§ãã¼ãã«ã«æ´æ°ããªãå ´åã並å度ãä¸ãã¦ãã£ã¦ãæ§è½ã伸ã³ã¾ããã32, 64並åã§ã¯ç¡å¹ã®å ´å㯠10,000 qps ç¨åº¦ãæå¹ã 㨠5,000 qps ã«éããåå以ä¸ã®ã¹ã³ã¢ã§ãã
æå¹ã§ä¸¦å度ãä¸ãããã³ããã¼ã¯ä¸ã« SHOW PROCESSLIST ãè¦ããã¨ãState ã "Waiting for query cache lock" ã¨ãªã£ã¦ããè¡ã大éã«åå¨ãã¦ãã¾ããã
ãã ããæå¹ã®å ´åã§ãã0.1ç§ãã¨ã« update ãæããã¨ã¹ã³ã¢ãä¸ãã£ã¦ãã¾ãã
次ã«ãrow examined 60000 ç¨åº¦ã®éãéç´ã¯ã¨ãªãæ··ããå ´åã(heavy query)
ã¯ã¨ãªãéããããæ´æ°ããªããã°ãã£ãã·ã¥ãæå¹ã«ä½ç¨ããã¹ã³ã¢ãä¸ããã¾ãããã ããå½ç¶ã§ããæ´æ°ãåæã«æããã¨ãã£ãã·ã¥ã«ã»ã¨ãã©ãããããªããªããããç¡å¹ã®æã¨åçã«ãªã£ã¦ãã¾ãã¾ãã
çµè«
ã¨ãããã¨ã§ãã¯ã¨ãªãã£ãã·ã¥ãæå¹ã«ãã¦ããã¨ããã£ã¦æ§è½ãè½ã¡ããã¨ããããã¨ããçµè«ã§ãã
ãã¡ããã¦ã¼ã¹ã±ã¼ã¹ã«ãã£ã¦ããã¾ãæ´æ°ã®æãããªã DB ã«éãã¯ã¨ãªãæãããããªå ´åã«ã¯å¹æçã«ä½ç¨ãããã¨ã¯ããã¨æãã¾ãã
ãã¦ããã®çµæãè¸ã¾ãã¦ãã¨ããå®éç¨ä¸ã® DB ãã¯ã¨ãªãã£ãã·ã¥æå¹ããç¡å¹ã«å¤æ´ãã¦ã¿ã¾ãããæ¯è¼çæ´æ°ã®å¤ã使ãããã§ãã
- select 1000qps, insert 100qps, update 300qps
- ã¯ã¨ãªãã£ãã·ã¥ãããç 50% ç¨åº¦
- ãã¼ã¿ã¯å ¨ã¦ InnoDB buffer pool ã«ä¹ããµã¤ãº
ã¯ã¨ãªãã£ãã·ã¥ãç¡å¹ã«ããã¨ããã
- CPU (user) 使ç¨çã 2/3 ã«ä½ä¸ (3%â2%ãç¨åº¦ã§ããâ¦)
- Threads_running ã平常æ 1ã2ç¨åº¦ãªã®ã«ææ 50ç¨åº¦ã«è·³ãä¸ããç¾è±¡ã解æ¶
ã¨ããæ¹åãå¾ããã¾ããã
ã¾ããslow query log ã«é常æã¯æ°msecã§çµæã®è¿ãã¯ã¨ãªãã以ä¸ã®ããã« 100msec ç¨åº¦æãã£ã¦ããã¨ããä¸å¯©ãªç¾è±¡ãåºã¦ãã¾ããããããã¯ã¨ãªãã£ãã·ã¥ãç¡å¹ã«ããã¨ããã±ã£ããã¨æ¢ã¿ã¾ããã
Query_time: 0.102920 Lock_time: 0.050687
ç¹å®ãã¼ãã«ã§ããªããç¹å®ã¯ã¨ãªã§ããªãããããè¨ã£ãããã« Query_time: 0.1+α, Lock_time: 0.05+α ã¨ããé常ã«æ°æã¡æªã (ä¸ã« 100ms ãæããã®ã§æ§è½çã«å¤§åé¡) ãªç¾è±¡ã ã£ãã®ã§ãããã¾ããã¯ã¨ãªãã£ãã·ã¥ãç¡å¹ã«ãã¦ç´ãã¨ã¯ã
query cacheãªãã¦ãããªãã£ãããï¼ã£ã¦ããã
ææ¥ã¯ @n0ts ããã§ãï¼