問題描述
當(dāng) Azure Redis 服務(wù)器負(fù)載過高的情況下,使用時就會遇見連接超時篡殷,命令超時,IO Socket超時等異常埋涧。為了能定位是那些因素引起的板辽,可以參考微軟官方文檔( 管理 Azure Cache for Redis 的服務(wù)器負(fù)載 : https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-best-practices-server-load#avoid-long-running-commands) 開始以下因素的分析:
值大小 : 可以通過Redis-cli.exe 的bigkeys來進(jìn)行分析 [redis-cli.exe -h yourcachename.redis.cache.chinacloudapi.cn -p 6379 -a YourAccessKey --bigkeys ]
避免出現(xiàn)客戶端連接高峰 : 可以查看Redis Metrics中的連接數(shù)
內(nèi)存壓力 : 通過查看Redis Metrics中的內(nèi)存使用量
避免長時間運(yùn)行的命令 : 通過Azure Redis門戶上的console或者是Redis-cli.exe 來執(zhí)行 slowlog get 100指令
本文就重點(diǎn)演示在Azure Redis門戶上的console頁面執(zhí)行 slowlog get 100 指令。
問題回答
因?yàn)镽edis 服務(wù)器是單線程系統(tǒng)棘催。 長時間運(yùn)行的命令(官名:慢指令, Slowlog)可能導(dǎo)致客戶端出現(xiàn)延遲或超時劲弦,因?yàn)榉?wù)器在忙于處理長時間運(yùn)行的命令時無法響應(yīng)任何其他請求。那么醇坝,如何來查看慢指令呢邑跪?
第一步: 登錄Azure門戶,選擇需要查看的Redis服務(wù)呼猪,進(jìn)入Console頁面
第二步:在Console命令頁輸入:slowlog get 100
- slowlog get 100: 獲取當(dāng)前Redis服務(wù)中所記錄的慢指令信息画畅,每一個指令包含六部分內(nèi)容,id郑叠,unix時間夜赵,指令執(zhí)行時間(ms 微秒), 指令內(nèi)容,客戶端IP:端口乡革,客戶端機(jī)器名。
- **slowlog len **: 返回當(dāng)前Redis服務(wù)器中所記錄的慢指令日志中所記錄指令數(shù)
- **slowlog reset ** :清空當(dāng)前慢指令記錄
指令輸出示例:
Welcome to secure redis console! This console connects to your live redis server and all commands are run on the server.
WARNING: Use expensive commands with caution as they can impact your server load!
>slowlog get 100
1) 1) (integer) 16
2) (integer) 1639993957
3) (integer) 10012
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:14835"
6) ""
2) 1) (integer) 15
2) (integer) 1639993727
3) (integer) 10195
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:19468"
6) ""
3) 1) (integer) 14
2) (integer) 1639992068
3) (integer) 13279
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:46504"
6) ""
4) 1) (integer) 13
2) (integer) 1639990412
3) (integer) 14152
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:39900"
6) ""
5) 1) (integer) 12
2) (integer) 1639990251
3) (integer) 10710
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:52381"
6) ""
6) 1) (integer) 11
2) (integer) 1639989209
3) (integer) 11665
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:38779"
6) ""
7) 1) (integer) 10
2) (integer) 1639989142
3) (integer) 13642
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:12348"
6) ""
8) 1) (integer) 9
2) (integer) 1639988822
3) (integer) 22073
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:51454"
6) ""
9) 1) (integer) 8
2) (integer) 1639988414
3) (integer) 13668
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:1550"
6) ""
10) 1) (integer) 7
2) (integer) 1639987239
3) (integer) 18846
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:57350"
6) ""
11) 1) (integer) 6
2) (integer) 1639986196
3) (integer) 12921
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:1739"
6) ""
12) 1) (integer) 5
2) (integer) 1639986196
3) (integer) 15833
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:1739"
6) ""
13) 1) (integer) 4
2) (integer) 1639985175
3) (integer) 14434
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:1649"
6) ""
14) 1) (integer) 3
2) (integer) 1639984227
3) (integer) 61332
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:24878"
6) ""
15) 1) (integer) 2
2) (integer) 1639984227
3) (integer) 27560
4) 1) "GET"
2) "key:__rand_int__"
5) "167.220.233.137:7637"
6) ""
16) 1) (integer) 1
2) (integer) 1639983695
3) (integer) 10361
4) 1) "SET"
2) "Message_dd2_0"
3) "eyJ0eXAiOiJKV1QiLCJub25jZSI6Inp1d2hMNzhSWDJsdGZITlN1TDYyOEhpRDNrTzhWSnJXZl9CNEtVcjBFTWsiLCJhbGciOiJSUzI1NiIsIng1dCI6IkpSNGxDdzkw... (4140520 more bytes)"
5) "167.220.233.137:1166"
6) "MININT-S4MGVOU"
17) 1) (integer) 0
2) (integer) 1639983310
3) (integer) 16577
4) 1) "SET"
2) "Message_dd_2222"
3) "eyJ0eXAiOiJKV1QiLCJub25jZSI6Inp1d2hMNzhSWDJsdGZITlN1TDYyOEhpRDNrTzhWSnJXZl9CNEtVcjBFTWsiLCJhbGciOiJSUzI1NiIsIng1dCI6IkpSNGxDdzkw... (7774 more bytes)"
5) "167.220.233.137:58313"
6) "MININT-S4MGVOU"
>slowlog len
(integer) 17
>slowlog reset
OK >slowlog len
(integer) 0
Each entry from the slow log is comprised of the following six values:
- A unique progressive identifier for every slow log entry.
- The unix timestamp at which the logged command was processed.
- The amount of time needed for its execution, in microseconds.
- The array composing the arguments of the command.
- Client IP address and port.
- Client name if set via the CLIENT SETNAME command.
參考資料
SLOWLOG GET ****[count]:https://redis.io/commands/slowlog-get
管理 Azure Cache for Redis 的服務(wù)器負(fù)載: https://docs.azure.cn/zh-cn/azure-cache-for-redis/cache-best-practices-server-load#value-sizes
當(dāng)在復(fù)雜的環(huán)境中面臨問題摊腋,格物之道需:濁而靜之徐清沸版,安以動之徐生。 云中兴蒸,恰是如此!
分類: 【Azure Redis 緩存】
標(biāo)簽: Azure Redis, Azure 環(huán)境, Slowlogs, Redis 慢指令