[MySQL] time out(wait_timeout) °è»ê°ú ¼³Á¤
Á¶È¸ : 429 À̸§ : ºÒ¹Ù´Ù
E-mail :
[MySQL] time out(wait_timeout) °è»ê°ú ¼³Á¤

- ÀÛ¼ºÀÚ : ±èÄ¥ºÀ
- ÀÛ¼ºÀÏ : 2003-08-11(º¸¿Ï, ±×·¡ÇÁ Ãß°¡)
2003-08-04
- ³» ¿ë : life time °è»ê¿¡ ÀÇÇÑ wait_timeout ¼³Á¤
- ¼ö ÁØ : ÃÊÁß±Þ ÀÌ»ó
- Å°¿öµå : MySQL, wait_timeout, interactive_timeout, connect_timeout,
max_connections, Aborted_clients, Connections,
Max_used_connections, Slow_queries, Questions, Uptime

*ÁÖ1)
ÀÌ ¹®¼­¿¡ ´ëÇÑ ÃֽŠ³»¿ëÀº ¾Æ·¡ URL¿¡¼­ È®ÀÎÇÒ ¼ö ÀÖ½À´Ï´Ù.

http://www.linuxchannel.net/docs/mysql-timeout.txt

*ÁÖ2)
ÀÌ ¹®¼­¿¡¼­ »ç¿ëÇÑ life time, EXP, CUR, PAS, POL, DEF, LPT ... ¿Í °°Àº
¿ë¾î´Â ÇÊÀÚ°¡ ÀÚÀÇÀûÀ¸·Î ºÙÀÎ °¡Äª¿ë¾î·Î½á °ø½ÄÀûÀÎ ¿ë¾î°¡ ¾Æ´Õ´Ï´Ù.

---------------------------------------------------------
¸ñÂ÷

0. ¹è°æ

1. MySQLÀÇ time out
1-1. connect_timeout
1-2. interactive_timeout
1-3. wait_timeout

2. ¿¬°á Ãë¼ÒÀ²(POC)°ú connection life time
2-1. ¿¬°á Ãë¼ÒÀ²(POC)
2-2. connection life time

3. ÀÓ°è life time
3-1. ÇöÀç ÃÖ´ë(ÃÖ¾Ç) ¿¹»ó ÀÓ°è life time (EXP)
3-2. ÇöÀç Æò±Õ ÀÓ°è life time (CUR)
3-3. Áö³­ °ú°Å ÃÖ´ë ÀÓ°è life time (PAS)
3-4. Áö³­ °ú°Å À¯Ãß ÃÖ´ë ÀÓ°è life time (POL)

4. ÀÓ°è life time(LPT) °è»ê(¿¹Á¦)

5. wait_timeout °è»ê ¹× º¸Á¤

6. °á°ú È®ÀÎ

7. Èıâ
---------------------------------------------------------


0. ¹è°æ

¾ÆÁÖ ¹Ù»Û MySQL ¼­¹ö¿¡¼­´Â °£È¤ 'Too many connections' À̶ó´Â ¿¡·¯¸¦ ¸¸³¯
¼ö ÀÖÀ» °Ì´Ï´Ù.

´ëºÎºÐ ÀÌ ¿¡·¯¸¦ ÇØ°áÇϱâ À§Çؼ­,

- max_connections
- wait_timeout

ÀÌ µÎ°³ÀÇ ÆĶó¸ÞÅ͸¦ Æ©´×Çϸ鼭 ¼³Á¤ÇÏ´Â °ÍÀÌ ÀϹÝÀûÀÔ´Ï´Ù.

±×·±µ¥, MySQL ¸Å´º¾ó¿¡´Â ÀÌ ¿¡·¯¿¡ ´ëÇÑ ÀÚ¼¼ÇÑ ¼³¸íÀÌ ºüÁ® ÀÖ½À´Ï´Ù.

¿¹¸¦µé¾î, ½ÇÁ¦ Max_used_connections ÀÌ ÇÑ°è max_connections ¿¡ µµ´ÞÇÏÁö ¾Ê¾Ò´Âµ¥µµ
ºÒ±¸ÇÏ°í ÀÌ·± ¿¡·¯¸¦ ¸¸³ª¸é »ó´çÈ÷ ³­Ã³ÇÕ´Ï´Ù.

ÀÌ·± °æ¿ì´Â ´ëºÎºÐ max_connections °ªÀ» ¿Ã¸®°í, wait_timeout °ªÀ» ÁÙ¿©¼­ Æ©´×
ÇÏ°ï ÇÏÁö¸¸ ¿ª½Ã Á¤È®ÇÑ Æ©´×ÀÌ ¾î·Æ½À´Ï´Ù.

½ÇÁ¦·Î Á»´õ Á¤È®ÇÏ°Ô Æ©´×Çϱâ À§Çؼ­´Â,

- ½Ã½ºÅÛ Àüü »óȲ(½ÇÁ¦ ¾î´À Á¤µµ·Î ¹Ù»ÛÁö¿¡ ´ëÇÑ »ó´ëÀû ¼öÄ¡),
- ÃÊ´ç connections ¼ö,
- Ä¿³Ø¼Ç´ç Æò±Õ Äõ¸® ¿äû¼ö,
- Ä¿³Ø¼Ç´ç »ý¼ºµÈ Æò±Õ ¾²·¹µå ¼ö
- ÃÊ´ç Æò±Õ Àü¼Û·®
- DISK¿¡ »ý¼ºµÈ Àӽà Å×ÀÌºí »ý¼º ºñÀ²
- Slow_queries
- ÇÑ°è µµ´Þ N ÃÊ °è»ê
- Ä¿³Ø¼Ç life time

ÀÌ·± °ªµéÀ» °è»ê ¹× °í·ÁÇÏ¿©,

- max_connections
- wait_timeout
- back_log
- thread_cache_size
- key_buffer_size
- record_buffer (read_buffer_size)
- record_rnd_buffer
- sort_buffer_size
- ±âŸ ¸Þ¸ð¸® ¼³Á¤

ÀÌ·± ÆĶó¸ÞÅÍ¿¡ ¼³Á¤À» ÇØÁà¾ß ÇÕ´Ï´Ù.

½ÇÁ¦ MySQL ¼­¹öÀÇ ÆĶó¸ÞÅÍ ¼³Á¤Àº,

1) »ç¿ë°¡´ÉÇÑ ÃÖ´ë Àüü µ¥ÀÌÅͺ£À̽º Å©±â¿Í °¢ Å×À̺í Æò±Õ Å©±â °è»ê
2) MySQL ÀÌ »ç¿ëÇÏ´Â ½Ã½ºÅÛ ¹°¸®Àû ¸Þ¸ð¸® Å©±â
3) 1)¿¡ ÀÇÇÑ shared ¸Þ¸ð¸®¿Í ¾²·¹µå ¸Þ¸ð¸® ÇÒ´ç ¹× °è»ê
4) 2)°ú 3)¿¡ ÀÇÇÑ ÃÖ´ë µ¿½Ã Á¢¼Ó °¡´ÉÇÑ max_connections °è»ê
5) time out ¼³Á¤
6) ±× ¿Ü ¼³Á¤
7) ½Ã½ºÅÛÀ» ¿î¿µÇϸ鼭 Áö³­ Åë°è µ¥ÀÌÅÍ¿¡ ÀÇÇÑ ¼³Á¤°ª ´Ù½Ã Æ©´×

ÀÌ¿Í °°Àº ¼ø¼­·Î Æ©´×ÇØ ³ª°¡¾ß ÇÕ´Ï´Ù.

2)¹ø°ú 3)¹ø °°Àº °æ¿ì´Â

MySQL ÀÌ »ç¿ëÇÒ ¹°¸®Àû ¸Þ¸ð¸® ÃÑÇÕ =
(
key_buffer_size +
(read_buffer_size + sort_buffer_size) * max_connections
)

ÀÌ¿Í °°Àº °ø½ÄÀ» »ç¿ëÇÕ´Ï´Ù.
ÀüÀÚÀÇ key_buffer_size ´Â ¸ðµç ¾²·¹µåµéÀÌ Ç×»ó °øÀ¯Çؼ­ »ç¿ëÇÏ´Â shared
¸Þ¸ð¸®ÀÌ°í, ±× ¹ØÀÇ µÎ°³´Â °¢ ¾²·¹µå¸¶´Ù »ç¿ëÇÏ´Â not shared ¸Þ¸ð¸®ÀÔ´Ï´Ù.

