Redis分析慢查詢操作的實(shí)例教程
什么是慢查詢
慢查詢的作用:通過(guò)慢查詢分析,找到有問(wèn)題的命令進(jìn)行優(yōu)化。
和mysql的慢SQL日志分析一樣,redis也有類似的功能,來(lái)幫助定位一些慢查詢操作。
Redis slowlog是Redis用來(lái)記錄查詢執(zhí)行時(shí)間的日志系統(tǒng)。
查詢執(zhí)行時(shí)間指的是不包括像客戶端響應(yīng)(talking)、發(fā)送回復(fù)等IO操作,而單單是執(zhí)行一個(gè)查詢命令所耗費(fèi)的時(shí)間。
另外,slow log保存在內(nèi)存里面,讀寫(xiě)速度非???,因此你可以放心地使用它,不必?fù)?dān)心因?yàn)殚_(kāi)啟slow log而損害Redis的速度。
慢查詢?nèi)罩舅膫€(gè)屬性:
1、第一個(gè)字段是每個(gè)慢查詢唯一標(biāo)識(shí)。
2、處理完命令后的時(shí)間戳
3、執(zhí)行改名了所需要的時(shí)間,單位微妙
4、命令的參數(shù)列表,是個(gè)數(shù)組類型
每個(gè)慢查詢實(shí)體的ID都是唯一的,而且不會(huì)被重新設(shè)置,只會(huì)在redis重啟后才會(huì)重置它.
慢查詢參數(shù)
首先來(lái)關(guān)注下慢日志分析對(duì)應(yīng)的兩個(gè)參數(shù):
1、slowlog-log-slower-than:預(yù)設(shè)閥值,即記錄超過(guò)多少時(shí)間的記錄,默認(rèn)為10000微秒,即10毫秒。
2、slowlog-max-len:記錄慢查詢的條數(shù),默認(rèn)為128條,當(dāng)超過(guò)設(shè)置的條數(shù)時(shí)最早進(jìn)入隊(duì)列的將被移除。線上建議增大數(shù)值,如:1000,這樣可減少隊(duì)列移除的頻率。
127.0.0.1:6379> config get slowlog-log-slower-than 1) "slowlog-log-slower-than" 2) "10000" 127.0.0.1:6379> config get slowlog-max-len 1) "slowlog-max-len" 2) "128"
可以用config set對(duì)這兩個(gè)參數(shù)進(jìn)行調(diào)整,或者在配置文件中設(shè)置。
################################## SLOW LOG ################################### # The Redis Slow Log is a system to log queries that exceeded a specified # execution time. The execution time does not include the I/O operations # like talking with the client, sending the reply and so forth, # but just the time needed to actually execute the command (this is the only # stage of command execution where the thread is blocked and can not serve # other requests in the meantime). # # You can configure the slow log with two parameters: one tells Redis # what is the execution time, in microseconds, to exceed in order for the # command to get logged, and the other parameter is the length of the # slow log. When a new command is logged the oldest one is removed from the # queue of logged commands. # The following time is expressed in microseconds, so 1000000 is equivalent # to one second. Note that a negative number disables the slow log, while # a value of zero forces the logging of every command. slowlog-log-slower-than 10000 # There is no limit to this length. Just be aware that it will consume memory. # You can reclaim memory used by the slow log with SLOWLOG RESET. slowlog-max-len 128
慢查詢命令
語(yǔ)法:slowlog subcommand [argument]
如,進(jìn)行查詢慢查詢、獲取慢查詢記錄的數(shù)量、重置慢查詢?nèi)罩镜炔僮鳎?/p>
192.168.10.38:9001> slowlog get (empty list or set) 192.168.10.38:9001> slowlog get 10 (empty list or set) 192.168.10.38:9001> slowlog len (integer) 0 192.168.10.38:9001> slowlog reset OK
總結(jié)
以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)腳本之家的支持。
相關(guān)文章
redis中如何使用lua腳本讓你的靈活性提高5個(gè)逼格詳解
這篇文章主要給大家介紹了關(guān)于redis中如何使用lua腳本讓你的靈活性提高5個(gè)逼格的相關(guān)資料,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2018-10-10
redis.clients.jedis.exceptions.JedisDataException:?NOAUTH?
本文主要介紹了redis.clients.jedis.exceptions.JedisDataException:?NOAUTH?Authentication?required數(shù)據(jù)操作異常的解決方法,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2024-05-05
簡(jiǎn)單聊一聊redis過(guò)期時(shí)間的問(wèn)題
在使用redis的過(guò)期時(shí)間時(shí)不由想到設(shè)置了過(guò)期時(shí)間,下面這篇文章主要給大家介紹了關(guān)于redis過(guò)期時(shí)間問(wèn)題的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-04-04
深入解析RedisJSON之如何在Redis中直接處理JSON數(shù)據(jù)
JSON已經(jīng)成為現(xiàn)代應(yīng)用程序之間數(shù)據(jù)傳輸?shù)耐ㄓ酶袷?然而,傳統(tǒng)的關(guān)系型數(shù)據(jù)庫(kù)在處理JSON數(shù)據(jù)時(shí)可能會(huì)遇到性能瓶頸,本文將詳細(xì)介紹RedisJSON的工作原理、關(guān)鍵操作、性能優(yōu)勢(shì)以及使用場(chǎng)景,感興趣的朋友一起看看吧2024-05-05
redis實(shí)現(xiàn)sentinel哨兵架構(gòu)的方法
哨兵是一個(gè)分布式系統(tǒng),可以在一個(gè)架構(gòu)中運(yùn)行多個(gè)哨兵(sentinel) 進(jìn)程,這些進(jìn)程使用流言協(xié)議(gossip protocols)來(lái)接收關(guān)于Master主服務(wù)器是否下線的信息,這篇文章主要介紹了redis實(shí)現(xiàn)sentinel哨兵架構(gòu),需要的朋友可以參考下2022-11-11
redis分布式鎖的go-redis實(shí)現(xiàn)方法詳解
這篇文章主要介紹了redis分布式鎖的go-redis實(shí)現(xiàn)方法,本文給大家介紹的非常詳細(xì)對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-12-12

