CAP 可能是CAP理论的最好解释

2023-10-27

一篇非常精彩的解释CAP理论的文章,翻译水平有限,不准确之处请参考原文,还请见谅。

 

Chapter 1: “Remembrance Inc” Your new venture :

Last night when your spouse appreciated you on remembering her birthday and bringing her a gift, a strange Idea strikes you. People are so bad in remembering things. And you’re sooo good at it. So why not start a venture that will put your talent to use? The more you think about it, the more you like it. In fact you even come up with a news paper ad which explains your idea

第一章:记忆公司

昨晚当你的妻子感激你记得她生日还给她买了礼物时,你突然冒出一个想法。人们的记性总是很糟而你又是如此善于记忆,所以为什么不利用你的天赋干出一番事业呢?你越想越觉得这个点子不错。事实上你甚至想出一份新闻广告来解释你的想法。

记忆公司! - 不用记忆,从不忘记

您是否曾为健忘而感到沮丧?不用担心,只需一通电话。当您需要记住什么时,拨打555-55,告诉我们您想记住的东西。例如,来电让我们知道您老板的电话号,然后忘了这事。当您想要知道已忘了的东西时,拨打同样的号码,我们将告诉您老板的电话号。费用:每次仅需0.1美元。

So, your typical phone conversation will look like this:

·         Customer : Hey, Can you store my neighbor’s birthday?

·         You: Sure.. when is it?

·         Customer : 2nd of jan

·         You: (write it down against the customer’s page in your paper note book )Stored. Call us any time for knowing your neighbor’s birthday again!

·         Customer : Thank you!

·         You: No problem! We charged your credit card with $0.1

所以您的通话通常是这样的:

Ø  客户:嗨!能记一下我邻居的生日吗?

Ø  你:当然可以,他生日是什么时候?

Ø  客户:12

Ø  你:(在笔记本上该客户的那一页记下)记好了!想知道他生日时随时打给我们!

Ø  客户:谢谢!

Ø  不客气,您的信用卡将支付0.1美元。

 

Chapter 2 : You scale up:

Your venture gets funded by YCombinator. Your Idea is so simple, needs nothing but a paper notebook and phone, yet so effective that it spreads like wild fire. You start getting hundreds of call every day.

And there starts the problem. You see that more and more of your customers have to wait in the queue to speak to you. Most of them even hang up tired of the waiting tone. Besides when you were sick the other day and could not come to work you lost a whole day of business. Not to mention all those dissatisfied customers who wanted information on that day.
You decide it’s time for you to scale up and bring in your wife to help you.

第二章:公司扩张

你拿到了YC的投资。这个点子是如此简单,只需纸笔和电话,但却像燎原之火一样发展迅猛。你每天逐渐有上百个来电。但问题也随之而来。你发现越来越多的客户要排队等你应答。他们都受够了等待。而且当你生病没法工作时,你将损失一整天的生意,更不用说那些客户的不满。于是你决定:是时候把你的妻子拉过来帮忙了。

Your start with a simple plan:

1.    You and your wife both get an extension phone

2.    Customers still dial (555)–55-REMEM and need to remember only one number

3.    A pbx will route the a customers call to whoever is free and equally

你的计划很简单:

1.      你和你妻子都有分机号

2.      客户还是拨打原来的号码

3.      交换机将把客户来电发给你们俩空闲的那位。

 

Chapter 3 : You have your first “Bad Service” :

Two days after you implemented the new system, you get a call from your trusted customer Jhon. This is how it goes:

·         Jhon: Hey

·         You: Glad you called “Remembrance Inc!”. What can I do for you?

·         Jhon: Can you tell me when is my flight to New Delhi?

·         You: Sure.. 1 sec sir
(You look up your notebook)
(wow! there is no entry for “flight date” in Jhon’s page)!!!!!

·         You: Sir, I think there is a mistake. You never told us about your flight to delhi

·         Jhon: What! I just called you guys yesterday!(cuts the call!)

第三章:第一次Bad Service

就在扩张后两天,你接到了老客户Jhon的来电:

Ø  Jhon:嗨!

Ø  你:感谢致电记忆公司,有什么可以帮您?

Ø  Jhon:能告诉我第一次飞新德里的时间吗?

