서버에서 MySQL 구성을 수정하려고합니다. 우리 앱의 특징은 많은 데이터가 단일 테이블 (현재 3 억 행 이상)에 저장되어 있다는 것입니다. 이 테이블은 종종 인서트에 사용됩니다 (항상 제공됩니다).
몇 초 이상 걸리는 테이블에서 선택 쿼리를 실행하면 모든 삽입 (정확하게 커밋)이 테이블 액세스를 기다리고 있으며 앱이 응답하지 않습니다.
내가 아는 한 InnoDB는 select가 실행될 때 테이블을 잠그지 않습니다. 그러면 왜 차단 차단 테이블이 사용됩니까?
나는 innotop으로 이유를 찾으려고 노력했지만 결과를 해석하는 방법과 검색 위치를 잘 모르겠습니다. 필요한 정보를 알려 주시면 여기에 게시하겠습니다.
+-----+---------+-----------+--------+---------+------+----------------+-----------------------------------------------------------------------------------------------------------------------------------+
| Id | User | Host | db | Command | Time | State | Info |
+-----+---------+-----------+--------+---------+------+----------------+-----------------------------------------------------------------------------------------------------------------------------------+
| 1 | root | localhost | dbname | Query | 29 | NULL | COMMIT |
| 2 | root | localhost | dbname | Query | 30 | NULL | COMMIT |
| 4 | root | localhost | dbname | Query | 29 | NULL | COMMIT |
| 5 | root | localhost | dbname | Query | 29 | NULL | COMMIT |
| 6 | root | localhost | dbname | Query | 25 | NULL | COMMIT |
| 7 | root | localhost | dbname | Query | 0 | NULL | show full processlist |
| 13 | user | localhost | dbname | Query | 25 | NULL | COMMIT |
| 38 | user | localhost | dbname | Sleep | 0 | | NULL |
| 39 | user | localhost | dbname | Sleep | 9017 | | NULL |
| 40 | user | localhost | dbname | Query | 33 | Sorting result | SELECT * FROM `large_table` WHERE (`large_table`.`hotspot_id` = 3000064) ORDER BY discovered_at LIMIT 799000, 1000 |
| 60 | user | localhost | dbname | Sleep | 1033 | | NULL |
| 83 | root | localhost | dbname | Sleep | 3728 | | NULL |
| 112 | root | localhost | NULL | Sleep | 6 | | NULL |
+-----+---------+-----------+--------+---------+------+----------------+-----------------------------------------------------------------------------------------------------------------------------------+
=====================================
110824 12:24:24 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 19 seconds
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 1521117, signal count 1471216
Mutex spin waits 0, rounds 20647617, OS waits 239914
RW-shared spins 2119697, OS waits 1037149; RW-excl spins 505734, OS waits 218177
------------
TRANSACTIONS
------------
Trx id counter 0 412917332
Purge done for trx's n:o < 0 412917135 undo n:o < 0 0
History list length 48
Total number of lock structs in row lock hash table 5
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0 0, not started, process no 28363, OS thread id 1092766032
MySQL thread id 83, query id 3249941 localhost root
---TRANSACTION 0 412901582, not started, process no 28363, OS thread id 1144449360
MySQL thread id 60, query id 3677008 localhost user
---TRANSACTION 0 412917189, not started, process no 28363, OS thread id 1144314192
MySQL thread id 43, query id 3905773 localhost root
---TRANSACTION 0 412534255, not started, process no 28363, OS thread id 1092630864
MySQL thread id 39, query id 14279 localhost user
---TRANSACTION 0 412917331, not started, process no 28363, OS thread id 1144179024
MySQL thread id 38, query id 3908045 localhost user
---TRANSACTION 0 412917201, not started, process no 28363, OS thread id 1092495696
MySQL thread id 13, query id 3908257 localhost user
---TRANSACTION 0 412538821, not started, process no 28363, OS thread id 1092360528
MySQL thread id 7, query id 3908258 localhost root
show engine innodb status
---TRANSACTION 0 412917330, ACTIVE 6 sec, process no 28363, OS thread id 1144043856
2 lock struct(s), heap size 368, undo log entries 1
MySQL thread id 2, query id 3907373 localhost root
COMMIT
Trx read view will not see trx with id >= 0 412917331, sees < 0 412917131
---TRANSACTION 0 412917328, ACTIVE 6 sec, process no 28363, OS thread id 1092225360
2 lock struct(s), heap size 368, undo log entries 1
MySQL thread id 6, query id 3907345 localhost root
COMMIT
Trx read view will not see trx with id >= 0 412917329, sees < 0 412917131
---TRANSACTION 0 412917326, ACTIVE 6 sec, process no 28363, OS thread id 1091955024
2 lock struct(s), heap size 368, undo log entries 1
MySQL thread id 4, query id 3907335 localhost root
COMMIT
Trx read view will not see trx with id >= 0 412917327, sees < 0 412917131
---TRANSACTION 0 412917324, ACTIVE 6 sec, process no 28363, OS thread id 1092090192
2 lock struct(s), heap size 368, undo log entries 1
MySQL thread id 5, query id 3907328 localhost root
COMMIT
Trx read view will not see trx with id >= 0 412917325, sees < 0 412917131
---TRANSACTION 0 412917321, ACTIVE (PREPARED) 7 sec, process no 28363, OS thread id 1143908688 preparing
2 lock struct(s), heap size 368, undo log entries 1
MySQL thread id 1, query id 3907125 localhost root
COMMIT
Trx read view will not see trx with id >= 0 412917322, sees < 0 412917131
---TRANSACTION 0 412917131, ACTIVE 20 sec, process no 28363, OS thread id 1074075984, thread declared inside InnoDB 111
mysql tables in use 1, locked 0
MySQL thread id 40, query id 3904958 localhost user Sorting result
SELECT * FROM `large_table` WHERE (`large_table`.`hotspot_id` = 3000064) ORDER BY discovered_at LIMIT 848000, 1000
Trx read view will not see trx with id >= 0 412917132, sees < 0 412917132
--------
FILE I/O
--------
I/O thread 0 state: waiting for i/o request (insert buffer thread)
I/O thread 1 state: waiting for i/o request (log thread)
I/O thread 2 state: waiting for i/o request (read thread)
I/O thread 3 state: waiting for i/o request (write thread)
Pending normal aio reads: 0, aio writes: 0,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 1; buffer pool: 0
3510225 OS file reads, 284998 OS file writes, 202897 OS fsyncs
1.05 reads/s, 21299 avg bytes/read, 8.10 writes/s, 7.58 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 275, free list len 13392, seg size 13668,
489950 inserts, 491830 merged recs, 10986 merges
Hash table size 8850487, used cells 8127172, node heap has 32697 buffer(s)
71914.53 hash searches/s, 8701.91 non-hash searches/s
---
LOG
---
Log sequence number 157 3331524445
Log flushed up to 157 3331521939
Last checkpoint at 157 3326072846
1 pending log writes, 0 pending chkp writes
199025 log i/o's done, 7.53 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 4788954432; in additional pool allocated 1048576
Buffer pool size 262144
Free buffers 0
Database pages 229447
Modified db pages 1439
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages read 7453325, created 14887, written 118658
1.37 reads/s, 0.11 creates/s, 0.53 writes/s
Buffer pool hit rate 1000 / 1000
--------------
ROW OPERATIONS
--------------
1 queries inside InnoDB, 0 queries in queue
7 read views open inside InnoDB
Main thread process no. 28363, id 1091684688, state: flushing log
Number of rows inserted 1093064, updated 249134, deleted 1405, read 1115880534
7.89 inserts/s, 2.47 updates/s, 0.05 deletes/s, 80953.21 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================
편집하다:
이것을 명확히 해 주셔서 감사합니다.
이제 질문을 두 가지 경우로 나눠야합니다.
이 단일 테이블을 잠그면 전체 앱이 '중지'되는 것이 정상입니까? 다른 테이블에 대한 쿼리에 대해 DB가 응답하지 않아야합니까? 버퍼가 너무 낮게 설정되어 있습니까?
이 테이블을 MyISAM으로 전환하면 도움이됩니까? 이 테이블에서 거래가 전혀 필요하지 않습니다. 그런 상황에서 다른 잠금 장치가 없습니까 (긴 선택 + 많은 빠른 삽입물)?
EDIT2 :
삽입 쿼리는 다음과 같습니다.
INSERT INTO `large_table` (`device_address`, `hotspot_id`, `minute`, `created_at`, `updated_at`, `discovered_with_hci`, `hour`, `rssi`, `day`, `device_class`, `discovered_at`) VALUES('10:40:03:90:10:40', 3000008, 1, '2011-08-22 05:01:08', '2011-08-22 05:01:08', -1, 5, -79, '2011-08-22 05:01:01', '0', '2011-08-22 05:01:01')
이것이 인덱스가 정의 된 것입니다.
+-------------+------------+----------------------------------------------+--------------+---------------------+-----------+-------------+----------+--------+------+------------+---------+
| Table | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment |
+-------------+------------+----------------------------------------------+--------------+---------------------+-----------+-------------+----------+--------+------+------------+---------+
| large_table | 0 | PRIMARY | 1 | id | A | 92396334 | NULL | NULL | | BTREE | |
| large_table | 1 | index_large_table_on_discovered_with_hci | 1 | discovered_with_hci | A | 18 | NULL | NULL | YES | BTREE | |
| large_table | 1 | index_large_table_on_hotspot_id | 1 | hotspot_id | A | 18 | NULL | NULL | YES | BTREE | |
| large_table | 1 | index_large_table_on_day_and_hour_and_minute | 1 | day | A | 18 | NULL | NULL | YES | BTREE | |
| large_table | 1 | index_large_table_on_day_and_hour_and_minute | 2 | hour | A | 18 | NULL | NULL | YES | BTREE | |
| large_table | 1 | index_large_table_on_day_and_hour_and_minute | 3 | minute | A | 537187 | NULL | NULL | YES | BTREE | |
| large_table | 1 | index_large_table_on_created_at | 1 | created_at | A | 8399666 | NULL | NULL | YES | BTREE | |
| large_table | 1 | index_large_table_on_rssi | 1 | rssi | A | 18 | NULL | NULL | YES | BTREE | |
+-------------+------------+----------------------------------------------+--------------+---------------------+-----------+-------------+----------+--------+------+------------+---------+
편집 3 :
이러한 쿼리 중에 전체 응용 프로그램이 응답하지 않는 이유는 무엇입니까? 'large_table'에만 영향을 미쳐서는 안됩니까?
어쩌면 mysql 설정에 문제가 있습니까? 서버는 16GB RAM이 장착 된 4 코어 Xeon 2GHz입니다. MySQL + Rails 앱을 실행합니다
내 구성 매개 변수 :
skip-external-locking
key_buffer = 64M
max_allowed_packet = 16M
thread_stack = 128K
thread_cache_size = 8
query_cache_size = 32M
tmp_table_size = 64M
max_heap_table_size = 64M
table_cache = 256
read_rnd_buffer_size = 512K
sort_buffer_size = 2M
myisam-recover = BACKUP
max_connections = 200
query_cache_limit = 1M
long_query_time = 200
max_binlog_size = 100M
innodb_buffer_pool_size = 4G
safe-updates
max_join_size=100000000
Mysqltuner 스크립트는 다음을 제안합니다.
long_query_time (<= 10)
innodb_buffer_pool_size (>= 62G)
show engine innodb status;
.