iT邦幫忙

2021 iThome 鐵人賽

DAY 11
0
Software Development

Redis還在學系列 第 11

Day11 Redis組態檔設定-EVENT NOTIFICATION/GOPHER SERVER/ADVANCED CONFIG/ACTIVE DEFRAGMENTATION

Redis.config

EVENT NOTIFICATION

  • notify-keyspace-events

訂閱事件通知,當有想要關注的事件發生時主動通知管理者.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658o88toBENFe.png

# 預設
notify-keyspace-events ""

# E 空間通知  x key到期刪除通知  z執行排序操作通知
notify-keyspace-events Exz

GOPHER SERVER

  • gopher-enabled no

是否啟用Gopher通訊協定.

Gopher 介紹

https://ithelp.ithome.com.tw/upload/images/20210926/20111658e4X4QA2TbS.png

# 預設
# gopher-enabled no

ADVANCED CONFIG

  • hash-max-ziplist-entries

設定ziplist中允許存儲的最大條目個數.(建議可以設定為128)

  • hash-max-ziplist-value

設定ziplist中允許條目value值最大字元數.(建議爲1024)

https://ithelp.ithome.com.tw/upload/images/20210926/20111658Qag1bl1nUm.png

# 預設
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
  • list-max-ziplist-size

設定ziplist列表最大值,有以下五項:
-5:最大大小:64 Kb x不建議用於正常工作負載
-4:最大大小:32 Kb x不推薦
-3:最大大小:16 Kb x可能不推薦
-2:最大大小:8 Kb v很好
-1:最大大小:4 Kb v好

https://ithelp.ithome.com.tw/upload/images/20210926/20111658VWwiSnyDwq.png

# 預設
list-max-ziplist-size -2
  • list-compress-depth

設定一個quicklist兩端不被壓縮的節點個數.
0: 表示都不壓縮.
1: 表示quicklist兩端各有1個節點不壓縮,中間的節點壓縮.
3: 表示quicklist兩端各有3個節點不壓縮,中間的節點壓縮.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658MSIFJp9v56.png

# 預設
list-compress-depth 0
  • set-max-intset-entries

當集合中的元素全是整數,且長度不超過設定時,Redis會選用intset作爲內部編碼,大於設定值則用set.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658DwnHMHB8A1.png

# 預設
set-max-intset-entries 512
  • zset-max-ziplist-entries
  • zset-max-ziplist-value

當有序集合的元素小於zset-max-ziplist-entries設定值且同時每個元素的值都小於zset-max-ziplist-value設定值時,Redis會用ziplist來作爲有序集合的內部編碼實現,ziplist可以有效的減少內存的使用.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658KMTQp8ddB3.png

# 預設
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
  • hll-sparse-max-bytes

當value值大小 <= hll-sparse-max-bytes使用sparse數據結構.
當value值大小 > hll-sparse-max-bytes使用dense數據結構.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658Vs32OTnN7w.png

# 預設
hll-sparse-max-bytes 3000
  • stream-node-max-bytes
  • stream-node-max-entries

Streams單個節點的字節數,以及切換到新節點之前可能包含的最大項目數.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658hKWvMJZdPO.png

# 預設
stream-node-max-bytes 4096
stream-node-max-entries 100
  • activerehashing

設定是否主動重新散列每100毫秒CPU時間使用1毫秒,以幫助重新散列主Redis散列表(將頂級鍵mapping到值).

https://ithelp.ithome.com.tw/upload/images/20210926/20111658fCU838Iv2Q.png

# 預設
activerehashing yes
  • client-output-buffer-limit

normal
對用戶端輸出緩衝進行限制可以強迫那些不從Redis Server讀取數據的用戶端斷開連接,用來強制關閉傳輸緩慢的用戶端.

replica
用戶端對於Replica和MONITER,如果client-output-buffer一旦超過256mb,又或者超過64mb持續60秒,那麼服務器就會立即斷開用戶端連接.

pubsub
用戶端對於pubsub,如果client-output-buffer一旦超過32mb,又或者超過8mb持續60秒,那麼服務器就會立即斷開用戶端連接.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658EsUXpBmpi2.png

# 預設
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
  • client-query-buffer-limit

用戶端查詢緩衝區累積新命令. 默認情況下,它被限制爲固定數量,以避免協議失步(例如由於客戶端中的錯誤)將導致查詢緩衝區中的未綁定內存使用.假如有特殊的需求執行很大的query可以在此配置它.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658cvnnr8g9JN.png

