问题描述
我是动物园管理员的新手.我已经在一台机器上配置了它.但是我在zookeeper的文档中看到了ensemble"和quorum"这两个词.
I am new to zookeeper. I have configured it on a single machine. But I came across the words "ensemble" and "quorum" in the documentation of zookeeper.
谁能告诉我它们之间的区别?
Can anyone please tell me the difference between these?
- 合奏
- 法定人数
推荐答案
这个答案是为那些对Ensemble 和 Quorum
仍然有疑问的人准备的.Ensemble 只不过是一组 Zookeeper 服务器,其中 Quorum 定义了形成健康的 Ensemble 的规则.这是使用公式 Q = 2N+1
定义的,其中 Q
定义了形成一个健康的 Ensemble 所需的节点数量,该集合可以允许 N
个故障节点.您将在以下示例中了解此公式.
在开始举例之前,我想定义两件事-
集群:一组连接的节点/服务器(现在将使用 node
),其中一个节点作为领导者/主控,其余作为追随者/从属.
健康的集成:在任何给定时间点只有一个活动领导者的集群,因此容错.
让我用一个例子来解释,它在定义 Ensemble 和 Quorum
时经常使用.
This answer is for those who still have doubt understanding Ensemble and Quorum
. Ensemble is nothing but a cluster of Zookeeper servers, where in Quorum defines the rule to form a healthy Ensemble. Which is defined using a formula Q = 2N+1
where Q
defines number of nodes required to form a healthy Ensemble which can allow N
failure nodes. You will understand about this formula in the following example.
Before I start with an example, I want to define 2 things-
Cluster: Group of connected nodes/servers (now on will use node
) with one node as Leader/Master and rest as Followers/Slaves.
Healthy Ensemble: A cluster with only one active Leader at any given point of time, hence fault tolerant.
Let me explain with an example, which is used commonly across while defining Ensemble and Quorum
.
- 假设您有 1 个 zookeeper 节点.这里不用担心,因为我们需要 1 个以上的节点来组成一个集群.
- 现在取 2 个节点.形成一个集群没有问题,但是形成一个健康的Ensemble却有问题,因为 - 假设这两个节点之间的连接丢失,那么两个节点都会认为另一个节点已关闭,因此它们都尝试充当Leader,这会导致不一致,因为它们无法相互通信.这意味着2个节点的集群甚至不能承受一次故障,那么这个集群有什么用??.他们并不是说你不能建立一个由 2 个节点组成的集群,他们只是说 - 这与拥有单个节点相同,因为两者都不允许出现单一故障.希望这很清楚
- 现在取 3 个节点.形成集群或健康的 Ensemble 没有问题 - 因为根据上面的公式,这可以允许 1 次失败
3 = 2N+1 =>;N = (3-1)/2 = 1
.所以当下一次故障发生时(连接或节点故障),没有节点会被选为 Leader,因此 Ensemble 不会提供任何写/更新/删除服务,因此客户端集群的状态在 Zookeeper 集群节点之间保持一致.所以Leader选举不会发生,直到有多数节点可用并连接,其中Majoritym = (n/2)+1
,其中n
代表节点数上次选举发生时可用.所以在这里,第一次选举发生在 3 个节点上(作为一个 3 个节点的集群).然后发生了第 1 次失败,因此剩余的 2 个节点可以进行选举,因为它们具有多数m = (3/2)+1 = 2
.然后发生了第二次失败,现在他们没有多数,因为只有一个节点可供选举,但所需的多数是m = (2/2)+1 = 2
. - 现在取 4 个节点.形成集群或健康的 Ensemble 没有问题,但有 4 个节点与 3 个节点相同,因为两者都只允许 1 次故障.让我们从 Quorum 公式推导出它
4 = 2N+1 =>;N = (4-1)/2 = ⌊1.5⌋ = 1//floor(1.5)=1
- 现在取 5 个节点.形成一个集群或健康的 Ensemble 没有问题——因为根据上面的公式,这可以允许 2 次失败
5 = 2N+1 =>;N = (5-1)/2 = 2
. - 现在取 6 个节点.形成集群或健康的 Ensemble 没有问题,但 6 个节点与 5 个节点相同,因为两者都只允许 2 次故障.让我们从 Quorum 公式推导出它
6 = 2N+1 =>;N = (6-1)/2 = ⌊2.5⌋ = 2
- Lets say you have 1 zookeeper node. No need to worry here as we need more than 1 node to form a cluster.
- Now take 2 nodes. There is no problem forming a cluster but there is problem to form a healthy Ensemble, because - Say the connection between these 2 nodes are lost, then both nodes will think the other node is down, so both of them try to act as Leader, which leads to inconsistency as they can't communicate with each other. Which means cluster of 2 nodes can't even afford even a single failure, so what is the use of this cluster??. They are not saying you can't make a cluster of 2 nodes, all they are saying is - it is same as having single node, as both don't allow even a single failure. Hope this is clear
- Now take 3 nodes. There is no problem forming a cluster or healthy Ensemble - as this can allow 1 failure according the formula above
3 = 2N+1 => N = (3-1)/2 = 1
. So when the next failure occurs (either connection or node failure), no node will be elected as Leader, hence the Ensemble won't serve any write/update/delete services, hence the states of the client cluster remains consistent across zookeeper cluster nodes. So the Leader election won't happen until there is majority nodes available and connected, where Majoritym = (n/2)+1
, wheren
stands for number of nodes available when the previous election happened. So here, 1st election happened with 3 nodes (as its a 3 node cluster). Then there was a 1st failure, so remaining 2 nodes can conduct election, as they have majoritym = (3/2)+1 = 2
. Then 2nd failure happened, now they don't have majority as there is only one node available for election, but the majority required ism = (2/2)+1 = 2
. - Now take 4 nodes. There is no problem forming a cluster or healthy Ensemble, but having 4 nodes is same as 3 nodes, because both allows only 1 failure. Lets derive it from the Quorum formula
4 = 2N+1 => N = (4-1)/2 = ⌊1.5⌋ = 1 //floor(1.5)=1
- Now take 5 nodes. There is no problem forming a cluster or healthy Ensemble - as this can allow 2 failure according the formula above
5 = 2N+1 => N = (5-1)/2 = 2
. - Now take 6 nodes. There is no problem forming a cluster or healthy Ensemble, but having 6 nodes is same as 5 nodes, because both allows only 2 failure. Lets derive it from the Quorum formula
6 = 2N+1 => N = (6-1)/2 = ⌊2.5⌋ = 2
结论:
- 要形成 Quorum,我们至少需要 3 个节点 - 因为 2 个节点集群甚至无法处理单个故障
- 形成一个奇数节点的集合是很好的 - 因为
n
(偶数)节点倾向于允许与n-1
(奇数)相同数量的失败数量)节点 - 拥有更多节点并不好,因为它们会增加性能延迟.建议的生产集群大小为 5 - 如果一台服务器因维护而停机,它仍然可以处理另外一个故障.
- To form a Quorum we need atleast 3 nodes - as 2 node cluster can't even handle single failure
- Its good to form an Ensemble of odd number of nodes - as
n
(even number) nodes tends to allow same number of failure as ofn-1
(odd number) nodes - Its not good to have more nodes, as they add latency into performance. Suggested Production cluster size is 5 - if one server is down for maintenance, it still can handle one more failure.
这篇关于zookeeper中集成和仲裁的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!