Redis之阻塞
1. 发现阻塞
jedis需要统计出异常,并打印到日志文件中
2. 内在原因
1. API或者数据结构使用不合理
1. 如何发现慢查询
1. 使用redis自带的慢查询方式,找到慢语句以后,可以向这两个方向调整。
1. 修改为低算法度的命令
2. 调整大对象
2. 如何发现大对象
redis-cli -h {ip} -p {port} --bigkeys
[root@datanode2 ~]# /usr/local/redis-3.0.6/bin/redis-cli -h 172.16.1.228 -c -p 6388 --bigkeys
# 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 hash found so far 'prod_extend_info_5971' with 5 fields
[00.00%] Biggest string found so far '0ABA59AE-91C3-4ACB-9EB6-776406F32E33' with 8 bytes
[00.00%] Biggest string found so far 'B96B4579-D037-4C1A-BD5E-E5358451572E' with 34 bytes
[00.00%] Biggest string found so far 'hdfs_products_2115827' with 1184 bytes
[00.01%] Biggest string found so far 'hdfs_products_2038485' with 1191 bytes
[00.02%] Biggest string found so far 'hdfs_products_2098878' with 1235 bytes
[00.02%] Biggest string found so far 'hdfs_products_100053011' with 1284 bytes
[00.13%] Biggest string found so far 'gtCart_522418' with 2235 bytes
[00.42%] Biggest string found so far 'gtCart_522576' with 2245 bytes
[00.47%] Biggest string found so far 'gtCart_380643' with 13101 bytes
[01.24%] Biggest hash found so far 'prod_extend_info_15139' with 6 fields
[01.78%] Biggest hash found so far 'new_edition_home_content' with 18 fields
[02.32%] Biggest list found so far 'home_zyk_brand' with 4 items
[02.97%] Biggest zset found so far '{home}_app_channel_model_sort_17' with 16 members
[16.67%] Biggest string found so far 'gtCart_280157' with 20139 bytes
[17.44%] Biggest hash found so far 'xc_spec_specvaluemap' with 94 fields
[23.08%] Biggest set found so far 'uc_member_notice_relation_key_1_3' with 3 members
[25.35%] Biggest set found so far '102_oneyuan_reward' with 4 members
[34.56%] Biggest hash found so far 'gtCollection_null' with 33727 fields
[36.36%] Biggest list found so far '{live_chat_history}_234' with 20 items
[46.51%] Biggest list found so far 'para_key_1' with 31 items
[56.58%] Biggest string found so far 'SPECIAL_PRODUCT_null' with 89358 bytes
[92.72%] Biggest list found so far 'platform_short_info_list' with 71 items
-------- summary -------
Sampled 690944 keys in the keyspace!
Total key length in bytes is 18758999 (avg len 27.15)
Biggest string found 'SPECIAL_PRODUCT_null' has 89358 bytes
Biggest list found 'platform_short_info_list' has 71 items
Biggest set found '102_oneyuan_reward' has 4 members
Biggest hash found 'gtCollection_null' has 33727 fields
Biggest zset found '{home}_app_channel_model_sort_17' has 16 members
670480 strings with 133206870 bytes (97.04% of keys, avg size 198.67)
6 lists with 140 items (00.00% of keys, avg size 23.33)
3 sets with 8 members (00.00% of keys, avg size 2.67)
20442 hashs with 126673 fields (02.96% of keys, avg size 6.20)
13 zsets with 80 members (00.00% of keys, avg size 6.15)
使用工具rdbtools
[root@localhost ~]# yum -y install python-pip python-redis
[root@localhost ~]# pip install rdbtools
安装python-lzf
pkg_resources.DistributionNotFound: The 'rdbtools==0.1.14' distribution was not found and is required by the application
执行命令:rdb -c memory /tmp/dump_81.rdb > /tmp/2.txt
grep -v '{prod}_other_color_new' /tmp/2.txt |awk -F ',' '{print $3,$7}' | sort -k2 -rn | head -10 分析结果
2. CPU饱和的问题
redis-cli --stat 通过这个命令查看每秒处理的请求
redis-cli info commandstats 分析不同命令的开销时间
3. 持久化相关的阻塞
1. fork阻塞
2. AOF刷盘阻塞
3. HugePage写操作阻塞
3. 外在原因
1. CPU竞争
2. 内存交换
3. 网络问题
一往无前虎山行,拨开云雾见光明

浙公网安备 33010602011771号