# 預設
# client-query-buffer-limit 1gb
  • proto-max-bulk-len

在Redis協議中,批次請求(即表示單個字元)通常限制爲512mb.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658PDgycrfCdb.png

# 預設
# proto-max-bulk-len 512mb
  • hz

設定hz當增加時,在Redis處於空閒狀態下,將使用更多CPU.範圍介於1到500之間,大多數用戶應使用默認值10,除非僅在需要非常低延遲的環境中將此值提高到100.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658ELW4svWpeO.png

# 預設
hz 10
  • dynamic-hz yes

是否啓用動態hz時,實際配置的hz將用做最少配置,但是一旦連接了更多用戶端,將根據實際需要使用配置的hz值的倍數.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658cJKqpFOY4t.png

# 預設
dynamic-hz yes
  • aof-rewrite-incremental-fsync yes

設定使否啟用當一個子Process rewrite aof檔案時,文件每生成32mb數據會被同步.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658Hx0Kb8COJF.png

# 預設
aof-rewrite-incremental-fsync yes
  • rdb-save-incremental-fsync

設定是否啟用當Redis Server保存rdb當案時,則每生成32mb數據將對檔案進行fsync.這對於以遞增方式將文件提交到磁盤並避免大延遲峯值非常有用.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658hE1t68dRjx.png

# 預設
rdb-save-incremental-fsync yes
  • lfu-log-factor

設定日誌因數,決定使鍵計數器飽和的鍵命中次數.

  • lfu-decay-time

設定用來遞減鍵計數器的時間.(以分鐘計)

https://ithelp.ithome.com.tw/upload/images/20210926/20111658R4miEAuUxN.png

# 預設
# lfu-log-factor 10
# lfu-decay-time 1

ACTIVE DEFRAGMENTATION

https://ithelp.ithome.com.tw/upload/images/20210926/20111658ge6v9sKWx5.png

  • activedefrag

是否啓用碎片整理.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658w7P5ZAWJXr.png

# 預設
# activedefrag no
  • active-defrag-ignore-bytes

啓動活動碎片整理的最小碎片浪費量.

https://ithelp.ithome.com.tw/upload/images/20210926/2011165833VCCIRw5L.png

# 預設
# active-defrag-ignore-bytes 100mb
  • active-defrag-threshold-lower

啓動碎片整理的最小碎片百分比.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658axG5HYRVug.png

# 預設
# active-defrag-threshold-lower 10
  • active-defrag-threshold-upper

使用最大消耗時的最大碎片百分比.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658CqtcxaaGaC.png

# 預設
# active-defrag-threshold-upper 100
  • active-defrag-cycle-min

在CPU百分比中進行碎片整理的最小消耗.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658li8o96LvXN.png

# 預設
# active-defrag-cycle-min 1
  • active-defrag-cycle-max

在CPU百分比達到最大值時,進行碎片整理.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658pk68BKA0U9.png

# 預設
# active-defrag-cycle-max 25
  • active-defrag-max-scan-fields

從set / hash / zset / list 掃描的最大字段數.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658rWQhBVTu4t.png

# 預設
# active-defrag-max-scan-fields 1000
  • jemalloc-bg-thread

默認情況下,用於清除的Jemalloc後臺線程是啓用的.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658XLUUtTT5h9.png

# 預設
jemalloc-bg-thread yes
  • server_cpulist

設定Redis Server IO Process使用的threads.

  • bio_cpulist

設定 BIO Process使用的threads.

  • aof_rewrite_cpulist

設定aof IO Process使用的threads.

  • bgsave_cpulist

設定bgsave IO Process使用的threads.

https://ithelp.ithome.com.tw/upload/images/20210926/20111658VLLUgGkwXf.png

# 預設
# server_cpulist 0-7:2
# bio_cpulist 1,3
# aof_rewrite_cpulist 8-11
# bgsave_cpulist 1,10-11
  • ignore-warnings

設定要ignore的檢查

https://ithelp.ithome.com.tw/upload/images/20210926/20111658b2eGhxzXLM.png

# 預設
# ignore-warnings ARM64-COW-BUG

上一篇
Day10 Redis組態檔設定-LUA SCRIPTING/REDIS CLUSTER/CLUSTER DOCKER/NAT support/SLOW LOG/LATENCY MONITOR
下一篇
Day12 Redis應用實戰-String操作
系列文
Redis還在學30
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言