自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

Redis如何分析慢查詢操作?

數(shù)據(jù)庫(kù) 其他數(shù)據(jù)庫(kù) Redis
和mysql的慢SQL日志分析一樣,redis也有類似的功能,來(lái)幫助定位一些慢查詢操作。Redis slowlog是Redis用來(lái)記錄查詢執(zhí)行時(shí)間的日志系統(tǒng)。

Redis如何分析慢查詢操作?

什么是慢查詢

和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)存里面,讀寫速度非???,因此你可以放心地使用它,不必?fù)?dān)心因?yàn)殚_啟slow log而損害Redis的速度。

慢查詢參數(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ì)列移除的頻率。 

  1. 127.0.0.1:6379> config get slowlog-log-slower-than  
  2. 1) "slowlog-log-slower-than"  
  3. 2) "10000"  
  4. 127.0.0.1:6379> config get slowlog-max-len  
  5. 1) "slowlog-max-len"  
  6. 2) "128"  

可以用config set對(duì)這兩個(gè)參數(shù)進(jìn)行調(diào)整,或者在配置文件中設(shè)置。 

  1. ################################## SLOW LOG ###################################  
  2. # The Redis Slow Log is a system to log queries that exceeded a specified  
  3. # execution time. The execution time does not include the I/O operations  
  4. like talking with the client, sending the reply and so forth,  
  5. # but just the time needed to actually execute the command (this is the only  
  6. # stage of command execution where the thread is blocked and can not serve  
  7. # other requests in the meantime). 
  8.  
  9. # You can configure the slow log with two parameters: one tells Redis  
  10. # what is the execution timein microseconds, to exceed in order for the  
  11. # command to get logged, and the other parameter is the length of the  
  12. # slow log. When a new command is logged the oldest one is removed from the  
  13. # queue of logged commands.   
  14. # The following time is expressed in microseconds, so 1000000 is equivalent  
  15. to one second. Note that a negative number disables the slow log, while  
  16. # a value of zero forces the logging of every command.  
  17. slowlog-log-slower-than 10000   
  18. # There is no limit to this length. Just be aware that it will consume memory.  
  19. # You can reclaim memory used by the slow log with SLOWLOG RESET.  
  20. slowlog-max-len 128 

慢查詢命令

語(yǔ)法:slowlog subcommand [argument]

如,進(jìn)行查詢慢查詢、獲取慢查詢記錄的數(shù)量、重置慢查詢?nèi)罩镜炔僮鳎?/p>

  1. 192.168.10.38:9001> slowlog get  
  2. (empty list or set 
  3. 192.168.10.38:9001> slowlog get 10  
  4. (empty list or set 
  5. 192.168.10.38:9001> slowlog len   
  6. (integer) 0  
  7. 192.168.10.38:9001> slowlog reset  
  8. OK   

 

責(zé)任編輯:龐桂玉 來(lái)源: Java技術(shù)棧
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)