°£·«ÇÏ°Ô Á¤¸®ÇÏ¸é ´ÙÀ½°ú °°½À´Ï´Ù.

MySQL caches(all threads shared)
(
- key_buffer_size : 8MB < INDEX key
- table_cache : 64 < number of open tables for all threads
- thread_cache_size : 0 < number of keep in a cache for reuse
)

MySQL buffers(not shared)
(
- join_buffer_size : 1MB < FULL-JOIN
- myisam_sort_buffer_size : 8MB < REPAIR, ALTER, LOAD
- record_buffer : 2MB < sequential scan allocates
- record_rnd_buffer : 2MB < ORDER BY(avoid disk)
- sort_buffer : 2MB < ORDER BY, GROUP BY
- tmp_table_size : 32MB < advanced GROUP BY(avoid disk)
)

MySQL memory size
(
- INDEX(key) : 8MB < key_buffer_size (shared)
- JOIN : 1MB < join_buffer_size (not shared)
- RECORD(read) : 2MB < record_buffer (not shared)
: 2MB < record_rnd_buffer (not shared)
- SORT : 8MB < myisam_sort_buffer_size (not shared)
: 2MB < sort_buffer (not shared)
- TABLE(temporary) : 32MB< tmp_table_size(not shared)
)

MySQL timeout
(
- connect_timeout : 5 > bad handshake timeout
- interactive_timeout : 28800 > interactive to re-interactive timeout
- wait_timeout : 28000 > none active to re-active timeout
)

MySQL connections
(
- max_connections : 100 < 'to many connections' error
- max_user_connections : 0(no limit) < user limit
)


ÀÌ ±ÛÀº ¸Þ¸ð¸® ¼³Á¤¿¡ °üÇÑ ³»¿ëÀº »ó´çÈ÷ ¹æ´ëÇϹǷΠ¿©±â¿¡¼­´Â Á¦¿ÜÇÏ°í,
MySQL ÀÇ time out °è»ê¿¡ °üÇÑ ³»¿ëÀÔ´Ï´Ù.

ÀÌ ±ÛÀÇ ÀüÁ¦ Á¶°Ç
(
- MySQL ¼­¹ö°¡ »ó´çÈ÷ ¹Ùºü¼­ time out ¼³Á¤ÀÌ ÇÊ¿äÇÏ´Ù.
- ¼­¹öÀÇ ¹Ù»Û Á¤µµ¿Í µ¥ÀÌÅͺ£À̽º Å©±â¿¡¼­ °è»êÇÑ
max_connections ¼³Á¤°ªÀÌ ÇöÀç MySQL ¼­¹öÀÇ ÇÑ°èÁ¡ÀÌ´Ù.
(ÃÊ°ú½Ã ¼­¹ö Áõ¼³ÀÌ ÇÊ¿äÇÔ)
- ¿¬°á Ãë¼ÒÀ²(Aborted_clients*100/Connections)ÀÌ ³ôÀº °æ¿ì
(Æ©´× ±âÁØ 0.1% ¶Ç´Â 0.5% ÀÌ»ó)
)

time out ¼³Á¤ ¸ñÀû
(
- Á¦ÇÑµÈ ÀÚ¿ø(¸Þ¸ð¸®)ÀÇ È¿À²Àû ÀÌ¿ë
- MySQL ¼º´É ±Ø´ë (ÇÑ°èÁ¡¿¡ ±Ø´ë, ÇÑ°èÁ¡À» ÃÊ°úÇÏÁö ¾ÊÀ½)
- ¿øÇÒÇÑ Ä¿³Ø¼Ç ó¸®
- Àý´ëÀûÀ¸·Î ºÒÇÊ¿äÇÑ Ä¿³Ø¼ÇÀ» °­Á¦·Î close(ºÒÇÊ¿äÇÑ Ä¿³Ø¼Ç ¹Ýȯ)
- ±âŸ
)


1. MySQLÀÇ time out

