MySQL + php 由于 CPU 使用率过高导致应用程序崩溃

MySQL + php 由于 CPU 使用率过高导致应用程序崩溃

就在最近,我维护的应用程序开始崩溃,mysql 的 CPU 使用率达到 100%... 甚至更高 :) 应用程序本身相当老旧,并且有很多慢查询,但在指责它之前,我想检查一下这是否不是 mysql 的问题。我不想问,但有人能看看SHOW ENGINE INNODB STATUS并告诉我其中是否有可疑之处吗?

=====================================
2022-09-06 09:41:55 0x7fc0d07b6700 INNODB MONITOR OUTPUT
=====================================
Per second averages calculated from the last 19 seconds
-----------------
BACKGROUND THREAD
-----------------
srv_master_thread loops: 331407 srv_active, 0 srv_shutdown, 746026 srv_idle
srv_master_thread log flush and writes: 1077433
----------
SEMAPHORES
----------
OS WAIT ARRAY INFO: reservation count 10587175
OS WAIT ARRAY INFO: signal count 16395655
RW-shared spins 0, rounds 53351140, OS waits 6923021
RW-excl spins 0, rounds 53028151, OS waits 518758
RW-sx spins 2458, rounds 50803, OS waits 1261
Spin rounds per wait: 53351140.00 RW-shared, 53028151.00 RW-excl, 20.67 RW-sx
------------------------
LATEST FOREIGN KEY ERROR
------------------------

------------
TRANSACTIONS
------------
Trx id counter 51455398
Purge done for trx's n:o < 51455398 undo n:o < 0 state: running but idle
History list length 41
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 421941565186184, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421941565188024, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421941565189864, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421941565183424, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421941565187104, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421941565182504, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421941565185264, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421941565180664, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421941565181584, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421941565184344, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
---TRANSACTION 421941565179744, not started
0 lock struct(s), heap size 1136, 0 row lock(s)
--------
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] , aio writes: [0, 0, 0, 0] ,
 ibuf aio reads:, log i/o's:, sync i/o's:
Pending flushes (fsync) log: 0; buffer pool: 0
3407791191 OS file reads, 23186343 OS file writes, 2496201 OS fsyncs
1 pending preads, 0 pending pwrites
3625.23 reads/s, 16384 avg bytes/read, 124.73 writes/s, 14.53 fsyncs/s
-------------------------------------
INSERT BUFFER AND ADAPTIVE HASH INDEX
-------------------------------------
Ibuf: size 1, free list len 3093, seg size 3095, 718207 merges
merged operations:
 insert 773740, delete mark 82990, delete 494
discarded operations:
 insert 0, delete mark 0, delete 0
Hash table size 34679, node heap has 1 buffer(s)
Hash table size 34679, node heap has 12 buffer(s)
Hash table size 34679, node heap has 73 buffer(s)
Hash table size 34679, node heap has 50 buffer(s)
Hash table size 34679, node heap has 8 buffer(s)
Hash table size 34679, node heap has 45 buffer(s)
Hash table size 34679, node heap has 2 buffer(s)
Hash table size 34679, node heap has 18 buffer(s)
32794.22 hash searches/s, 21657.81 non-hash searches/s
---
LOG
---
Log sequence number 94588304242
Log flushed up to   94588304242
Pages flushed up to 94588300431
Last checkpoint at  94588296730
0 pending log flushes, 0 pending chkp writes
1221882 log i/o's done, 3.05 log i/o's/second
----------------------
BUFFER POOL AND MEMORY
----------------------
Total large memory allocated 137428992
Dictionary memory allocated 3122549
Buffer pool size   8192
Free buffers       634
Database pages     7349
Old database pages 2732
Modified db pages  191
Pending reads      1
Pending writes: LRU 0, flush list 0, single page 0
Pages made young 105805584, not young 27891291271
0.00 youngs/s, 0.00 non-youngs/s
Pages read 3407821728, created 13603254, written 21494430
0.00 reads/s, 0.00 creates/s, 0.00 writes/s
Buffer pool hit rate 982 / 1000, young-making rate 0 / 1000 not 374 / 1000
Pages read ahead 0.00/s, evicted without access 0.00/s, Random read ahead 0.00/s
LRU len: 7349, unzip_LRU len: 0
I/O sum[276774]:cur[88], unzip sum[0]:cur[0]
--------------
ROW OPERATIONS
--------------
0 queries inside InnoDB, 0 queries in queue
1 read views open inside InnoDB
Process ID=1, Main thread ID=140466150430464, state: sleeping
Number of rows inserted 428234279, updated 1035424, deleted 45779, read 70493463554
2454.98 inserts/s, 1.42 updates/s, 0.05 deletes/s, 66260.57 reads/s
----------------------------
END OF INNODB MONITOR OUTPUT
============================

答案1

每秒速率=RPS;

建议考虑对 my.cnf [mysqld] 部分进行调整,以减少 CPU 繁忙

innodb_buffer_pool_size=2G  # from 128M to reduce innodb_buffer_pool_reads RPS of 3,142
read_rnd_buffer_size=32K  # from 256K to reduce handler_read_rnd_next RPS of 32,190
innodb_io_capacity=900  # from 200 to use more IOPS of your NVME storage devices 
net_buffer_length=96K  # from 16K to reduce packet in/out count

请查看个人资料以获取联系信息和免费实用脚本,以协助进行性能调整。还有更多调整需要完成。

相关内容