CPU가 처리해 하는 작업이 얼마나 쌓여 있는지 확인 - 대략적인 서버 부하가 어느정도인지 판단.
shll> uptime
- load average 확인
shell> vmstat 1
- procs -r : 프로세스 큐에서 CPU가 실행주기를 기다리는 프로세스의 수
- procs -b : 지정된 이벤트가 발생하기 전까지는 실행될 수 없는 프로세스의 수
-cpu -us : 사용자 프로세스를 위해 사용한 CPU 사용률로 application의 코드가 사용한 CPU 시간
(대표적으로 정렬, group by , 압축 )
-cpu -sy : 커널이 시용한 CPU 시간
-cpu -id : CPU가 아무것도 하지 않고 대기(idle) 하는데 사용한 CPU 사용률. 아무런 작업도 하지않는 장비에서 이 값이 높게 나타남
cpu -wa : 디스크 입출력을 기다리는 데(wait) 사용한 CPU 사용률 . 주로 DBMS서버가 실행중인 장비에서 관심을 갖고 봐야함. "wa(wait I/O)" 값이 높으면 디스크IO가 과도하게 많이 발생해 CPU가 데이터의 입출력을 기다리는 시간이 많다는 것을 의미.
show global variables like 'tmp_table_size'; show global variables like 'innodb_buffer_pool_size'; show global variables like 'innoDB_flush_method'; show global variables like 'tmp_table_size'; show global variables like 'max_heap_table_size'; show global variables like 'query_cache_size'; show global variables like 'query_cache_type'; show global variables like 'query_cache_limit'; show global variables like 'table_open_cache'; show global variables like 'opened_tables' ; show global variables like 'innodb_adaptive_hash_index'; show global variables like 'innodb_thread_concurrency'; show global variables like 'innodb_read_io_threads'; show global variables like 'innodb_write_io_threads'; -- show global variables like 'innodb_spin_wait_delay'; -> 0 -- show global variables like 'innodb_buffer_pool_instances'; -> 4
-- The thread cache SHOW GLOBAL STATUS LIKE 'Connections'; -- 16 SHOW GLOBAL STATUS LIKE 'Threads_created'; -- 4 SHOW GLOBAL STATUS LIKE 'Max_used_connections'; -- 4
-- Threads_created/Connections select 4 / 16 ; -- 0.2500 > 0.01 이면 thread_cache_size 증가필요 --> Max_used_connections 보다 커야함 show global variables like 'thread_cache_size';
innodb_flush_method=O_DIRECT쓸 때 이중 버퍼를 피하기 위해 사용 합니다. innodb_buffer_pool_size전체 InnoDB 데이터를 메모리에로드하도록 설정 하면 디스크에서 읽는 것을 방지 할 수 있습니다. innodb_log_file_size너무 높게 만들지 마십시오 . 더 빠른 디스크를 사용하면 종종 플러시가 나쁘지 않으며 서버에서 충돌하는 동안 복구 시간이 단축됩니다. 다음 두 변수를 혼합하지 마십시오 : innodb_thread_concurrency및 thread_concurrency. 이것은 MySQL 성능에 더 나은 영향을 미칩니다. 단지 할당 max_connections. 너무 많은 연결을 사용하면 MySQL이 많은 RAM을 사용하고 불필요하게 MySQL 서버 속도를 늦출 수 있습니다. thread_cache비교적 높은 설정을 유지하십시오 . 연결을 열 때 속도가 느려지는 것을 방지하려면 최소 16 개가 충분해야합니다. skip-name-resolve DNS 조회를 제거하는 데 사용 합니다. 쿼리가 자주 반환되고 데이터가 너무 많이 변경되지 않는 경우 쿼리 캐시를 사용합니다. 또 다른 해결책은 temp_table_size디스크 쓰기를 방지하기 위해 늘리는 것입니다. max_heap_table_size 을 늘리면 디스크 쓰기가 방지됩니다. sort_buffer_size이 변수는 연결별로 구성되고 모든 메모리를 매우 빠르게 사용할 수 있으므로 너무 높게 설정하지 마십시오 . 설정 innodb_flush_log_at_trx_commit = 0은 성능을 향상시킬 수 있습니다.
--문자열타입 스키마체크 select table_schema, table_name, column_name, column_type, , character_set_name, collation_name from information_schema.columns where table_schema='employee' and column_name ='%dept_no%' ;
-- 숫자타입의 스키마체크 select table_schema, table_name, column_name , column_type, character_set_name, collation_name from information_schema.columns where table_schema='sakila' and column_name like '%film_id%' ;
SUM (DATA_LENGTH) : 인덱스가없는 데이터 크기 SUM (INDEX_LENGTH) : 데이터없는 인덱스 크기
팁 이러한 종류의 쿼리를 실행하면 리소스가 많이 소모됩니다.
테이블 수가 많은 경우 몇 분 동안 서버가 정지 될 수 있습니다.
테이블이 10,000 개 있으면 10 분,
innodb_stats_on_metadata를 비활성화하면 1 분을 쉽게 계산할 수 있습니다.
MariaDB [(none)]> SET innodb_stats_on_metadata = 0;
InnoDB/XtraDB
그 성능에는 비용이 듭니다! 비용은 데이터베이스 크기보다 사용 가능한 충분한 RAM이 있어야한다는 것입니다. 인덱스도 캐시되기 때문입니다. InnoDB의 일반적인 값은 다음 표에 나와 있습니다.
Pool size and statistics
엔진을 위해 예약해야하는 RAM 양을 정확히 알 수있는 가장 좋은 방법은
다음 명령을 실행하여 엔진 통계를 표시하는 것
MariaDB [(none)]> SHOW engine innodb STATUS\G;
*************************** 1. row ***************************
Type: InnoDB
[...]
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 826540032; in additional pool allocated 0
Total memory allocated by read views 112
Internal hash tables (constant factor + variable factor)
Adaptive hash index 18423648 (12750568 + 5673080)
Page hash 797656 (buffer pool 0 only)
Dictionary cache 4132069 (3189008 + 943061)
File system 171664 (82672 + 88992)
Lock system 1993392 (1993016 + 376)
Recovery system 0 (0 + 0)
Dictionary memory allocated 943061
Buffer pool size 49151
Buffer pool size, bytes 805289984
Free buffers 18830
Database pages 29975
Old database pages 11052
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 50, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 28131, created 1844, written 281524
0.00 reads/s, 0.00 creates/s, 16.12 writes/s
Buffer pool hit rate 1000 / 1000, young-making rate 0 / 1000 not 0 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 29975, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
[...]
1 row in set (0.00 sec)
Buffer pool size: 49151 * 16 * 1024 = 768 MB
Free buffers: 18830 * 16 * 1024 = 294 MB
위 결과는 충분함. 만약 충분하지 않다면 더 크게 설정할 수 있음
[mysqld]
innodb_buffer_pool_size = 1024M ( 인스턴스 재시작 필요)
Redo logs
리두로그 크기 변경시 다음 순서대로 해야함(오류방지를 위해)
Change the size of the redo logs per file (2 by default) in your configuration file:
Copy
[mysqld]
innodb_log_file_size = 512M
Force the syncing data to the redo logs:
Copy
MariaDB [(none)]> SET GLOBAL innodb_fast_shutdown = 0;
Stop the MariaDB instance:
Copy
service mysql stop
Remove the current redo logs:
Copy
rm -f /var/lib/mysql/ib_logfile*
Start MariaDB:
Copy
service mysql start
Transaction commits and logs
innodb_flush_log_at_trx_commit 성능에 영향을 준다
SHOW SESSION VARIABLES LIKE 'innodb_flush_log_at_trx_commit';
1: 가장 안전함 그러나 쓸때마다 동기화 -> 오버헤드 발생할 수 있음
2: 초당 한번 디스크에 쓴다 - 덜 안전 -> 하지만 복제를 사용하는 경우 문제가 되지 않음
3: 가장 빠름 -> 데이터가 손실되어도 되는경우 사용 -> 가장위험 -> 따라서 레플리케이션(슬레이브)에만 사용할것
[mysqld]
innodb_flush_log_at_trx_commit = 2
sync_binlog=0
sync_binlog : 1 -> 가장 안전
sync_binlog : 0 -> 성능에 가장 좋음 -> 배터리 보호 기능이있는 RAID 카드를 얻는 것이 좋다.
sync_binlog value값 확인
SHOW SESSION VARIABLES LIKE 'sync_binlog';
즉시변경을 원할 경우
MariaDB [(none)]> SET global sync_binlog=0; MariaDB [(none)]> SET GLOBAL innodb_flush_log_at_trx_commit=2;
마지막으로 중요한 옵션은 innodb_max_dirty_pages_pct입니다.
설정 한 InnoDB / XtraDB 버퍼 풀 크기에 포함 된 최대 더티 페이지의 백분율입니다.
예를 들어 버퍼 풀 크기를 100GB로 설정하고 리두 로그를 2GB로 설정 한 경우 기본적으로 RAM에서 수정 된 데이터의 75 % 만 허용됩니다. 그러나 리두 로그 (ib_logfile) 크기는 2GB에 불과합니다! innodb_max_dirty_pages_pct의 백분율을 줄이면 InnoDB / XtraDB가 더 자주 플러시되고 시스템 충돌로부터 더 잘 보호됩니다.
인스턴스사양을 한단계 늘리는것과 innodb_buffer_pool_size 를 75% 이상이 되도록 수동으로 설정하는 것 중 권장되는 방법은 무었일까?
-- inodb_buffer_pool_size 계산방법 show global status like 'Innodb_buffer_pool_pages_data'; -- IBPDataPages 2976794 show global status like 'Innodb_buffer_pool_pages_total';-- IBPTotalPages 3014656 SHOW GLOBAL STATUS LIKE 'Innodb_page_size'; -- IPS 16384