Ø  你:当然可以,请稍等(你翻阅你的笔记本,在Jhon那页却没发现航班这一项)

Ø  先生,抱歉,我想您没有告诉过我们您去新德里的航班信息。

Ø  Jhon:什么!?我昨天就打给过你们!(挂断了)

How did that happen? Could Jhon be lying? You think about it for a second and the reason hits you! Could Jhon’s call yesterday reached your wife? You Go to your wife’s desk and check her notebook. Sure enough it’s there. You tell this to your wife and she realizes the problem too.

What a terrible flaw in your distributed design! Your distributed system is not consistent! There could always be a chance that a customer updates something which goes to either you or your wife and when the next call from the customer is routed to another person there will not be a consistent reply from Remembrance Inc!

怎么可能发生这种事?Jhon在说谎吗?你一下子想到了原因!可能Jhon昨天打给了你的妻子。于是你到她桌上检查她的笔记本。没错,就是这个原因。你告诉了你妻子,她也意识到了这个问题。多么糟糕的问题!你的分布式系统不是一致性的!客户打给你或你妻子,再来电时却是另一个人接的,你的记忆公司没法给出一个一致性的答复!

 

Chapter 4: You fix the Consistency problem:

Well, your competitors may ignore a bad service, but not you. You think all night in the bed when your wife is sleeping and come up with a beautiful plan in the morning. You wake up your wife and tell her:

” Darling this is what we are going to do from now”

·         Whenever any one of us get a call for an update(when the customer wants us to remember something) before completing the call we tell the other person

·         This way both of us note down any updates

·         When there is call for search(When the customer wants information he has already stored) we don’t need to talk with the other person. Since both of us have the latest updated information in both of our note books we can just refer to it..

第四章:修复一致性问题

你的竞争者可能会忽视这个问题,你却不会。你妻子入睡时你想了一整晚,终于在清晨时想出了一个美丽的方案。你叫醒她说:

亲爱的,这是我们从今往后要做的事:

Ø  不论我俩谁接到客户要求记东西的电话,打完电话前我们要告诉另一个人

Ø  这样我俩都能记下任何的更新

Ø  当客户要求查找时,我们不用互相问,因为我俩的笔记本上都记录了所有更新。

There is only one problem though, you say, and that is an “update” request has to involve both of us and we cannot work in parallel during that time. For eg. when you get an update request and telling me to update too, i cannot take other calls. But that’s okay because most calls we get anyway are “search” (a customer updates once and asks many times) . Besides, we cannot give wrong information at any cost.

“Neat” your wife says, “but there is one more flaw in this system that you haven’t thought of. What if one of us doesn’t report to work on a particular day? On that day, then, we won’t be able to take “any” Update calls, because the other person cannot be updated! We will have Availability problem , i.e, for eg., if an update request comes to me I will never be able to complete that call because even though I have written the update in my note book, I can never update you. So I can never complete the call!”

但是还是有一个问题,客户要求记东西的来电需要我们俩人同时处理,所以那段时间就没法并行工作了。例如,当你接到保存或更新请求时也会告诉我,于是我就不能接听其他来电了。但是因为多数来电都是查找的,所以也没什么大问题(客户更新一次然后查找多次)。而且,我们要不惜一切代价避免记错东西。

很好!你的妻子说但是还有个问题你没想到。要是我俩中的一个哪天不能来工作呢?在那天我们就不能一起接受更新的来电了,因为另一个人不能记下这个更新。所以我们会有可用性问题!例如,我接到更新来电时就没法完成这个请求,因为即使我在我的本子上记下了,我也没法告诉你。所以我没法完成这个来电

 

Chapter 5: You come up with the greatest solution Ever:

You being to realize a little bit on why distributed system might not be as easy as you thought at first. Is it that difficult to come up with a solution that could be both “Consistent and Available”? Could be difficult for others, but not for you!! Then next morning you come up with a solution that your competitors cannot think of in their dreams! You wake your wife up eagerly again..

” look” , you tell her.. “This is what we can do to be consistent and available” . The plan is mostly similar to what I told you yesterday:

·         i) Whenever any one of us get a call for an update(when the customer wants us to remember something) before completing the call, if the other person is available we tell the other person. This way both of us note down any updates

