当我试图理解CAP中的“Availability”(A)和“Partition tolerance”(P)时,我发现很难理解各种文章的解释。
我有一种感觉,a和P可以同时出现(我知道事实并非如此,这就是我不能理解的原因!)
简单地解释一下,什么是A和P以及它们之间的区别?
当我试图理解CAP中的“Availability”(A)和“Partition tolerance”(P)时,我发现很难理解各种文章的解释。
我有一种感觉,a和P可以同时出现(我知道事实并非如此,这就是我不能理解的原因!)
简单地解释一下,什么是A和P以及它们之间的区别?
当前回答
一致性:
对于给定的客户端,读操作保证返回最近的写操作(如ACID)。如果在此期间有任何请求,则必须等待节点之间/节点内的数据同步完成。
可用性:
每个节点(如果没有失败)总是执行查询,并且应该总是响应请求。它是否返回最新的副本并不重要。
Partition-tolerance:
当发生网络分区时,系统将继续工作。
关于AP,可用性(始终可访问)可以与(Cassendra)或 没有(RDBMS)分区容忍
图片来源
其他回答
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
理解CAP定理的简单方法:
In case of network partition, one needs to choose between perfect availability and perfect consistency. Picking consistency means not being able to answer a client's query as the system cannot guarantee to return the most recent write. This sacrifices availability. Picking availability means being able to respond to a client's request but the system cannot guarantee consistency, i.e., the most recent value written. Available systems provide the best possible answer under the given circumstance.
这个解释来自这篇优秀的文章。希望能有所帮助。
将P与C和A等同看待是一个错误,而C、A、P之间的“三选二”概念是具有误导性的。我解释CAP定理的简洁方式是,“在分布式数据存储中,在网络分区时,你必须在一致性或可用性中选择一个,并且不能两者兼得”。新的NoSQL系统正试图关注可用性,而传统的ACID数据库则更关注一致性。
你真的不能选择CA,网络分区不是任何人都想要的,它只是分布式系统的一个不受欢迎的现实,网络可能会失败。问题是,当这种情况发生时,你如何权衡你的应用程序。第一个提出这个术语的人的这篇文章似乎很清楚地解释了这一点。
一致性——当我们发送读请求时,如果它正在返回结果,它应该返回客户端请求给出的最近的写。 可用性—您的读/写请求应该总是成功的。 分区容忍度——当网络分区(某些机器相互通信的问题)发生时,系统仍然可以工作。
在分布式环境中,存在网络分区发生的可能性,我们无法避免CAP的“P”。因此,我们在“一致性”和“可用性”之间进行选择。
http://bigdatadose.com/understanding-cap-theorem/
一致性意味着整个集群中的数据是相同的,因此您可以从/写入任何节点并获得相同的数据。
可用性意味着即使集群中的某个节点宕机,也能够访问集群。
分区容忍意味着即使两个节点之间存在“分区”(通信中断)(两个节点都在工作,但不能通信),集群也能继续工作。
为了同时获得可用性和分区容忍,您必须放弃一致性。考虑一下在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系统实际上并不存在(即使有些系统声称存在)。