redis cluster slots數量 為何是16384(2的14次方)
redis cluster集群通過分片的方式來保存數據庫中鍵值對:集群的整個數據庫被分為16384個槽(slot),
數據庫中的每個鍵都屬於這16384個槽的其中一個,集群中的每個節點可以處理0個或者最多16384個槽
當數據庫中的16384個槽都有節點在處理時,集群處於上線狀態(ok);相反地,如果數據庫中有
任何一個槽沒有得到處理,那麽集群處於下線狀態(fail).
為什麽slots數量是16384(即2的14次方)?
redis source code author antirez say
https://github.com/antirez/redis/issues/2576
The reason is:
- Normal heartbeat packets carry the full configuration of a node, that can be replaced in an idempotent way with the old in order to update an old config. This means they contain the slots configuration for a node, in raw form, that uses 2k of space with16k slots, but would use a prohibitive 8k of space using 65k slots.
- At the same time it is unlikely that Redis Cluster would scale to more than 1000 mater nodes because of other design tradeoffs.
So 16k was in the right range to ensure enough slots per master with a max of 1000 maters, but a small enough number to propagate the slot configuration as a raw bitmap easily. Note that in small clusters the bitmap would be hard to compress because when N is small the bitmap would have slots/N bits set that is a large percentage of bits set.
翻譯
1、正常的心跳包攜帶節點的完整配置,可以用冪等方式替換舊節點以更新舊配置。 這意味著它們包含原始形式的節點的插槽配置,它使用帶有16k插槽的2k空間,但使用65k插槽時將使用高達8k的空間。
2、同時,由於其他設計權衡,Redis Cluster不太可能擴展到超過1000個主節點。
因此,16k處於正確的範圍內,以確保每個主站有足夠的插槽,最多1000個主站,但足夠小的數字可以輕松地將插槽配置傳播為原始位圖。 請註意,在小型集群中,位圖難以壓縮,因為當N很小時,位圖將設置插槽/ N位,這是設置的大部分位。
redis cluster slots數量 為何是16384(2的14次方)