·         ii) But if the other person is not available(doesn’t report to work) we send the other person an email about the update.

·         iii) The next day when the other person comes to work after taking a day off, He first goes through all the emails, updates his note book accordingly.. before taking his first call.

第五章:最棒的解决方法

你有点儿意识到了为什么分布式系统不像你一开始想的那样简单。想出一个既一致又可用的方案很难吗?对其他人也许很难,但对你则不是!第二天早上,你想出了一个你的竞争者们做梦都想不到的解决方法。你再一次急切地叫醒了你妻子。

看!你跟她说,这就是我们既一致又可用的做法,方案与我昨天告诉你的很像

Ø  不论我俩谁接到客户要求记东西的电话,打完电话前我们要告诉另一个人,这样我俩都能记下任何的更新。

Ø  但是如果另一个人请假不在,我们给他发一封更新的邮件。

Ø  第二天他来工作时,在处理任何来电前先看一遍这些邮件,更新到他的本子上。

Genius! You wife says! I can’t find any flaws in this systems. Let’s put it to use.. Remembrance Inc! is now both Consistent and available!

天才啊!你的妻子说。这个方案想不到任何的问题的。咱们就这样来吧!记忆公司现在既是一致的又是可用的!

 

Chapter 6: Your wife gets angry :

Everything goes well for a while. Your system is consistent. Your system works well even when one of you doesn’t report to work. But what if Both of you report to work and one of you doesn’t update the other person? Remember all those days you’ve been waking your wife up early with your Greatest-idea-ever-bullshit? * What if your wife decides to take calls but is too angry with you and decides not to update you for a day? Your idea totally breaks! Your idea so far is good for consistency and availability but is not Partition Tolerant!*
You can decide to be partition tolerant by deciding not to take any calls until you patch up with your wife.. Then your system will not be “available” during that time…

第六章:妻子的愤怒

一切都很顺利。你的系统是一致的,当你俩中的一人不能工作时也能运行良好。但是假如你们都来工作了,但是却没把更新告诉另一个人呢?想想你吵醒你妻子,说你那些所谓的伟大的点子。要是哪天她接电话却很生气而不告诉你去更新呢?你的方法完全毁了。到目前为止,你的方法是一致而可用的,但却不是分区容忍的。你可以在与你妻子和好前不接听任何来电,于是你的系统在那段时间又是不可用的了

 

Chapter 7: Conclusion :

So Let’s look at CAP Theorem now. Its states that, when you are designing a distributed system you can get cannot achieve all three of Consistency, Availability and Partition tolerance. You can pick only two of:

·         Consistency: You customers, once they have updated information with you, will always get the most updated information when they call subsequently. No matter how quickly they call back

·         Availability: Remembrance Inc will always be available for calls until any one of you(you or your wife) report to work.

·         Partition Tolerance: Remembrance Inc will work even if there is a communication loss between you and your wife!

第六章:总结

让我们现在看一下CAP理论。它说:当你设计分布式系统时,你只能实现一致性、可用性和分区容忍中的两者:

Ø  一致性:你的客户再次来电时总能查到他们刚来电更新的信息,不论相隔多短

Ø  可用性:不论你和你妻子谁来工作,记忆公司总能接听来电,处理客户请求

Ø  分区容忍:即便你和你妻子失联,记忆公司依然能正常运转

 

Bonus : Eventual Consistency with a run around clerk :

Here is another food for thought. You can have a run around clerk, who will update other’s notebook when one of your’s or your wife’s note books is updated. The greatest benefit of this is that, he can work in background and one of your or your wife’s “update” doesn’t have to block, waiting for the other one to update. This is how many NoSql systems work, one node updates itself locally and a background process synchronizes all other nodes accordingly… The only problem is that you will lose consistency of some time. For eg., a customer’s call reaches your wife first and before the clerk has a chance to update your notebook , the customer’ calls back and it reaches you. Then he won’t get a consistent reply.. But that said, this is not at all a bad idea if such cases are limited. For eg., assuming a customer won’t forget things so quickly that he calls back in 5 minutes.

奖励:最终一致性和东奔西跑的员工

