Я запускаю кластер Percona 5.6 (3 узла) в контейнерах lxc. Аппаратное обеспечение каждого узла выглядит следующим образом:
4 x Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40GHz (2 Sockets)
16GB RAM
130GB HD
Моя база данных имеет размер чуть менее 4 ГБ. Мне удалось настроить параметры конфигурации, чтобы выборы обрабатывались быстро. Однако я вижу, что некоторые UPDATE и INSERT работают довольно медленно (5 секунд +). Таким образом, должно быть какое-то узкое место, которое мне интересно, смогу ли я решить с помощью настройки конфигурации.
Я знаю, что для нескольких таблиц может потребоваться удаление некоторых неиспользуемых индексов, но мне было интересно, что еще нужно изучить, чтобы повысить производительность запросов. Нагрузка не такая уж и большая, около 100 пользователей, так как это внутренняя система.
innodb_buffer_pool_size: 8G
innodb_log_file_size: 256M
innodb_log_buffer_size: 128M
innodb_flush_log_at_trx_commit: 2
innodb_thread_concurrency: 0
innodb_flush_method: O_DIRECT
innodb_file_per_table: ON
Вот мой SHOW ENGINE INNODB STATUS:
| InnoDB | |
=====================================
2018-08-14 15:22:02 7f3330863700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 9 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 22626 srv_active, 0 srv_shutdown, 79338 srv_idle
srv_master_thread log flush and writes: 101963
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 86267
OS WAIT ARRAY INFO: signal count 1537634
Mutex spin waits 800672, rounds 1115180, OS waits 19238
RW-shared spins 605666, rounds 2660513, OS waits 58073
RW-excl spins 79517, rounds 2104544, OS waits 8150
Spin rounds per wait: 1.39 mutex, 4.39 RW-shared, 26.47 RW-excl
------------
TRANSACTIONS
------------
Trx id counter 1057692300
Purge done for trx's n:o < 1057692300 undo n:o < 0 state: running but idle
History list length 2030
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 0, not started
MySQL thread id 621427, OS thread handle 0x7f3330863700, query id 7014924 localhost myuser init
SHOW ENGINE INNODB STATUS
---TRANSACTION 0, not started
MySQL thread id 608823, OS thread handle 0x7f33311c8700, query id 6968932 10.0.10.200 myuser
---TRANSACTION 1057692298, not started
MySQL thread id 2, OS thread handle 0x7f35905c8700, query id 7014913 committed 7569847
--------
FILE I/O
--------
I/O thread 0 state: waiting for completed aio requests (insert buffer thread)
I/O thread 1 state: waiting for completed aio requests (log thread)
I/O thread 2 state: waiting for completed aio requests (read thread)
I/O thread 3 state: waiting for completed aio requests (read thread)
I/O thread 4 state: waiting for completed aio requests (read thread)
I/O thread 5 state: waiting for completed aio requests (read thread)
I/O thread 6 state: waiting for completed aio requests (write thread)
I/O thread 7 state: waiting for completed aio requests (write thread)
I/O thread 8 state: waiting for completed aio requests (write thread)
I/O thread 9 state: waiting for completed aio requests (write thread)
Pending normal aio reads: 0 [0, 0, 0, 0] , aio writes: 0 [0, 0, 0, 0] ,
ibuf aio reads: 0, log i/o's: 0, sync i/o's: 0
Pending flushes (fsync) log: 0; buffer pool: 0
189853 OS file reads, 666579 OS file writes, 119023 OS fsyncs
0.00 reads/s, 0 avg bytes/read, 14.78 writes/s, 2.89 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 926, seg size 928, 3164 merges
merged operations:
insert 3331, delete mark 1275, delete 655
discarded operations:
insert 0, delete mark 0, delete 0
9.67 hash searches/s, 95.66 non-hash searches/s
---
LOG
---
Log sequence number 75281381079
Log flushed up to 75281381079
Pages flushed up to 75281381079
Last checkpoint at 75281381079
Max checkpoint age 434154333
Checkpoint age target 420587011
Modified age 0
Checkpoint age 0
0 pending log writes, 0 pending chkp writes
142005 log i/o's done, 2.00 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total memory allocated 8942256128; in additional pool allocated 0
Total memory allocated by read views 776
Internal hash tables (constant factor + variable factor)
Adaptive hash index 411468128 (151384312 + 260083816)
Page hash 1107208 (buffer pool 0 only)
Dictionary cache 39612436 (35402768 + 4209668)
File system 1602712 (812272 + 790440)
Lock system 21251648 (21250568 + 1080)
Recovery system 0 (0 + 0)
Dictionary memory allocated 4209668
Buffer pool size 524280
Buffer pool size, bytes 8589803520
Free buffers 82805
Database pages 425581
Old database pages 157253
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 223, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 189492, created 236089, written 496948
0.00 reads/s, 0.00 creates/s, 12.55 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: 425581, unzip_LRU len: 38
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
----------------------
INDIVIDUAL BUFFER POOL INFO
----------------------
---BUFFER POOL 0
Buffer pool size 65535
Buffer pool size, bytes 1073725440
Free buffers 9846
Database pages 53705
Old database pages 19844
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 27, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 24150, created 29555, written 83723
0.00 reads/s, 0.00 creates/s, 3.56 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: 53705, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 1
Buffer pool size 65535
Buffer pool size, bytes 1073725440
Free buffers 9114
Database pages 54443
Old database pages 20117
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 28, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 24455, created 29988, written 46033
0.00 reads/s, 0.00 creates/s, 0.67 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: 54443, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 2
Buffer pool size 65535
Buffer pool size, bytes 1073725440
Free buffers 10545
Database pages 53012
Old database pages 19588
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 27, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 23505, created 29507, written 64763
0.00 reads/s, 0.00 creates/s, 1.89 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: 53012, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 3
Buffer pool size 65535
Buffer pool size, bytes 1073725440
Free buffers 9551
Database pages 53984
Old database pages 19947
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 16, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 24437, created 29547, written 61138
0.00 reads/s, 0.00 creates/s, 0.89 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: 53984, unzip_LRU len: 5
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 4
Buffer pool size 65535
Buffer pool size, bytes 1073725440
Free buffers 10559
Database pages 52987
Old database pages 19579
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 29, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 23524, created 29463, written 69996
0.00 reads/s, 0.00 creates/s, 2.11 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: 52987, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 5
Buffer pool size 65535
Buffer pool size, bytes 1073725440
Free buffers 10906
Database pages 52633
Old database pages 19448
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 33, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 23070, created 29563, written 60299
0.00 reads/s, 0.00 creates/s, 1.56 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: 52633, unzip_LRU len: 33
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 6
Buffer pool size 65535
Buffer pool size, bytes 1073725440
Free buffers 10544
Database pages 53001
Old database pages 19583
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 20, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 23685, created 29316, written 52866
0.00 reads/s, 0.00 creates/s, 0.78 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: 53001, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
---BUFFER POOL 7
Buffer pool size 65535
Buffer pool size, bytes 1073725440
Free buffers 11740
Database pages 51816
Old database pages 19147
Modified db pages 0
Pending reads 0
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 43, not young 0
0.00 youngs/s, 0.00 non-youngs/s
Pages read 22666, created 29150, written 58130
0.00 reads/s, 0.00 creates/s, 1.11 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: 51816, unzip_LRU len: 0
I/O sum[0]:cur[0], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
0 read views open inside InnoDB
0 RW transactions active inside InnoDB
0 RO transactions active inside InnoDB
0 out of 1000 descriptors used
Main thread process no. 74272, id 139857921410816, state: sleeping
Number of rows inserted 12277268, updated 41111, deleted 326, read 31539377489
0.11 inserts/s, 0.67 updates/s, 0.00 deletes/s, 27069.99 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
ОБНОВЛЕНИЕ 1
Вот некоторые подробности о таблице, с которой чаще всего возникают проблемы:
Engine: Innodb
Row format: Compact
Column Count: 124
Table Row: 581705 (I know, not alot!)
AVG row length: 560
Data lenght: 310.9MB
Index lenght: 411.4MB
Max data length: 0.0bytes
Data free: 4.0mb
Table size (estimate): 722.3MB
file format: antelope
Auto Increment: 745745
Table collation: utf8_unicode_ci
Number of Indices: 34 (most are BTREE, single column, non-unique Indices)
Я думаю, что моя самая большая проблема с этой таблицей — это 1) количество индексов и 2) используемые типы данных. Существует довольно много использования «bigint (20) unsigned», которое я не могу только представить как совершенно ненужное. Наряду с полями «средний текст».
Я подозреваю, что вставки медленные из-за медленных обновлений. И я подозреваю, что это связано с количеством используемых индексов и больших типов данных.
Тем не менее, у меня есть много доступных ЦП / оперативной памяти, которые я могу использовать, если это необходимо, и я хотел бы знать, есть ли какие-либо дополнительные конфигурации, на которые я мог бы взглянуть.
ОБНОВЛЕНИЕ 2
Я включил userstat для определения некоторых неиспользуемых индексов с момента последнего перезапуска mysql (https://www.percona.com/blog/2012/06/30/find-unused-indexes/). Оказывается, я использовал только 15 из 34 индексов.
ОБНОВЛЕНИЕ 3
Вот вывод состояния во время резервного копирования потока:
iostat -xm 5
, чтобы увидеть статистику производительности диска? Если можете, разверните новый контейнер с инструментами для тестирования и выясните, нужна ли помощь MySQL или базовой инфраструктуре. Предлагает ли Percona проверку производительности в рамках поддержки? - person Kevin Bott   schedule 14.08.2018log_slow_verbosity=full
, чтобы вы могли видеть статистику InnoDB по запросу, а также время блокировки. Вы хотели бы знать, на что тратится время во время ваших обновлений. Ожидает блокировки? Он ждет IO? См. percona.com/doc/percona-server/LATEST/diagnostics. / - person Bill Karwin   schedule 15.08.2018