nginx+php+mysql这个架构中,出现了VPS偶发性100%CPU资源耗尽,大概持续5分钟又恢复正常,通过检查Mysql慢日志找到了问题:
Time Id Command Argument
# Time: 2024-06-03T11:56:09.101160Z
# User@Host: blog_is36_com[blog_is36_com] @ localhost [] Id: 135566
# Query_time: 8.490175 Lock_time: 0.159524 Rows_sent: 0 Rows_examined: 1386
use blog_is36_com;
SET timestamp=1717415769;
DELETE FROM sablog_sessions WHERE hash='XHm2K9' OR lastactivity<(1717415760-900) OR ('0'<>'0' AND uid='0') OR (uid='0' AND ip1='60' AND ip2='188' AND ip3='9' AND ip4='208' AND lastactivity>1717415760-60) OR (is_robot = '1' AND lastactivity < (1717415760-900));
--------------
# Time: 2024-04-15T10:20:42.123456Z
# User@Host: root[root] @ localhost []
# Query_time: 12.345678 Lock_time: 0.123456 Rows_sent: 456 Rows_examined: 12345
use dbname;
SET timestamp=1234567890;
SELECT * FROM table WHERE non_indexed_column = 'value';
# Time:这是查询执行的时间戳。
# User@Host:执行查询的用户是root,主机是localhost。
# Query_time:查询执行花费了12.345678秒。
# Lock_time:查询在锁定上花费了0.123456秒。
Rows_sent:查询发送了456行数据给客户端。
Rows_examined:查询检查了12345行数据,这可能是性能问题的一个指标,特别是如果检查的行数远大于发送的行数。
use dbname:表明这个查询是在dbname数据库上执行的。
SET timestamp:这是查询执行时的UNIX时间戳。
SELECT:这是实际执行的SQL语句。