你可以雇一个员工负责当一个本子上内容更新时去更新另一个本子。最大的好处就是,他能在后台工作,你或你妻子更新时不用等待另一个完成更新。这就是许多NoSQL数据库系统的工作方式。一个结点进行本地更新,后台进程将更新内容同步到其他所有结点。唯一的问题是:你将会失去一定时间的一致性。例如,客户先打给你妻子,在负责更新的员工未完成更新你的本子时,客户打给了你。那么他就无法得到一个一致性的回复。但即便如此,在某些情况下倒也不算是个坏主意。例如,一个客户不会忘东西忘得这么快,一般五分钟左右才会再次来电。

That’s CAP and eventual consistency for you in simple english :)

这就是给您的CAP理论和最终一致性的极简解释:)

转载文章:http://blog.csdn.net/dc_726/article/details/42784237
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

CAP 可能是CAP理论的最好解释 的相关文章

  • 如何测试 JUnit 测试的 Comparator?

    我需要测试 Compare 方法 但我对如何测试感到困惑 我可以看看该怎么做吗 public class MemberComparator implements Comparator
  • Android Studio 在编译时未检测到支持库

    由于 Android Studio 将成为 Android 开发的默认 IDE 因此我决定将现有项目迁移到 Android studio 中 项目结构似乎不同 我的项目中的文件夹层次结构如下 Complete Project gt idea
  • 解决错误:日志已在具有多个实例的atomikos中使用

    我仅在使用atomikos的实时服务器上遇到问题 在我的本地服务器上它工作得很好 我在服务器上面临的问题是 init 中出错 日志已在使用中 完整的异常堆栈跟踪 java lang RuntimeException Log already
  • JNI 不满意链接错误

    我想创建一个简单的 JNI 层 我使用Visual studio 2008创建了一个dll Win 32控制台应用程序项目类型 带有DLL作为选项 当我调用本机方法时 出现此异常 Exception occurred during even
  • HDFS:使用 Java / Scala API 移动多个文件

    我需要使用 Java Scala 程序移动 HDFS 中对应于给定正则表达式的多个文件 例如 我必须移动所有名称为 xml从文件夹a到文件夹b 使用 shell 命令我可以使用以下命令 bin hdfs dfs mv a xml b 我可以
  • Java 页面爬行和解析之 Crawler4j 与 Jsoup

    我想获取页面的内容并提取其中的特定部分 据我所知 此类任务至少有两种解决方案 爬虫4j https github com yasserg crawler4j and Jsoup http jsoup org 它们都能够检索页面的内容并提取其
  • jdbc4.MySQLSyntaxErrorException:数据库中不存在表

    我正在使用 SpringBoot 开发一个网络应用程序 这是我的application properties文件来指定访问数据库的凭据 spring datasource driverClassName com mysql jdbc Dri
  • hibernate总是自己删除表中的所有数据

    您好 我正在开发一个 spring mvc 应用程序 它使用 hibernate 连接到存储文件的 mysql 数据库 我有两个方法 一个方法添加我选择的特定文件路径中的所有文件 另一种方法调用查询以返回从 mysql 存储的文件列表 问题
  • Prim 的迷宫生成算法:获取相邻单元格

    我基于 Prim 算法编写了一个迷宫生成器程序 该算法是 Prim 算法的随机版本 从充满墙壁的网格开始 选择一个单元格 将其标记为迷宫的一部分 将单元格的墙壁添加到墙壁列表中 While there are walls in the li
  • MySQL“列计数与第 1 行的值计数不匹配”是什么意思

    这是我收到的消息 ER WRONG VALUE COUNT ON ROW 列计数与第 1 行的值计数不匹配 这是我的全部代码 我的错误在哪里 DROP TABLE student CREATE TABLE employee emp id I
  • Clip 在 Java 中播放 WAV 文件时出现严重延迟

    我编写了一段代码来读取 WAV 文件 大小约为 80 mb 并播放该文件 问题是声音播放效果很差 极度滞后 你能告诉我有什么问题吗 这是我的代码 我称之为doPlayJframe 构造函数内的函数 private void doPlay f
  • Java中接口作为方法参数

    前几天去面试 被问到了这样的问题 问 反转链表 给出以下代码 public class ReverseList interface NodeList int getItem NodeList nextNode void reverse No
  • 反思 Groovy 脚本中声明的函数

    有没有一种方法可以获取 Groovy 脚本中声明的函数的反射数据 该脚本已通过GroovyShell目的 具体来说 我想枚举脚本中的函数并访问附加到它们的注释 Put this到 Groovy 脚本的最后一行 它将作为脚本的返回值 a la
  • org.jdesktop.application 包不存在

    几天以来我一直在构建一个 Java 桌面应用程序 一切都很顺利 但是今天 当我打开Netbeans并编译文件时 出现以下编译错误 Compiling 9 source files to C Documents and Settings Ad
  • Tomcat 6找不到mysql驱动

    这里有一个类似的问题 但关于类路径 ClassNotFoundException com mysql jdbc Driver https stackoverflow com questions 1585811 classnotfoundex
  • 在mysql连接字符串中添加应用程序名称/程序名称[关闭]

    Closed 这个问题需要细节或清晰度 help closed questions 目前不接受答案 我正在寻找一种解决方案 在连接字符串中添加应用程序名称或程序名称 以便它在 MySQL Workbench 中的 客户端连接 下可见 SQL
  • 当单元格内的 JComboBox 中有 ItemEvent 时,如何获取 CellRow

    我有一个 JTable 其中有一列包含 JComboBox 我有一个附加到 JComboBox 的 ItemListener 它会根据任何更改进行操作 但是 ItemListener 没有获取更改的 ComboBox 所在行的方法 当组合框
  • 如何测试 spring-security-oauth2 资源服务器安全性?

    随着 Spring Security 4 的发布改进了对测试的支持 http docs spring io spring security site docs 4 0 x reference htmlsingle test我想更新我当前的
  • 使用用户定义函数 MySql 时出错

    您好 请帮我解决这个问题 提前致谢 我在数据库中定义了这些函数 CREATE FUNCTION levenshtein s1 VARCHAR 255 s2 VARCHAR 255 RETURNS INT DETERMINISTIC BEGI
  • com.jcraft.jsch.JSchException:身份验证失败

    当我从本地磁盘上传文件到远程服务器时 出现这样的异常 com jcraft jsch JSchException Auth fail at org apache tools ant taskdefs optional ssh Scp exe

