当我试图理解CAP中的“Availability”(A)和“Partition tolerance”(P)时,我发现很难理解各种文章的解释。
我有一种感觉,a和P可以同时出现(我知道事实并非如此,这就是我不能理解的原因!)
简单地解释一下,什么是A和P以及它们之间的区别?
当我试图理解CAP中的“Availability”(A)和“Partition tolerance”(P)时,我发现很难理解各种文章的解释。
我有一种感觉,a和P可以同时出现(我知道事实并非如此,这就是我不能理解的原因!)
简单地解释一下,什么是A和P以及它们之间的区别?
当前回答
Brewer's keynote, the Gilbert paper, and many other treatments, places C, A and P on an equal footing as desirable properties of an implementation and effectively say 'choose two!'. However, this is often considered to be a misleading presentation, since you cannot build - or choose! - 'partition tolerance': your system either might experience partitions or it won't. CAP is better understood as describing the tradeoffs you have to make when you are building a system that may suffer partitions. In practice, this is every distributed system: there is no 100% reliable network. So (at least in the distributed context) there is no realistic CA system. You will potentially suffer partitions, therefore you must at some point compromise C or A.
https://github.com/henryr/cap-faq#10-why-do-some-people-get-annoyed-when-i-characterise-my-system-as-ca
其他回答
一致性:
对于给定的客户端,读操作保证返回最近的写操作(如ACID)。如果在此期间有任何请求,则必须等待节点之间/节点内的数据同步完成。
可用性:
每个节点(如果没有失败)总是执行查询,并且应该总是响应请求。它是否返回最新的副本并不重要。
Partition-tolerance:
当发生网络分区时,系统将继续工作。
关于AP,可用性(始终可访问)可以与(Cassendra)或 没有(RDBMS)分区容忍
图片来源
一致性意味着整个集群中的数据是相同的,因此您可以从/写入任何节点并获得相同的数据。
可用性意味着即使集群中的某个节点宕机,也能够访问集群。
分区容忍意味着即使两个节点之间存在“分区”(通信中断)(两个节点都在工作,但不能通信),集群也能继续工作。
为了同时获得可用性和分区容忍,您必须放弃一致性。考虑一下在master-master设置中是否有两个节点X和Y。现在,X和Y之间的网络通信中断了,所以它们不能同步更新。此时你可以:
A)允许节点不同步(放弃一致性),或者
B)认为集群“关闭”(放弃可用性)
所有可用的组合是:
CA - data is consistent between all nodes - as long as all nodes are online - and you can read/write from any node and be sure that the data is the same, but if you ever develop a partition between nodes, the data will be out of sync (and won't re-sync once the partition is resolved). CP - data is consistent between all nodes, and maintains partition tolerance (preventing data desync) by becoming unavailable when a node goes down. AP - nodes remain online even if they can't communicate with each other and will resync data once the partition is resolved, but you aren't guaranteed that all nodes will have the same data (either during or after the partition)
您应该注意,CA系统实际上并不存在(即使有些系统声称存在)。
我将用这里提到的ATM机示例详细解释
CAP定理讨论了一致性和可用性之间的权衡,如果您的分布式系统遭受分区,您必须做出取舍。分布式系统意味着您将数据存储在多个节点中,分区意味着这些节点之间的连接以某种方式断开。
分区是分布式系统中的通信中断 两个节点之间的连接丢失或暂时延迟。分区 容忍度意味着集群必须在任何情况下继续工作 系统节点间通信中断次数。
假设我们有一家小银行,只有两台自动取款机。客户可以存、取、查余额。你必须确保余额不会低于零。这些atm机之间的连接可以通过三种方式断开
1-您要使用的ATM机不能用。你刚刚放了个坏了的牌子
2-你要用的ATM机在工作,但另一台不能工作
3-他们都在工作,但有一个网络问题,他们无法相互沟通。
这个分布式系统正在遭受分区,我们需要在可用性和一致性之间做出选择:
如果银行选择一致的设计,自动柜员机将不会处理您的请求,因为它无法更新另一台自动柜员机中的余额。 如果银行选择了可用性,你的ATM会处理请求,跟踪发生了什么,然后当连接建立时,它只是告诉其他ATM发生了什么,但余额同时会不一致。
根据上图C是断开的,但A,B, D可以继续工作。现在我们可以调用系统部分工作(分区容忍)。
假设一个特定的事务只需要a、B和d,系统可以执行它而不会产生任何不一致。
但是当C必须参与一个特定的事务时,系统可以以两种方式执行。
1.由于C不可用,A可以拒绝用户请求。
So the system has Partition-Tolerance and consistency (P,C).
But no availability, because of the rejection.
2.A可以将C接收到的消息保存在A的本地内存中,并在C连接回来时传输。
So the system has Partition-Tolerance and availability (P,A).
But no consistency.because C has not updated.
根据CAP定理,分布式系统有三个特征:
一致性(C)表示所有系统组件具有相同的信息。
系统的可用性(A)意味着它不会因为另一个系统故障而停止工作。
分区容差(P)表示在任意网络包丢失的情况下,系统将继续工作。
根据CAP定理,一个系统最多只能有这三个特征中的两个。(ap, cp, ca)