Mysql 进程 CPU 使用率超过 3500%,Qcache_lowmem_prunes 过高

标签 mysql cpu-usage

昨晚在线用户急剧增加后,我遇到了mysql CPU使用问题。平均服务器负载为150(1分钟),top中mysql CPU使用率为3500-4000%。显示进程列表;结果是 250 个查询。以下是一些设置和状态:

max_connections=400
query_cache_type=1
join_buffer_size=4096
query_cache_size=5M
query_cache_limit=1048576
query_cache_min_res_unit=4096

这里是执行

show status like '%qcach%';

30秒内3次

+-------------------------+------------+
| Variable_name           | Value      |
+-------------------------+------------+
| Qcache_free_blocks      | 597        |
| Qcache_free_memory      | 1658184    |
| Qcache_hits             | 1813237610 |
| Qcache_inserts          | 456473072  |
| Qcache_lowmem_prunes    | 433310255  |
| Qcache_not_cached       | 105476947  |
| Qcache_queries_in_cache | 1564       |
| Qcache_total_blocks     | 4027       |
+-------------------------+------------+
+-------------------------+------------+
| Variable_name           | Value      |
+-------------------------+------------+
| Qcache_free_blocks      | 429        |
| Qcache_free_memory      | 1422288    |
| Qcache_hits             | 1813245095 |
| Qcache_inserts          | 456475419  |
| Qcache_lowmem_prunes    | 433312602  |
| Qcache_not_cached       | 105477523  |
| Qcache_queries_in_cache | 1553       |
| Qcache_total_blocks     | 3896       |
+-------------------------+------------+
+-------------------------+------------+
| Variable_name           | Value      |
+-------------------------+------------+
| Qcache_free_blocks      | 481        |
| Qcache_free_memory      | 1546088    |
| Qcache_hits             | 1813254695 |
| Qcache_inserts          | 456477824  |
| Qcache_lowmem_prunes    | 433314721  |
| Qcache_not_cached       | 105478263  |
| Qcache_queries_in_cache | 1699       |
| Qcache_total_blocks     | 4146       |
+-------------------------+------------+

服务器配置:

2 x Intel(R) Xeon(R) CPU E5-2650 v4 @ 2.20GHz.
64GB RAM
Mysql running on SSDs.

最佳答案

我已将query_cache_size更改为128M。 mysql 进程使用的 CPU 比以前少得多。

冲洗状态2分钟后结果:

| Qcache_free_blocks      | 15777    |
| Qcache_free_memory      | 66772864 |
| Qcache_hits             | 74013    |
| Qcache_inserts          | 5293     |
| Qcache_lowmem_prunes    | 0        |
| Qcache_not_cached       | 5125     |
| Qcache_queries_in_cache | 37880    |
| Qcache_total_blocks     | 92907 

但是,5-10分钟后Qcache_lowmem_prunes再次开始增加(可能比以前慢,但仍然以每秒50-100点的速度增加)。

我认为问题不再是query_cache_size。

冲水后7分钟:

| Qcache_free_blocks      | 14825    |
| Qcache_free_memory      | 54665504 |
| Qcache_hits             | 534784   |
| Qcache_inserts          | 44569    |
| Qcache_lowmem_prunes    | 6194     |
| Qcache_not_cached       | 34718    |
| Qcache_queries_in_cache | 49212    |
| Qcache_total_blocks     | 114243   |
+-------------------------+----------+

AVG Query Size = 1616
Frag Indicator = 12.98%
Utilisation = 59.27%
Removal Ratio = 13.9%
Hit Rate = 87.09%

之后我将 query_cache_min_res_unit 更改为 2048。 冲洗后10分钟状态:

| Qcache_free_blocks      | 21987    |
| Qcache_free_memory      | 38858856 |
| Qcache_hits             | 255849   |
| Qcache_inserts          | 20100    |
| Qcache_lowmem_prunes    | 15638    |
| Qcache_not_cached       | 16691    |
| Qcache_queries_in_cache | 64573    |
| Qcache_total_blocks     | 152132   |

AVG Query Size = 1477
Frag Indicator = 14.45%
Utilisation = 71%
Removal Ratio = 79%
Hit Rate = 87%

关于Mysql 进程 CPU 使用率超过 3500%,Qcache_lowmem_prunes 过高,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48923630/

相关文章:

mysql - 如何使用第一个相关日期连接两个表?

mysql - 主键继续在此处添加 id 号,例如已删除的项目

java - CentOS 6 中 JVM 的 CPU 使用率总是超过 100%

c++ - 查找快速进程的 CPU 使用率

html - 浏览器是否渲染不在视口(viewport)内的 Canvas 元素?

Android - Handset built in Developer Tools - "Show Cpu Usage"选项是什么意思?

python - 如何将多线程添加到连续的 Python 函数中?

mysql - 有没有一种简单的方法可以在带有 MySQL 后端的 Access 中按表单查询?

php - mysql仅在post包含数据的情况下更新数据

mysql - 合并日期和人员状态列之间的 2 结果(Sql 查询)