본문 바로가기
Database/MYSQL

MySQL5.6 메모리 사용량을 억제

by 반화넬 2019. 4. 23.
반응형


이번은 MySQL5.6이 메모리 450Mbyte도 소비하고 있었기 때문에 메모리 소비를 개선하는 방법입니다.

# ps alx | grep mysql | awk '{printf ("%d\t%s\n", $8,$13)}'
1488    /bin/sh
454036  /usr/sbin/mysqld
912     grep
 
살펴보면 버그 인 것 같습니다.
일단 상황은 어떻게되어 있는지 확인합니다.

mysql> show variables like 'table_definition_cache';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| table_definition_cache | 1400  |
+------------------------+-------+
1 row in set (0.00 sec)
 

이 'table_definition_cache'은 메모리에 테이블 구조, 컬럼의 형태, 인덱스 등 테이블 정의 만 캐시한다는 것,
데이터베이스를 1 ~ 2 개 정도 밖에 사용하지 않는 경우 Value는 400 당에서 좋은 것 같습니다.

/etc/my.cnf를 열고 [mysqld] 아래 기준에 다음 행을 추가합니다.
[mysqld]
table_definition_cache = 400

# service mysql restart
mysql 재부팅 후 다시 확인합니다.

mysql> show variables like 'table_definition_cache';
+------------------------+-------+
| Variable_name          | Value |
+------------------------+-------+
| table_definition_cache |  400  |
+------------------------+-------+
1 row in set (0.00 sec)
 

메모리도 검토 한 결과, 약 97M까지 줄어 들었습니다.

# ps alx | grep mysql | awk '{printf ("%d\t%s\n", $8,$13)}'
1488    /bin/sh
97056   /usr/sbin/mysqld
912     grep

전체 메모리를 확인합니다.

# free -h
             total       used       free     shared    buffers     cached
Mem:          996M       569M       426M        32M       122M       196M
-/+ buffers/cache:       250M       745M
Swap:         2.0G       3.1M       2.0G

상당히 여유가 생겼으므로 김에 Swap 영역을 지 웁니다.

swapoff -a && swapon -a
Swap의 used가 0으로되어 있습니다.

# free -h
             total       used       free     shared    buffers     cached
Mem:          996M       573M       423M        35M       122M       199M
-/+ buffers/cache:       250M       745M
Swap:         2.0G         0B       2.0G
 

반응형