redis - 服务器单核100%问题的排查
现象
今天查看服务器时,mongo内存吃了5G,redis单核也100%了..真是..
排查
引起redis CPU100%的原因有几个
- reids连接数过高
- 数据持久化引起的阻塞
- 主从频繁全量同步
- value值过大
- redis慢查询
服务器没开持久化,单机运行
排除2
3
的可能
我们进redis-cli
看一下info
里面内容很多可以看这里
127.0.0.1:6379> info clients
# Clients
connected_clients:13
client_recent_max_input_buffer:4
client_recent_max_output_buffer:48
blocked_clients:0
tracking_clients:0
clients_in_timeout_table:0
(0.90s)
连接数不高,排除连接数太高的可能
[root@mail ~]# redis-cli -p 6379 --bigkeys -i 0.1
# Scanning the entire keyspace to find biggest keys as well as
# average sizes per key type. You can use -i 0.1 to sleep 0.1 sec
# per 100 SCAN commands (not usually needed).
[00.00%] Biggest string found so far '"mahua_row_scale37411"' with 6 bytes
[00.00%] Biggest string found so far '"mahua_row_scale34693"' with 7 bytes
[00.00%] Biggest string found so far '"seo_ua_pc_14444"' with 151 bytes
[00.00%] Biggest string found so far '"seo_ua_m_26483"' with 163 bytes
[00.00%] Biggest list found so far '"td_ip_life_port_118.81.119.196"' with 100 items
[00.01%] Biggest string found so far '"seo_cooike_clean_6721"' with 192 bytes
[00.04%] Biggest string found so far '"mahua_row_jsone6599c6e2c2e96bfd19c7969ec35625b"' with 215 bytes
没有大的value值, 也排除
[root@mail ~]# redis-cli
127.0.0.1:6379> slowlog get 3
1) 1) (integer) 166990785
2) (integer) 1641266385
3) (integer) 386244
4) 1) "keys"
2) "tdp_*_n_*"
5) "127.0.0.1:52804"
6) ""
2) 1) (integer) 166990784
2) (integer) 1641266385
3) (integer) 263181
4) 1) "keys"
2) "td_user_dot_wait_long_time_*"
5) "127.0.0.1:52820"
6) ""
3) 1) (integer) 166990783
2) (integer) 1641266384
3) (integer) 301927
4) 1) "keys"
2) "tdp3_qiyun_ip_*"
5) "127.0.0.1:52808"
6) ""
(0.77s)
看到了慢查询,一个查询居然能达到300ms
所以这里的问题是慢查询导致的..优化方向也就有了
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 【设计模式】告别冗长if-else语句:使用策略模式优化代码结构
· 提示词工程——AI应用必不可少的技术
· 字符编码:从基础到乱码解决
· 地球OL攻略 —— 某应届生求职总结