Mysql进程占CPU使用率的3500%以上,Qcache_lowmem_prunes占用率过高

时间:2018-02-22 09:21:01

标签: mysql cpu-usage

我遇到了昨晚在线用户急剧增加后mysql CPU使用率出现问题。平均服务器负载为150(1分钟),顶部的mysql CPU使用率为3500-4000%。 show processlist;结果是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.

2 个答案:

答案 0 :(得分:1)

我已将query_cache_size更改为128M。 mysql procces使用的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%

答案 1 :(得分:1)

Wilson Hauck感谢您的回复。 我在编写时只将query_cache_min_res_unit更改为512。 FLUSH STATUS后10小时:

| Qcache_free_blocks      | 65446    |
| Qcache_free_memory      | 53083696 |
| Qcache_hits             | 39641904 |
| Qcache_inserts          | 2559829  |
| Qcache_lowmem_prunes    | 240861   |
| Qcache_not_cached       | 2564542  |
| Qcache_queries_in_cache | 155462   |
| Qcache_total_blocks     | 385780   |

AVG Query Size = 1385
Frag Indicator = 16.96%
Utilisation = 80%
Removal Ratio = 9.4%
Hit Rate = 88.56%

如您所见,去除率现在低于10%。我认为这很好。我真的需要更改其他变量吗?