Skip to content

mysql-timeout.txt

26KB · 909 lines

plaintext
[MySQL] time out(wait_timeout) ��� ����

- �ۼ��� : ��ĥ�� <san2(at)linuxchannel.net>
- �ۼ��� : 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) �DZ� 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���� ��).

  ������ �Ǵ� ���'
  (
      <FONT FACE='����ü'>
      ���� ���� connection ��(Y)
      |
      + Max connection ------+------+------
      |                     '|      |
      |                    ' |      |
      |                   '  |      |
      |                 .    |      |
      |               .      |      |
      |             .        |      |
      | . . . . . '          |      |
      |                      |      |
      +----------------------+------+-------> X sec
                             N sec
      </FONT>
      * �ð��� ������ ���� �ް��� ����(������ ���)
  )

  �� Ʃ�׵� ���
  (
      <FONT FACE='����ü'>
      ���� ���� connection ��(Y)
      |
      + Max connection ------+------+------
      |                       . ' ' |
      |                     .       |
      |                   '         |
      |                 '           |
      |               .             |
      |             .               |
      | . . . . . '                 |
      |                             |
      +----------------------+------+-------> X sec
                                    N sec
      </FONT>
      * �ð��� ������ ���� �ϸ��� ����(������ ���)
  )


  ����
  (
      <FONT FACE='����ü'>
      ���� ���� connection ��(Y)
      |
      + Max connection -------------+------
      |              |           . '|
      |              |       . '    |
      |              |   . '        |
      |              + '            |
      |          . ' |              |
      |      . '     |              |
      |  . '         |              |
      |              |              |
      +--------------+--------------+-------> X sec
                   (N+1)/2          N sec
      </FONT>
      * Ŀ�ؼ� ����� 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
  ); // ��� �ٻ� ������ ���ſ� �̹� �Ѱ��� �ʰ��� ���

<FONT FACE='����ü'>
+------+------+------+---------+-----------+-------+-------+
| ���� |  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  |
+------+------+------+---------+-----------+-------+-------+
</FONT>
* 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 ����
�����ϸ� �˴ϴ�.

<FONT FACE='����ü'>
+------+----------------------------------+
| ���� |  ��� �Ӱ� life time (LPT)       |
|------+----------------------------------|
| ex1  |            66                    |
|------+----------------------------------|
| ex2  |            42                    | 
|------+----------------------------------|
| ex3  |            19                    |
+------+----------------------------------+
</FONT>


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 ��)


<FONT FACE='����ü'>
+------+-------+----------+--------------------+---------+
| ���� |  LPT  |  cpq(��) |    wait_timeout    |   AVG   |
|------+-------+----------+--------------------+---------|
| ex1  |   66  |     5    |         53         |    59   |
|------+-------+----------+--------------------+---------|
| ex2  |   42  |     7    |         36         |    39   |
|------+-------+----------+--------------------+---------|
| ex3  |   19  |     9    |         17         |    18   |
+------+-------+----------+--------------------+---------+
</FONT>

�� 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 ....
���� ������ �ΰ��ؼ� õ������..



E