随机推荐

  • 算法 - 剑指Offer 股票的最大利润

    题目 假设把某股票的价格按照时间先后顺序存储在数组中 请问买卖该股票一次可能获得的最大利润是多少 解题思路 这题解题思路较为简单 首先我们需要记录的两个变量 第一个为我们花费买入的点 满足的条件只要满足一点那就是要比前一个点要小 这样能赚的
  • 代码随想录算法训练营第二天

    Leetcode977 有序数组的平方 题目链接 关键词 双指针 问题思路 给一个非递减数组 返回平方后的非递减数组 忽略非递减的条件我们可以直接对原数组进行平方然后排序 显然这样对原数组的性质运用不完全 如何体现非递减的性质 发现新数组的
  • 2021泰迪杯B题数据处理4.1

    文章目录 涉及需要处理的数据文件 任务 4 肥料产品的多维度对比分析 数据样式 最终需要处理的结果的样式 数据处理总共分为3部分 获取氮磷钾的含量 获取氯含量 获取有机质含量 程序执行导出结果 总结 涉及需要处理的数据文件 需要处理的文件
  • 清华教授!亲手教你JavaScript 在线解压 ZIP 文件,实战理论全都有

    相信大家对 ZIP 文件都不会陌生 当你要打开本地的 ZIP 文件时 你就需要先安装支持解压 ZIP 文件的解压软件 但如果预解压的 ZIP 文件在服务器上 我们应该如何处理呢 最简单的一种方案就是把文件下载到本地 然后使用支持 ZIP 格
  • Intellij IDEA 的快捷键收集

    文档链接 IntelliJ IDEA13基础教程
  • UnsatisfiedLinkError: org.opencv.imgcodecs.Imgcodecs.imread_1(Ljava/lang/String;)J

    在使用opencv获取本地图片的时候 报了一个UnsatisfiedLinkError错误 网上找了很久 改什么启动类 下什么dll文件 感觉都不是我想要的结果 Mat img Imgcodecs imread filePath Cause
  • GAMES101课程学习笔记—Lec 10~12:Geometry 几何、隐式与显式、曲线与曲面、网格

    GAMES101课程学习笔记 Lec 10 12 Geometry 几何 隐式与显式 曲线与曲面 1 几何的表达方式 1 1 隐式几何 1 2 更多的隐式表达方法 1 2 1 代数曲面 1 2 2 CSG 构造实体几何 1 2 3 距离函数
  • 调试STM32f401过程出现的问题

    前言 最近在调试STM32F401遇到了一堆问题 检查结果就仅仅是一个简单的问题 写在此处 希望能帮到你 也为自己做一次深刻的笔记内容 实验条件 在之前STM32F103的电路图上直接焊接STM32F401进行系统配置 使用J LINK进行
  • 内卷--焦虑

    不知道是不是因为生活在浮躁的社会中 我很容易焦虑 焦虑到反复思考 严重影响了我的生活 我还带有强迫性思维的症状 这个和焦虑加在一起 把我的精神世界打的落花流水 我控制不了自己的大脑 更控制不了因为强迫焦虑带来的烦躁 抑郁 躁狂等症状 有时候
  • Nvidia-docker运行错误- Nvidia-docker : Unknown runtime specified nvidia

    使用nvidia docker的时候 出现了上面的bug 故总结一下 所使用的环境为ubuntu系统64位 GPU2080ti command1 sudo nvidia docker run e NVIDIA VISIBLE DEVICES
  • 自动曝光在移动平台上的实现方案——以《使命召唤手游》为例

    一 Intro 在PBR渲染中 除了已被大家深入分析了很多遍的PBR材质属性 Surface Appearance 外 合理的光源强度和后处理也是不可或缺的部分 这里结合工作中的一些实践经验 讨论一下后处理中另一个关键环节 自动曝光在移动平
  • JAVA远程连接ssh异步,SSH-2实现java连接远程服务器并执行脚本命令

    参考文档 maven jar包 https mvnrepository com artifact ch ethz ganymed ganymed ssh2 Ganymed SSH2 API文档 http www ganymed ethz c
  • linux-删除KVM虚拟机

    1 查看主机 virsh list 2 关闭主机 virsh shutdown 虚拟机名称 3 删除主机定义 virsh undefine 虚拟机名称 4 删除KVM虚拟机文件 find name 虚拟机名称 rm rf 虚拟机文件
  • 【动手学习pytorch笔记】37.5 BERT微调

    BERT微调 import json import multiprocessing import os import torch from torch import nn from d2l import torch as d2l bert
  • tkinter简单选取文件或文件夹绝对路径

    选取文件夹 选取文件夹 def get folder root tkinter Tk root withdraw 获取文件夹路径 path filedialog askdirectory 返回文件夹路径 return path 选取文件路径
  • 阿里云智能编码插件Cosy,让你的开发过程既高效又轻松

    阿里云智能编码插件 Alibaba Cloud AI Coding Assistant 是一款AI编程助手 它提供代码智能补全和代码示例搜索能力 帮助你更快更高效地写出高质量代码 让你的开发过程既高效又轻松 点击立即体验 阿里云智能编码 你
  • 用mac做开发真的比用windows好么?

    近几年发现周围的程序员们使用mac的越来越多了 可是本人貌似对mac并不感冒 依旧在使用windows的队伍中 感觉win10用着也不错啊 虽然不怎么用mac 但是有一点不得不说mac的外形的确很酷 这一点不得不承认 也可能有一部分人就因为
  • Android开发-在Android应用里实现自动发送邮件的功能

    前言 前段时间由于项目的需要 就是在Android应用里的用户反馈功能需要当用户输入反馈的文本信息后 用户点击提交按钮自动把反馈的文本信息已发送邮件的形式发送给开发者 要实现这个功能 首先需要两个邮箱账号 一个是发送方的邮箱地址 一个是接收
  • AXI Uartlite IP AXI驱动代码

    说明 AXI Uartlite IP AXI驱动代码 根据博客 Xilinx AXI Uartlite IP核的使用 有问题联系微信 Crazzy M 效果简单展示 module uart parameter UART REG NUM 2
  • CAP 可能是CAP理论的最好解释

    一篇非常精彩的解释CAP理论的文章 翻译水平有限 不准确之处请参考原文 还请见谅 Chapter 1 Remembrance Inc Your new venture Last night when your spouse apprecia