MySQL ¼­¹ö(Á¤È®È÷ `mysqld')ÀÇ time out ¼³Á¤Àº Å©°Ô 3°¡Áö°¡ ÀÖ½À´Ï´Ù.

mysqld time out
(
- connect_timeout (bad handshake timeout)
- interactive_timeout (interactive ¸ðµå¿¡¼­ connection time out)
- wait_timeout (none interactive ¸ðµå¿¡¼­ connection time out)
)

connect_timeout, interactive_timeout Àº Æ©´×°ú Á» °Å¸®°¡ ¸Ö°í,
½ÇÁ¦·Î ¹Ù»Û ¼­¹ö¶ó¸é, ¹Ýµå½Ã wait_timeout À» µû·Î Æ©´×ÇÏ¿© ¼³Á¤ÇØÁà¾ß ÇÕ´Ï´Ù.
(½ÇÁ¦ ÀÌ ±ÛÀÇ ³»¿ëÀÓ)


1-1. connect_timeout

ÀÌ ¼³Á¤Àº mysqld ¿Í mysql client °¡ ¿¬°á(connection)À» ¸Î±â À§Çؼ­
mysqld °¡ ¿¬°á ÆÐŶÀ» ±â´Ù¸®´Â ÃÖ´ë ½Ã°£ÀÔ´Ï´Ù.

Áï TCP ¿¬°áÀ» ¸Î´Â °úÁ¤(3-way handshake)¿¡¼­, connect_timeout µ¿¾È¿¡µµ
¿¬°á ÆÐŶÀÌ µé¾î¿ÀÁö ¾ÊÀ¸¸é ¿¬°áÀÌ ½ÇÆÐ(Ãë¼Ò°¡ ¾Æ´Ô)µÇ°í,
bad handshake ·Î ÀÀ´äÇÕ´Ï´Ù.

*Âü°í)
(
- ¿¬°á ½ÇÆÐ : ¿¬°á °úÁ¤Áß¿¡¼­ fail µÇ´Â °æ¿ì (Aborted_connects)
- ¿¬°á Ãë¼Ò : ¿¬°áÀÌ µÈ »óÅ¿¡¼­ °­Á¦·Î close µÈ °æ¿ì (Aborted_clients)
)

¹Ù²Ù¾î ¸»Çϸé mysqld ¿Í mysql client °¡ TCP ¿¬°áÀ» ¸Î´Â ÃÖ´ë ½Ã°£À¸·Î
ÀÌ ½Ã°£º¸´Ù Å« °æ¿ì´Â ¸ðµÎ Aborted_connects ¿¡ ÇØ´çµË´Ï´Ù.
(´ÜÀ§´Â ÃÊ)

¿¬°á ½ÇÆÐÀ²(POF) =
(
Aborted_connects * 100 / Connections
)

¿¬°áÀÌ ½ÇÆеǴ °æ¿ì
(
- ¿¬°á ÆÐŶ¿¡ ¿Ã¹Ù¸¥ ¿¬°á Á¤º¸°¡ ¾ø´Â °æ¿ì
- ƯÁ¤ user °¡ ±ÇÇÑÀÌ ¾ø´Â µ¥ÀÌÅͺ£À̽º¿¡ Á¢±ÙÇÒ °æ¿ì
- mysqld Á¢±Ù password °¡ Ʋ¸° °æ¿ì
- connect_timeout º¸´Ù ±ä ¿¬°á °úÁ¤
)

¿¬°á ½ÇÆÐÀ²(POF)ÀÌ ³ôÀº °æ¿ì´Â, ´ëºÎºÐ ±ÇÇÑÀÌ ¾ø´Â µ¥ÀÌÅͺ£À̽º ¿¬°áÀ̳ª,
Ʋ¸° password ¸¦ »ç¿ëÇÒ °æ¿ì°¡ ¸¹½À´Ï´Ù.

±âº»°ªÀº ´ëºÎºÐ 5(ÃÊ)·Î ¼³Á¤µÇ¾î ÀÖÀ¸¸ç, µû·Î Æ©´×ÇÒ ÇÊ¿ä´Â ¾ø½À´Ï´Ù.
mysqld ÀÇ --warnings ¿É¼Ç »ç¿ë°ú xxx.err ÆÄÀÏ¿¡ ±â·ÏµË´Ï´Ù.


1-2. interactive_timeout

interactive ¸ðµå¿¡¼­ time out À» ¸»ÇÕ´Ï´Ù.
interactive ¸ðµå´Â 'mysql>' °ú °°Àº ÇÁ·ÒÇÁÆ® ÀÖ´Â ÄܼÖÀ̳ª Å͹̳Π¸ðµå¸¦
¸»ÇÕ´Ï´Ù.

mysqld ¿Í mysql client °¡ ¿¬°áÀ» ¸ÎÀº ´ÙÀ½, ´ÙÀ½ Äõ¸®±îÁö ±â´Ù¸®´Â
ÃÖ´ë ½Ã°£À» ÀǹÌÇÕ´Ï´Ù.

¼³Á¤µÈ interactive_timeout ±îÁöµµ ¾Æ¹«·± ¿äû(Äõ¸®)ÀÌ ¾øÀ¸¸é ¿¬°áÀº
Ãë¼ÒµÇ°í, ±× ÀÌÈÄ¿¡ ´Ù½Ã ¿äûÀÌ µé¾î¿À¸é ¿¬°áÀº ÀÚµ¿À¸·Î ¸Î¾îÁý´Ï´Ù.

interactive_timeout ¾È¿¡ ´Ù½Ã ¿äûÀÌ µé¾î¿À¸é wait timeÀº 0À¸·Î ÃʱâÈ­
µË´Ï´Ù(CLIENT_INTERACTIVE).

ERROR 2006: MySQL server has gone away
No connection. Trying to reconnect...
Connection id: 12002
Current database: xxx

ÀÌ¿Í °°Àº ¿¬°á Ãë¼Ò´Â Aborted_clients ¿¡ ´©°èµÇ°í, wait_timeout ÀÇ
°á°úµµ ÇÔ²² Æ÷ÇԵ˴ϴÙ

±âº» °ªÀº 28800(8½Ã°£) ÃÊ·Î ¼³Á¤µÇ¾î Àִµ¥ »ó´çÈ÷ °ü´ëÇÑ(?) ¼³Á¤ÀÔ´Ï´Ù.
¾à 1½Ã°£(3600) Á¤µµ·Î ¼³Á¤ÇÏ´Â °ÍÀ» ±ÇÀåÇÕ´Ï´Ù.


1-3. wait_timeout

ÀÌ ¼³Á¤Àº Á¦ÀÏ Áß¿äÇÑ ÆĶó¸ÞÅÍ Ç׸ñÀÔ´Ï´Ù.

interactive ¸ðµå°¡ ¾Æ´Ñ °æ¿ì¿¡ ÇØ´çµÇ¸ç,
mysqld ¿Í mysql client °¡ ¿¬°áÀ» ¸ÎÀº ÈÄ, ´ÙÀ½ Äõ¸®±îÁö ±â´Ù¸®´Â
ÃÖ´ë ½Ã°£À» ÀǹÌÇÕ´Ï´Ù.

Áï ´ëºÎºÐ PHP ³ª C, PERL, python µîµîÀÇ API ¸¦ ÀÌ¿ëÇÑ client ÇÁ·Î±×·¥
¸ðµå¸¦ ¸»ÇÕ´Ï´Ù.

interactive_timeout °ú ¸¶Âù°¡Áö·Î wait_timeout ±îÁö ¾Æ¹«·± ¿äû(Äõ¸®)ÀÌ
¾øÀ¸¸é ¿¬°áÀº Ãë¼ÒµÇ°í ±× °á°ú´Â Aborted_clients ¿¡ ´©°èµË´Ï´Ù.

wait_timeout ¾È¿¡ ´Ù½Ã ¿äûÀÌ µé¾î¿À¸é wait time Àº 0 À¸·Î ÃʱâÈ­ µË´Ï´Ù.
(SESSION.WAIT_TIMEOUT)

¿¬°á Ãë¼ÒÀ²(POC) =
(
Aborted_clients * 100 / Connections
)

¿¬°áÀÌ Ãë¼ÒµÇ´Â °æ¿ì(°­Á¦ Á¾·áµÊ)
(
- Á¾·á(exit) µÇ±âÀü mysql_close() °¡ ¾ø´Â °æ¿ì
- wait_timeout À̳ª interactive_timeout ½Ã°£±îÁö ¾Æ¹«·± ¿äû(Äõ¸®)
ÀÌ ¾ø´Â °æ¿ì
)

±âº» °ªÀº interactive_timeout °ú ¸¶Âù°¡Áö·Î 28800(8½Ã°£) ÃÊ·Î ¼³Á¤µÇ¾î
Àִµ¥, ¿ª½Ã ³Ê¹« °ü´ëÇÑ(?) ¼³Á¤À̶ó°í ÇÒ ¼ö ÀÖ½À´Ï´Ù.

¾Õ¿¡¼­ ¿¬°á Ãë¼ÒÀ²(POC)À» °è»êÇØ º¸¸é, MySQL ¼­¹ö°¡ ¾î´À Á¤µµ ºñÀ²·Î °­Á¦
Á¾·áÇÏ´ÂÁö ¾Ë ¼ö ÀÖ½À´Ï´Ù.

¿¹¸¦ µé¾î POC °¡ 1 % À̶ó¸é, 100 °³ÀÇ Ä¿³Ø¼Ç´ç Çϳª Á¤µµ´Â mysql_close()
¾øÀÌ °­Á¦ Á¾·á(exit)µÇ°í ÀÖ´Ù´Â ÀǹÌÀÔ´Ï´Ù.

ÀÌ °ªÀÌ 0 %¿¡ °¡±î¿ï¼ö·Ï ÁÁ½À´Ï´Ù. ÀÌ Àǹ̴ Ŭ¶óÀ̾ðÆ® ÇÁ·Î±×·¥¿¡¼­
¸ðµÎ Á¤»óÀûÀ¸·Î Á¾·áÇß´Ù´Â ÀǹÌÀÔ´Ï´Ù.


2. ¿¬°á Ãë¼ÒÀ²(POC)°ú connection life time

2-1. ¿¬°á Ãë¼ÒÀ²(POC)

¿¬°á Ãë¼ÒÀ² °ªÀÌ Áö³ªÄ¡°Ô ³ôÀ¸¸é, wait_timeout ¼³Á¤ÀÌ ³Ê¹« ª°Å³ª,
´ëºÎºÐ client ÇÁ·Î±×·¥ÀÌ exit(Á¾·á)¸¦ Á¤»óÀûÀ¸·Î ÇÏÁö ¾ÊÀº °æ¿ìÀ̹ǷΠ¹Ýµå½Ã
Æ©´×ÀÌ ÇÊ¿äÇÕ´Ï´Ù.

ƯÈ÷ ¼­¹ö°¡ ¸Å¿ì ¹Ù»Û °æ¿ì´Â, ÀÌ wait_timeout ½Ã°£À» ª°Ô ¼³Á¤ÇÏ¿© ºÒÇÊ¿äÇÑ
Ä¿³Ø¼ÇÀ» ¸ðµÎ Á¦°ÅÇØ Áà¾ßÇÕ´Ï´Ù(¸Þ¸ð¸® ÇÑ°è ¹®Á¦).

wait_timeout Æ©´×ÀÌ ÇÊ¿äÇÑ °æ¿ì
(
- º¸Åë POC(¿¬°á Ãë¼ÒÀ²)°¡ 1 % ÀÌ»óÀÎ °æ¿ì
- ¾ÆÁÖ ¹Ù»Û ¼­¹ö¿¡¼­´Â Æ©´×Àü 0.01 % ÀÌ»óÀÎ °æ¿ì
- ±âŸ Æ©´× ±âÁØ¿¡ µû¶ó ´Ù¸§
)

ÁÖÀÇÇÒ Á¡Àº,

client ÇÁ·Î±×·¥(¿¹: PHP)À» ¼öÁ¤ÇÏÁö ¾Ê´Â »óÅ¿¡¼­, wait_timeout À» Æ©´×Çϸé
Æ©´×Àü¿¡ ºñÇؼ­ POC °¡ ´õ ¿Ã¶ó°¡¾ß Á¤»óÀÔ´Ï´Ù. ÀÌ Àǹ̴ ºñÁ¤»óÀûÀÎ Ä¿³Ø¼ÇÀ»
¹ÝȯÇÏ´Â ºñÀ²À̹ǷÎ, Á¤»óÀûÀÎ ¼­ºñ½ºÇÏ¿¡¼­ ÀÌ °ªÀÌ ¿Ã¶ó°¡¾ß ÇÔÀ» À̹ÌÇÕ´Ï´Ù.

warning
(
ÀÌÇÏ ´Ù·ç´Â 'life time' À̳ª 'ÀÓ°è life time' µîÀÇ ³»¿ëÀº ¹Ýµå½Ã
wait_timeout Æ©´×ÀÌ ÇÊ¿äÇÑ °æ¿ì¿¡ ÇØ´çµË´Ï´Ù.

¸¸¾à, wait_timeout Æ©´×ÀÌ ÇÊ¿äÇÏÁö ¾Ê´Ù¸é ÀÌÇÏ ³»¿ëÀ» ÇÊ¿äÇÏÁö ¾Ê½À´Ï´Ù.
)


±×·³ ÀÌÁ¦ wait_timeout °ªÀ» °è»êÇØ º¾½Ã´Ù.

ÀÌ °ªÀ» °è»êÇϱâ À§Çؼ­ mysqld ·Î±× ÆÄÀÏÀ» ºÐ¼®ÇØ¾ß Çϴµ¥,
ºÒÇàÈ÷µµ ½Ã°£ ±â·ÏÀÌ 1 ÃÊ °£°ÝÀ¸·Î ±â·ÏµÇ¾î À־ Á¢¼ÓÀ̳ª close ¶Ç´Â
°¢ Äõ¸® ½Ã°£ Åë°è¸¦ ±¸Çϱ⠾î·Æ½À´Ï´Ù.
(Ç¥º»À» ÇÏ·ç ´ÜÀ§·Î ÃàÃâÇÏ¿© °è»êÇÒ °æ¿ì, Á»´õ Á¤È®ÇÑ ÀÚ·á°¡ µÊ)

µû¶ó¼­, ÇöÀç MySQL ¼­¹öÀÇ STATUS Åë°è ÀڷḦ ÀÌ¿ëÇÏ´Â °Íµµ ÇϳªÀÇ ¹æ¹ýÀÔ´Ï´Ù.

Åë°è¸¦ ¾ò´Â ¹æ¹ý
(
mysql> tee /path/to/mysql.status.txt
mysql> SHOW STATUS;

or
shell> mysqladmin [OPTIONS] extended-status > mysql.status.txt
)

ÁÖ¿ä MySQL STATUS
(
Aborted_clients
Connections
Max_used_connections
Slow_queries
Questions
Uptime
...
)

Á÷Á¢ÀûÀÎ Æò±Õ wait_timeout °ªÀ» ±¸ÇÒ ¼ö ¾ø±â ¶§¹®¿¡,
°¢ Ä¿³Ø¼ÇÀ» ÀÏ·Ä·Î ´Ã¾î³õÀº »óÅÂÀÇ Æò±ÕÀûÀÎ Ä¿³Ø¼Ç life time °ªÀ»
±¸ÇØ¾ß ÇÕ´Ï´Ù.


2-2. connection life time

'life time' Àº ÇϳªÀÇ Ä¿³Ø¼ÇÀÌ ¿¬°áµÈ ÈÄ ¿ÏÀüÈ÷ close µÉ ¶§±îÁö ½Ã°£À» ¸»Çϸç,
ÇÊÀÚ°¡ ÀÚÀÇÀûÀ¸·Î ºÙÀÎ ¿ë¾îÀÔ´Ï´Ù.

Áï, ¿©±â¿¡¼­ÀÇ life time Àº ÇϳªÀÇ Ä¿³Ø¼ÇÀÌ »ì¾ÆÀÖ´Â µ¿¾ÈÀÇ ½Ã°£À» ¸»Çϸç,
ÀÌ ½Ã°£¿¡´Â Äõ¸® ½ÇÇà, connection idle, wait timeout, interactive timeout µîµîÀÌ
¸ðµÎ Æ÷ÇԵǾî ÀÖ´Â timeÀ» ¸»ÇÕ´Ï´Ù.

Á¶°Ç
(
connection idle ==> wait time out
interval of connection ==> 0
)


°¡Á¤
(
+----------------------------+------------------->+--------->
|connection | close|connection
|<-- queries execute time -->|<-- wait timeout -->|
|<------------- connection life time ------------>|
)

life time (ÇϳªÀÇ Ä¿³Ø¼Ç´ç Æò±Õ)
(
= Äõ¸® ½ÇÇà ½Ã°£(long query Æ÷ÇÔ)
+= { wait timeout | interactive timeout }
)


life time =
(
connection
[ wait time out ]
[ += 1'th query execute time ]
[ += wait time out]
[ += 2'th query execute time ]
[ += wait time out]
[ ... ]
[ += wait time out]
[ += n'th query execute time ]
[ += wait time out]
close
)


Ä¿³Ø¼Ç °ü·Ã Åë°è
(
cps = Connecions / Uptime ; // ÃÊ´ç Ä¿³Ø¼Ç ¼ö
spc = Uptime / Connections ; // Ä¿³Ø¼Ç ÁÖ±â(ÃÊ)
cpq = Question / Connections ; // Ä¿³Ø¼Ç´ç ¿äû Äõ¸® ¼ö
)

½ÇÁ¦ life time Àº mysqld ·Î±× ÆÄÀÏÀ» ºÐ¼®ÇغÁ¾ß Çϴµ¥,
ÀÌ°Í ¿ª½Ã »ó´çÈ÷ ±î´Ù·Ó½À´Ï´Ù(exit ½Ã°£ ±â·ÏÀÌ ¾ø±â ¶§¹®).

µû¶ó¼­, ¿©±â¿¡¼­´Â '½ÇÁ¦ life time'ÀÌ ¾Æ´Ñ °¡»óÀÇ 'ÀÓ°è life time'
¸¦ ±¸Çؼ­ wait time out ¼³Á¤¿¡ Áß¿äÇÑ ÀÚ·á·Î È°¿ëÇÏ°íÀÚ ÇÏ´Â °ÍÀÌ
ÀÌ ¹®¼­ÀÇ º» ³»¿ëÀÔ´Ï´Ù.


3. ÀÓ°è life time

¸ðµç Ä¿³Ø¼ÇÀÌ close µÇÁö ¾Ê´Â´Ù´Â °¡Á¤ÇÏ¿¡¼­, Áï ¸ðµç Ä¿³Ø¼ÇÀÌ
Çѹø Á¢¼ÓÈÄ °è¼ÓÀûÀ¸·Î »ì¾ÆÀÖ´Ù´Â °¡¼³À» ³»¸®°í,
ÇÑ°è µµ´Þ N sec ¸¦ ±¸Çؼ­ ÀÌ¿¡ ´ëÇÑ Æò±Õ°ª(AVG)À» ±¸Çغ¸¸é
ÀÌ Æò±Õ°ªÀÌ Ä¿³Ø¼Ç´ç 'Æò±Õ ÀÓ°è life time'ÀÌ µË´Ï´Ù.

¹Ù²Ù¾î ¸»Çϸé,
¸ðµç Ä¿³Ø¼ÇµéÀ» ²¿¸®¿¡ ²¿¸®¸¦ ¹«´Â °¡»óÀÇ Æò±ÕÀûÀÎ ÀÏÁ÷¼±À¸·Î ¸¸µé¾î
³õ°í, ÇÑ°è µµ´Þ N sec ¸¦ ±¸ÇÏ´Â ¹æ¹ýÀÔ´Ï´Ù
(Ä¿³Ø¼Ç°ú Ä¿³Ø¼Ç °£°ÝÀ» 0À¸·Î º½).

¹®Á¦°¡ µÇ´Â °æ¿ì'
(

µ¿½Ã Á¢¼Ó connection ¼ö(Y)
|
+ Max connection ------+------+------
| '| |
| ' | |
| ' | |
| . | |
| . | |
| . | |
| . . . . . ' | |
| | |
+----------------------+------+-------> X sec
N sec

* ½Ã°£ÀÌ Áö³²¿¡ µû¶ó ±Þ°ÝÇÑ ±â¿ï±â(¿À¸ñÇÑ ºÐÆ÷)
)

Àß Æ©´×µÈ °æ¿ì
(

µ¿½Ã Á¢¼Ó connection ¼ö(Y)
|
+ Max connection ------+------+------
| . ' ' |
| . |
| ' |
| ' |
| . |
| . |
| . . . . . ' |
| |
+----------------------+------+-------> X sec
N sec

* ½Ã°£ÀÌ Áö³²¿¡ µû¶ó ¿Ï¸¸ÇÑ ±â¿ï±â(º¼·ÏÇÑ ºÐÆ÷)
)


°¡Á¤
(

µ¿½Ã Á¢¼Ó connection ¼ö(Y)
|
+ Max connection -------------+------
| | . '|
| | . ' |
| | . ' |
| + ' |
| . ' | |
| . ' | |
| . ' | |
| | |
+--------------+--------------+-------> X sec
(N+1)/2 N sec

* Ä¿³Ø¼Ç °£°ÝÀ» 0À¸·Î º½(Á÷¼±Àû ±â¿ï±â)
)


ÇÑ°è µµ´Þ N sec °è»ê¹ý
(
1 sec : 1 * cps
2 sec : 2 * cps
3 sec : 3 * cps
...
N sec : N * cps => max_connections or Max_used_connections
)
or
(
N sec : max_connections or Max_used_connections / cps
)


ÃÖ´ë(ÃÖ¾Ç »óÅÂ) ÇÑ°è µµ´Þ life times ºÐÆ÷¿Í ±× Æò±Õ°ª(AVG) °è»ê¹ý
(
1 sec : 1 * cps'th connection : N sec (life time)
2 sec : 2 * cps'th connection : N - 1 sec
3 sec : 3 * cps'th connection : N - 2 sec
...
N sec : N * cps'th connection(max) : N - (N -1) sec

AVG : (N + 1) / 2 sec (life time) ; // ÀÓ°è life time
)

¸ðµç Ä¿³Ø¼ÇÀÌ °¢°¢(Æò±Õ) ÀÌ 'ÀÓ°è life time'¿Í °°°Å³ª ´õ Ŭ °æ¿ì
°á±¹ N sec ¿¡ µµ´ÞÇؼ­ full connection ÀÌ µÈ´Ù´Â ÀǹÌÀÔ´Ï´Ù.
±× ¹Ý´ë·Î,
Ä¿³Ø¼Ç Æò±Õ life time ÀÌ ÀÓ°è life time º¸´Ù ÀÛÀ¸¸é N sec ÀÌÈÄ¿¡¼­
full connection ÀÌ µÈ´Ù´Â °á·ÐÀÌ ³ª¿É´Ï´Ù.

ÀÌ°ÍÀº mysqld °¡ ÃÖ¾ÇÀÇ »óŸ¦ ¸»Çϸç, ¾ÆÁÖ ¹Ù»Û MySQL ¼­¹öÀ̰ųª
¾ÆÁÖ ¹Ù»Û ½Ã°£´ë(rush hour)¿¡ ÃæºÐÈ÷ ÀÌ·± »óȲÀÌ µÉ ¼ö ÀÖ´Ù´Â °ÍÀ»
¹ÝÁõÇÕ´Ï´Ù.

ÀÌ 'ÀÓ°è life time' À» ±¸Çؼ­ wait_timeout ¼³Á¤Çϴµ¥ Áß¿äÇÑ ÀÚ·á·Î
È°¿ëÇÏ´Â °ÍÀÌ º» ±ÛÀÇ ¸ñÀûÀ̸ç, ÀÌ 'ÀÓ°è life time'À» ´Ù¸¥ º¯¼ö°ªµé°ú
¼­·Î º¸Á¤ÇÏ¿© ÃÖÁ¾ wait_timeout À¸·Î ¼³Á¤ÇÏ´Â ³»¿ëÀÔ´Ï´Ù.


ÇöÀç ÃÖ´ë(ÃÖ¾Ç) ¿¹»ó ÀÓ°è life time °è»ê(EXP)
(
N sec = max_connections / cps
= max_connections * spc
= max_connections * Uptime / Connections

ÀÓ°è life time(EXP)
= (N + 1) / 2
)


ÇöÀç Æò±Õ ÀÓ°è life time °è»ê(CUR)
(
N sec = Max_used_connections / cps
= Max_used_connections * spc
= Max_used_connections * Uptime / Connections

ÀÓ°è life time(CUR)
= (N + 1) / 2
)

Áö³­ °ú°Å ÃÖ´ë ÀÓ°è life time °è»ê(PAS)
(
N sec = Max_used_connections / maximum of cps
= Max_used_connections * minimum of spc

ÀÓ°è life time(PAS)
= (N + 1) / 2
)

Áö³­ °ú°Å À¯Ãß ÃÖ´ë ÀÓ°è life time °è»ê(POL)
(
N sec = max_connections / maximum of cps
= max_connections * minimum of spc

ÀÓ°è life time(POL)
= (N + 1) / 2
)


3-1. ÇöÀç ÃÖ´ë(ÃÖ¾Ç) ¿¹»ó ÀÓ°è life time(EXP)

ÀÌ °ªÀº MySQL ¼­¹ö°¡ ½ÃÀÛÈÄ ÇöÀç±îÁöÀÇ ÃÊ´ç Æò±Õ Ä¿³Ø¼Ç ¼ö('ÀÌÇÏ 'cps')
¸¦ ±âÁØÀ¸·Î °è»êÇÒ ¶§, full connection ÀÎ max_connections ¿¡ µµ´ÞÇÒ ¶§ÀÇ
Æò±Õ ÀÓ°è life time ÀÔ´Ï´Ù.

Áï ¸ðµç Ä¿³Ø¼ÇÀº °¢°¢ Àý´ë·Î ÀÌ EXP º¸´Ù Å©¸é ¾ÈµÈ´Ù´Â Àǹ̰¡ µË´Ï´Ù.
(ÇÑ°èÁ¡À̹ǷÎ)

½ÇÁ¦·Î (wait_timeout > EXP) °æ¿ì´Â wait_timeout È¿°ú¸¦ ±â´ëÇϱ⠾î·Æ½À´Ï´Ù.

¿¹¸¦ µé¾î
(
wait_timeout = 120
EXP = 63
)

ÀÌ¿Í °°Àº °æ¿ì°¡ ¸¹Àºµ¥, ÀÌ°ÍÀ» ºÐ¼®(Çؼ®)ÇØ º¸¸é,
¸ðµç Ä¿³Ø¼ÇÀÇ Æò±Õ ÀÓ°è life time ÀÌ 64 ÃÊÀε¥ ±»ÀÌ 120 ÃʱîÁö ±â´Ù·Á¼­
close ÇÏ´Â °æ¿ì°¡ °ÅÀÇ ¾ø´Ù´Â Àǹ̰¡ µË´Ï´Ù. ¹°·Ð Æò±ÕÀûÀÎ °è»êÇÒ ¶§ÀÇ
¾ê±âÀÔ´Ï´Ù.

µû¶ó¼­ ÃÖ¼ÒÇÑ wait_timeout Àº EXP ¿Í °°°Å³ª ÀÌ °ªº¸´Ù ÀÛ°Ô ¼³Á¤ÇØÁÖ´Â °ÍÀÌ
È¿°ú°¡ ÀÖ½À´Ï´Ù.(Å©¸é º° È¿°ú¸¦ ±â´ëÇϱ⠾î·Á¿ò)


3-2. ÇöÀç Æò±Õ ÀÓ°è life time (CUR)

ÀÌ °ªÀº ÇöÀç±îÁö ÃÖ´ë µ¿½Ã Á¢¼Ó Ä¿³Ø¼Ç(Max_used_connections)¿¡ µµ´ÞÇÒ ¶§ÀÇ
Æò±Õ ÀÓ°è life time ÀÔ´Ï´Ù.

Áï life time ÀÌ ÇöÀç Ãß¼¼·Î, Æò±ÕÀûÀ¸·Î ÁøÇàÇÒ ¶§ÀÇ ÀÓ°è life time ÀÔ´Ï´Ù.

EXP º¸´Ù Ç×»ó À۰ųª °°½À´Ï´Ù. ¼­·Î °°Àº °æ¿ì´Â Áö³­ °ú°Å¿¡ ¹ú½á
full connection ±îÁö µµ´ÞÇß´Ù´Â Àǹ̰¡ µË´Ï´Ù.

ÀÌ °ªÀº ´ÜÁö Æò±ÕÀûÀÎ ÇöÀç Ãß¼¼¸¦ ¾Ë¾Æº¸´Âµ¥ À¯¿ëÇÕ´Ï´Ù.

±×·±µ¥,

EXP ¿Í CUR ¸ðµÎ ÇöÀç Æò±ÕÀûÀÎ Ãß¼¼¿¡ ´ëÇÑ life time ÀÔ´Ï´Ù.
¸ðµç ÇÁ·Î±×·¥ÀÌ ±×·¸µíÀÌ Æò±ÕÀûÀÎ ÀÛµ¿¿ø¸®´Â ¼³Á¤Àº »ó´çÈ÷ À§ÇèÇÕ´Ï´Ù.
Áï ÃÖ¾ÇÀÇ »óűîÁö °í·ÁÇؼ­ ÇÁ·Î±×·¥¿¡ ÀÓÇØ¾ß ÇÑ´Ù´Â °ÍÀÔ´Ï´Ù.

µû¶ó¼­, EXP¿Í CUR °ªº¸´Ù ´õ ÀÛÀº ÀÓ°è life time À» ±¸ÇØ¾ß Çϴµ¥,
ÀÌ°ÍÀº Áö³­ °ú°Å¿¡ °¡Àå ¹Ù»¦´ø cps ·Î °è»êÇÑ POL ÇØ¾ß ÇÕ´Ï´Ù.


3-3. Áö³­ °ú°Å ÃÖ´ë ÀÓ°è life time (PAS)

Áö³­ °ú°ÅÁß¿¡¼­ ÃÖ´ë cps °ªÀ» ¼±ÅÃÇÏ¿© °è»êÇÒ ¶§ÀÇ ÀÓ°è life time ÀÔ´Ï´Ù.
ÀÌ °ªÀº ´Ù¸¥ ÀÓ°è life time º¸´Ù Ç×»ó ÀÛ½À´Ï´Ù.

°ú°ÅÁß¿¡¼­ ÃÖ´ë cps ±¸ÇÏ´Â ¹æ¹ýÀÌ Á¶±Ý ±î·Î¿îµ¥ ÀÌ°ÍÀº ¸Å ½Ã°£´ë¸¶´Ù ¶Ç´Â
rush hour ¿¡ üũÇÏ¿© ±× Åë°èÀÇ °á°úÄ¡¸¦ ±¸ÇØ¾ß ÇÕ´Ï´Ù.

¸¸¾à ÃÖ´ë cps ¸¦ ±¸Çϱ⠾î·Á¿ì¸é ÇöÀç Æò±Õ cps * (1.5 ~ 2.0) Á¤µµ·Î °è»êÇϸé
µË´Ï´Ù.

ÀÌ PAS °ªÀº wait_timeout °ªÀ» ±¸Çϴµ¥ °áÁ¤ÀûÀÎ ÀÚ·á·Î ¾²À̸ç,
CUR ÀÇ º¸Á¤°ªÀ̶ó°í »ý°¢ÇÏ¸é µË´Ï´Ù.


3-4. Áö³­ °ú°Å À¯Ãß ÃÖ´ë ÀÓ°è life time (POL)

EXP °¡ ÇöÀç Æò±Õ cps °ªÀ¸·Î °è»êÇÑ ÀÓ°è life time ¿¡ ¹ÝÇؼ­, POL Àº PAS ¿Í
°°ÀÌ °ú°ÅÁß ÃÖ´ë cps °ªÀ¸·Î °è»êÇÑ ÀÓ°è life time ÀÔ´Ï´Ù.

Áï,
EXP ´Â Æò±ÕÀû cps ¿¡ ÀÇÇؼ­ °¢ Ä¿³Ø¼ÇÀ» ÀÏÁ÷¼±À¸·Î ´Ã¾î ³õ´Âµ¥ ¹ÝÇؼ­,
POL Àº ÃÖ´ë cps ¿¡ ÀÇÇؼ­ °¢ Ä¿³Ø¼ÇÀ» ÀÏÁ÷¼±À¸·Î ´Ã¾î ³õÀº »óÅ¿¡¼­ °è»êÇÑ
life tiem °ªÀÔ´Ï´Ù.

ÀÌ °ªµµ PAS ¿Í °°ÀÌ wait_timeout °ªÀ» ±¸Çϴµ¥ °áÁ¤ÀûÀÎ ÀÚ·á·Î ¾²À̸ç,
EXP ÀÇ º¸Á¤°ªÀ̶ó°í »ý°¢ÇÏ¸é µË´Ï´Ù.


4. ÃÖÁ¾ ÀÓ°è life time(LPT) °è»ê(¿¹Á¦)

½ÇÁ¦ ¿¹¸¦ µé¾î º¸°Ú½À´Ï´Ù.

ex1
(
max_connections = 100
Max_used_connections = 13
AVG of cps = 0.1
MAX of cps = 0.3
); // ¸Å¿ì ¹Ù»ÚÁö ¾ÊÁö¸¸ °ú°Å ¾î´À ¼ø°£¿¡ ±Ø´ë·Î ¹Ù»¦´ø °æ¿ì

ex2
(
max_connections = 100
Max_used_connections = 92
AVG of cps = 0.8
MAX of cps = 1.1
); // ºñ±³Àû ¹Ù»Û ¼­¹ö·Î½á °ÅÀÇ ÇÑ°èÁ¡¿¡ µµ´ÞÇÏ°í ÀÖ´Â °æ¿ì

ex3
(
max_connections = 100
Max_used_connections = 100
AVG of cps = 2.4
MAX of cps = 2.7
); // ¾ÆÁÖ ¹Ù»Û ¼­¹ö·Î °ú°Å¿¡ ÀÌ¹Ì ÇÑ°èÁ¡¿¡ ÃÊ°úÇÑ °æ¿ì


+------+------+------+---------+-----------+-------+-------+
| ±¸ºÐ | EXP | POL | | CUR (C%) | PAS | (DEF) |
|------+------+------+---------+-----------+-------+-------|
| ex1 | 201 | 167 | | 66 (33%) | 22 | 44 |
|------+------+------+---------+-----------+-------+-------|
| ex2 | 63 | 46 | | 58 (92%) | 42 | 16 |
|------+------+------+---------+-----------+-------+-------|
| ex3 | 21 | 19 | | 21(100%) | 19 | 2 |
+------+------+------+---------+-----------+-------+-------+

* C% : (CUR * 100 / EXP) ; // Æò±Õ cps ¿¡ ´ëÇÑ ÀÓ°è µµ´Þ »ç¿ëÀ²
* DEF : CUR - PAS ; // ÆíÂ÷

¼­¹ö°¡ ¹Ù»Ü¼ö·Ï EXP ³ª CUR °ªÀÌ Á¡Á¡ ÀÛ¾ÆÁö°í, C% °ªÀº Á¡Á¡ Ä¿Áý´Ï´Ù.

°¢°¢ max_connectionsÀÌ ¼­¹öÀÇ ÇÑ°è¶ó´Â ¼³Á¤¿¡¼­ EXP ³ª CUR °ªÀÌ 10 º¸´Ù
ÀÛÀ¸¸é ¼­¹öÀÇ Áõ¼³ÀÌ ÇÊ¿äÇÏ´Ù´Â °ÍÀ» ÀǹÌÇÕ´Ï´Ù.
(slow query 10 sec ¿¡ ±âÁØÀ» µÐ´Ù¸é)

¿©±â¿¡¼­ Áß¿äÇÑ ÀÓ°è life time Àº PAS °ªÀε¥,
ÀÌ PAS °ªÀº Á¦ÀÏ ¹Ù»Û »óÅ°¡ °è¼ÓµÈ´Ù´Â °¡Á¤À̹ǷΠ´Ù¸¥ °ªº¸´Ù Ç×»ó
Á¦ÀÏ ÀÛ½À´Ï´Ù.

½ÇÁ¦ À§ÀÇ ¿¹¸¦ º¸¸é,
ex1ÀÌ ex2 º¸´Ù Æò±ÕÀûÀ¸·Î ´õ ¹Ù»ÚÁö ¾ÊÁö¸¸ PAS °ªÀÌ ´õ ÀÛ½À´Ï´Ù.
ÀÌ Àǹ̴ °ú°ÅÀÇ ¾î´À ¼ø°£¿¡ ex2 º¸´Ù ´õ ¹Ù»¦´Ù´Â Áõ°ÅÀÌ°í ¾ÕÀ¸·Î
±×·² °¡´É¼ºÀÌ ÀÖ´Ù´Â ÀǹÌÀÔ´Ï´Ù.

DEF °ªÀÌ Å©´Ù´Â Àǹ̴ Æò±Õ°ú ÃÖ´ëÄ¡ÀÇ life time ÀÇ Â÷°¡ Å©´Ù´Â Àǹ̷Î
¼­¹ö°¡ ¹Ù»Ü¶§¿Í ±×·¸Áö ¾ÊÀ»¶§ÀÇ Â÷°¡ Å©´Ù´Â ÀǹÌÀÔ´Ï´Ù.

¶ÇÇÑ PAS °ªÀÌ 10 º¸´Ù ÀÛÀ¸¸é ¼­¹ö Áõ¼³ Çʿ伺ÀÌ »ó´çÈ÷ ³ô´Ù´Â Àǹ̰¡
µË´Ï´Ù. (slow query 10 sec ¿¡ ±âÁØÀ» µÐ´Ù¸é)

EXP, POL, CUR, PAS Áß¿¡¼­ Æ©´×ÇÒ ÀÓ°è life time °ªÀ» ¼±ÅÃÇØ¾ß Çϴµ¥,
POL À̳ª PAS °ª Áß¿¡¼­ Çϳª¸¦ ¼±ÅÃÇÏ¸é µË´Ï´Ù.

POL °ªÀ» ¼±ÅÃÇÒ °æ¿ì´Â ¸Å¿ì °ü´ëÇÑ Á¤Ã¥(¼³Á¤)ÀÌ µÉ °ÍÀÌ°í, PAS °ªÀ»
¼±ÅÃÇÏ¸é ¸Å¿ì Á¦ÇÑÀûÀÎ ¼³Á¤ÀÌ µË´Ï´Ù.

ÁÖÀÇÇÒ Á¡Àº ¼±ÅÃÇÑ ÀÓ°è life time ÀÌ 10 º¸´Ù ÀÛÀ¸¸é ¼­¹ö°¡ ¾ÆÁÖ ¹Ù»Û
»óÅ¿¡ ¸ñÇ¥¸¦ µÎ°í Æ©´×ÇØ¾ß ÇϹǷΠÁÖÀÇÇØ¾ß ÇÕ´Ï´Ù.

¿©±â¿¡¼­´Â ÆíÀÇ»ó PAS °ªÀ» ¼±ÅÃÇÏ°Ú½À´Ï´Ù.

±×·±µ¥ ex1 °°Àº °æ¿ì´Â DEF ÆíÂ÷°¡ »ó´çÈ÷ Å«µ¥, ex1 ºñ±³Àû ±×¸® ¹Ù»ÚÁö
¾ÊÀ¸¹Ç·Î ±× ´ÙÀ½À¸·Î ÀÛÀº CUR °ªÀ» ¼±ÅÃÇÏ´Â °ÍÀÌ ÁÁ½À´Ï´Ù.

¸¸¾à ¼­¹ö°¡ ÀüüÀûÀ¸·Î ºñ±³Àû ¹Ù»Ú´Ù°í »ý°¢Çϸé Á¦ÀÏ ÀÛÀº PAS °ªÀ»
¼±ÅÃÇÏ¸é µË´Ï´Ù.


+------+----------------------------------+
| ±¸ºÐ | ÃÖÁ¾ ÀÓ°è life time (LPT) |
|------+----------------------------------|
| ex1 | 66 |
|------+----------------------------------|
| ex2 | 42 |
|------+----------------------------------|
| ex3 | 19 |
+------+----------------------------------+



5. wait_timeout °è»ê ¹× º¸Á¤

ÀÌÁ¦ life time ÀÌ °áÁ¤µÇ¾úÀ¸´Ï wait_timeout °ªÀ» ¼³Á¤ÇØ º¾½Ã´Ù.

¾Õ¼­ ¾ê±âÇßµíÀÌ life time Àº °¢ Ä¿³Ø¼ÇÀ» Æò±ÕÀûÀ¸·Î ÀÏÁ÷¼±»ó¿¡
³õ¾ÒÀ» °æ¿ì, ÇÑ°è µµ´Þ ½Ã°£À» ÀǹÌÇÕ´Ï´Ù.

Áï °¢ Ä¿³Ø¼ÇÀº Æò±ÕÀûÀ¸·Î ÀÌ life time °ªÀ» ³Ñ¾î¼­¸é ¾ÈµÈ´Ù´Â ÀǹÌ
ÀÔ´Ï´Ù. (max_connections °ªÀÌ ÀÌ¹Ì Á¤ÇØÁø ÇÑ°èÀ̱⠶§¹®¿¡)

LPT °ªÀÌ 19 À̶ó¸é(ex3ÀÇ °æ¿ì),

cpq = 8(¿¹)
(
Questions / Connections
); // Ä¿³Ø¼Ç´ç Æò±Õ Äõ¸® ¿äû¼ö

LPT =
(
(connection)
(
[ = wait time out]
[ += 1'th query execute time ]
)
(
[ += wait time out]
[ += 2'th query execute time ]
)
(
[ ... ]
)
(
[ += wait time out]
[ += n'th query execute time ] ; // n => cpq
[ += wait time out]
)
(close)
) < 19

ÀÌ·± Á¶°Ç½ÄÀÌ ³ª¿É´Ï´Ù.

±×¸®°í
ÇϳªÀÇ Äõ¸®°¡ ½ÇÇàÇÑ ½Ã°£°ú ±× ´ÙÀ½ Äõ¸®±îÁöÀÇ ½Ã°£À» Æò±ÕÀûÀ¸·Î
°è»êÇÏ¸é ´ÙÀ½°ú °°½À´Ï´Ù.

2.4 sec = 19 / 8 = LPT / cpq

º¸Åë ÇϳªÀÇ Äõ¸®°¡ ½ÇÇàÇÏ´Â ½Ã°£Àº »ó´çÈ÷ ªÀº 0.001 ~ 2.0 sec Á¤µµ
µÇ´Â °ÍÀÌ º¸ÅëÀÔ´Ï´Ù.(¹°·Ð ¿¹¿Üµµ ÀÖÀ½)

±×·¯¸é ´ëÃæ wait time out °ªÀ» °è»ê ¶Ç´Â ÁüÂøÇÒ ¼ö ÀÖ½À´Ï´Ù.
Áï Æò±ÕÀûÀ¸·Î 2.4 ÃÊ º¸´Ù Ç×»ó ÀÛ´Ù´Â °á·ÐÀÌ ³ª¿É´Ï´Ù.

±×·¯³ª

ÀÌ °ªÀ» °ð¹Ù·Î wait_timeout °ªÀ¸·Î ¼³Á¤ÇÏ¸é »ó´çÈ÷ À§ÇèÇÕ´Ï´Ù.
ÀÌ °ªÀº ¾îµð±îÁö³ª Æò±ÕÀûÀÎ ¼öÄ¡ÀÏ »Ó ÆíÂ÷¿¡ ´ëÇÑ °í·Á°¡ ÀüÇô ¾ø½À´Ï´Ù.

¿¹¸¦ µé¾î, °¢ Ä¿³Ø¼Ç¸¶´Ù Äõ¸®°¡ ÇϳªÀÌ¸é »ó°üÀº ¾øÁö¸¸,
´ÙÀ½°ú °°Àº °æ¿ì°¡ »ó´çÈ÷ ¸¹±â ¶§¹®ÀÔ´Ï´Ù.

life time
(
connection
(
= wait time out ; // 0.1 sec
= 1'th query execute time ; // 0.4 sec
)
(½ÇÁ¦ Äõ¸®¿¡ »ó°ü¾ø´Â ÀÛ¾÷ ½Ã°£ = 3.1 sec)
(
+= wait time out ; // 3.1 sec > 2.4 sec
+= 2'th query execute time ; // 0.2 sec
)
close
) < 19 ; // ¿¹Á¦

µû¶ó¼­ ¾Õ¿¡¼­ °è»êÇÑ 2.4 sec ´Â ½ÇÁ¦·Î wait_timeout ¿¡ Àû¿ëÇϱ⿡´Â
¸Å¿ì ÀûÀýÇÏÁö ¾Ê½À´Ï´Ù.

°á·ÐÀûÀ¸·Î

ÇϳªÀÇ Ä¿³Ø¼ÇÀÌ ÃÖ¼ÒÇÑ Çϳª ÀÌ»óÀÇ Äõ¸®°¡ ÀÖ´Â °æ¿ì°¡ °ÅÀÇ ´ëºÎºÐÀ̹ǷÎ
ÀÌ Á¡À» °í·Á¼­ °è»êÇÏ¸é ´Ù¸§°ú °°Àº ÃÖÁ¾ÀûÀÎ °è»ê½ÄÀÌ ³ª¿É´Ï´Ù.

wait_timeout
(
= LPT - (LPT / cpq)
= LPT - (LPT * Connections / Questions)
)
* ´Ü) LPT > 10
* ´Ü) cpq > 1
* ´Ü) wait_timeout > 10 (ÇÑ°è°ª, slow query °í·Á)



+------+-------+----------+--------------------+---------+
| ±¸ºÐ | LPT | cpq(¿¹) | wait_timeout | AVG |
|------+-------+----------+--------------------+---------|
| ex1 | 66 | 5 | 53 | 59 |
|------+-------+----------+--------------------+---------|
| ex2 | 42 | 7 | 36 | 39 |
|------+-------+----------+--------------------+---------|
| ex3 | 19 | 9 | 17 | 18 |
+------+-------+----------+--------------------+---------+


ÀÌ wait_timeout Àº »ó´çÈ÷ Á¦ÇÑÀûÀÎ Á¤Ã¥ÀÔ´Ï´Ù.
Á»´õ °ü´ëÇÑ ¼³Á¤À» ¿øÇÑ´Ù¸é LPT °ªÀ» wait_timeout °ªÀ¸·Î ¼³Á¤Çϰųª
LPT¿Í °è»êÇÑ wait_timeout °ú Æò±Õ°ª(AVG)À» ÃÖÁ¾ wait_timeout °ªÀ¸·Î
¼³Á¤ÇÏ¸é µË´Ï´Ù.


6. °á°ú È®ÀÎ

ÀÌÁ¦ ÃÖÁ¾ÀûÀ¸·Î wait_timeout °ªÀÌ Á¤ÇØÁ³¹Ç·Î ÀÌ °ªÀ» ¼­¹ö¿¡ Àû¿ëÇØ
º¾´Ï´Ù.

Àû¿ë ¿¹
(
shell> safe_mysqld ... -O wait_timeout=17 &

or

[mysqld]
...
set-variable = wait_timeout=17
)


Æ©´×Àü¿¡ ºñÇؼ­ ¿¬°á Ãë¼ÒÀ²(POC)ÀÌ ´õ ¿Ã¶ó°¡¾ß Á¤»óÀÔ´Ï´Ù.
ÀÌ Àǹ̴ ºñÁ¤»óÀûÀÎ Ä¿³Ø¼ÇÀ» ¹ÝȯÇÏ´Â ºñÀ²À̹ǷÎ, ¼º°øÀûÀÎ
Æ©´×À̶ó°í ÇÒ ¼ö ÀÖ½À´Ï´Ù.



7. Èıâ

Çé... ¾îµð¿¡¼­ ¼è(?) Ÿ´Â ³¿»õ°¡ ³­´ÙÇß´õ´Ï....
CPU ÆÒÀÌ ¾Èµµ³×¿ä(¼³¸¶ ¼³¸¶ Çß´õ´Ï)....T.T
±×°Íµµ AMD CPU ....
Á¦°¡ ³¿»õ¿¡ ¹Î°¨Çؼ­ õ¸¸´ÙÇà..



my.cnf¿¡ wait_timeout¼³Á¤ÇÏ´Â ¹®Á¦
Tips 2008/01/31 17:21

±¸±Û¸µÀ» Çغ¸¸é ÀÌ ¹®Á¦·Î ¸¹Àº »ç¶÷µéÀÌ »ðÁúÀ» ÀÌ¹Ì Çß´Ù. ±×¸®°í ´ë´Ù¼ö°¡ ¹ö±×¶ó°í »ý°¢ÇÏ°í ÀÖ¾ú´Ù.

¹ö±×°¡ ¾Æ´Ï´Ù. ´ç¿¬ÇÑ »ðÁúÀ̾ú´Ù.

my.cnfÀÇ [mysqld] section¿¡ wait_timeout=300 À¸·Î ¼³Á¤ Ãß°¡ÇÏ°í ´Ù½Ã ¶ç¿î´Ù.(±âº»°ªÀº 28800)

mysql·Î Á¢¼ÓÇÏ¿© show variables like 'wait_timeout' À» Çغ»´Ù.

¾î¶ó? 28800ÀÌ´Ù. ¿Ö Àû¿ëÀÌ ¾ÈµÇ´Â °É±î..

show variables like '%timeout%'À» Çغ¸¸é, interactive_timeoutÀ̶ó´Â°Ô Àִµ¥, ÀÌ°Ô ¹Ù·Î Ä¿¸Çµå¶óÀΠŬ¶óÀ̾ðÆ®ÀÎ mysql (º¸Åë /usr/local/mysql/bin/mysql ¶Ç´Â /usr/local/bin/mysql µîµî)À» ¸»ÇÏ´Â °Å´Ù. ´ç¿¬È÷ mysql ±âº» Ŭ¶óÀ̾ðÆ®·Î interactive modeÁ¢¼ÓÇϸé wait_timeoutÀ» interactive_timeout°ªÀ¸·Î ¹Ù²ãÁִ°ŴÙ.
¿Ö³Ä±¸? interactive mode·Î Á¢¼ÓÇßÀ¸´Ï±î ±×·¸Áö ¤Ñ_¤Ñ

show global variables like '%timeout%'À» Çغ»´Ù.

wait_timeout=300À¸·Î ¼³Á¤ÀÌ Àß µÇ¾îÀÖ´Ù. Áï, interactive mode°¡ ¾Æ´Ñ Á¢¼Ó ¾²·¹µå¿¡ ´ëÇؼ­ wait_timeoutÀÌ »õ·Î ¼³Á¤ÇÑ °ªÀÌ µÈ´Ù´Â°Å´Ù. ´ç¿¬È÷ mysql·Î Á¢¼ÓÇؼ­´Â È®ÀÎÀ» ¸øÇÑ´Ù.

º»ÀÎÀÌ ÀÛ¼ºÇÏ´Â ÇÁ·Î±×·¥ÀÇ ¶óÀ̺귯¸®¸¦ ÀÌ¿ëÇÏ¿© Å×½ºÆ® Ä¿³Ø¼ÇÀ» ¸¸µé°í 300ÃÊ°£ ¾Æ¹«°Íµµ ÇÏÁö ¾ÊÀº ÈÄ¿¡ Äõ¸®¸¦ Çϳª ³¯·Áº¸ÀÚ "SELECT 1" °°Àº..

¿¡·¯°¡ ³­´Ù. 2006, Mysql server has gone away. ¼³Á¤ÇÑ wait_timeoutÀÌ ¸Ô¾ú´Ù.
¹¹.. ±×·±°Å´Ù.. ¼³Á¤ Àß µÅÀִ°Š°¡Áö±¸ Âø°¢ÇÏ°í, »ðÁúÇÏÁö ¸»ÀÚ.

ÀÛ¼º ³¯Â¥ : 2008-02-14