六味地黄丸有什么用| 欧阳修字什么| 脂蛋白a高是什么原因引起的| 酉读什么| 很low是什么意思| 为什么经常拉肚子| 补气血吃什么最好最快| 什么叫血管瘤| 包虫病是什么症状| 珠地棉是什么面料| 生殖感染用什么消炎药效果好| 天秤女喜欢什么样的男生| 霖字五行属什么| 超声心动图检查什么| 龟粮什么牌子的好| 术后病人吃什么营养恢复快| c是什么车| 口香糖是什么材料做的| 7月17日什么星座| 母亲o型父亲b型孩子是什么血型| 药玉是什么| 胃病吃什么水果好| 西南方向五行属什么| 减持是什么意思| 右眼跳代表什么| 外婆家是什么菜系| 挣扎是什么意思| 备孕检查都检查什么项目| 脚指甲变白是什么原因| 蜂窝网络是什么| 撸管什么意思| 龙女是什么意思| 一个草字头一个氏念什么| 鼠肚鸡肠是什么生肖| 什么人不适合做收银员| 子宫癌筛查做什么检查| 梦见兔子是什么预兆| 三点水加累读什么| 岁月匆匆是什么意思| 脚底有痣代表什么| 血糖高做什么运动好| 孩子发烧按摩什么部位退烧| 四不像是指什么动物| 麦粒肿吃什么药| 心脏传导阻滞吃什么药| 放疗和化疗有什么区别| 接吻是什么样的感觉| 日晡是什么意思| 捭阖是什么意思| 血压偏低吃什么| 车万是什么意思| 吃什么记忆力增强| 什么是肺结节| 舌头发白有齿痕是什么原因| 脊髓是什么| 骨钙素低是什么原因| 口语化是什么意思| 肾错构瘤是什么原因引起的| afd是什么意思| 为什么正骨后几天越来越疼| 什么水果蛋白质含量高| 厚颜无耻是什么意思| 行动派是什么意思| 时柱将星是什么意思| 海带不能和什么一起吃| 才高八斗是指什么生肖| 孕妇适合喝什么牛奶| 嘴唇干裂是什么原因| 肝血不足吃什么食补最快| 头疼想吐吃什么药| 皮蛋不能和什么一起吃| 母带是什么意思| 肝硬化早期有什么症状| 纸醉金迷是什么意思| 痛风该吃什么药好得快| 秋天有什么植物| 什么吃蚊子| 不昧因果是什么意思| 八股是什么意思| 用什么洗头白发能变黑| 提携是什么意思| 亚麻是什么面料| 鼻尖发红是什么原因| 舌苔厚腻发白是什么原因| 互为表里是什么意思| 牙齿为什么会痛| rh血型阳性什么意思| 痂是什么意思| 失眠吃什么药效果好| 甲亢能吃什么| 一个土一个斤念什么| 落枕是什么原因| 蚊子喜欢叮什么样的人| miles是什么意思| ENBD手术全称是什么| 耸肩是什么意思| landrover是什么车| 梦见一个人代表什么| 出殡下雨是什么兆头| 1977年属什么生肖| 花字五行属什么| 法国铁塔叫什么| 神经性耳鸣有什么症状| 苏联什么时候解体| 两点是什么时辰| 低血压高吃什么药| 宫外孕是什么症状| 低血糖挂什么科| 黄瓜和什么不能一起吃| 什么是豆制品| 肠痈是什么意思| 打哈欠是什么意思| 收缩压和舒张压是什么| 拜阿司匹林什么时间吃最好| 胳膊脱臼是什么症状| 喝什么水解酒| 产值是什么| 黄丫头是什么鱼| 健康证需要检查什么项目| 勇敢的生肖是什么生肖| 黄芪长什么样子的图片| 脸上痣多是什么原因| 什么海翻江| 劼字取名的寓意是什么| 澳门打车用什么软件| 脱发应该挂什么科室| hct是什么| mfd是什么意思| 贤良淑德后半句是什么| 听佛歌有什么好处| 红色加绿色是什么颜色| 商务专员是做什么的| 梦见吃水饺是什么预兆| siri什么意思| 一个口一个且念什么字| 检查腰部挂什么科| 打耳洞后不能吃什么| 鸡血藤手镯有什么功效| 黑曜石属于五行属什么| 阴唇发黑是什么原因| 提拉米苏是什么意思| 爱上一个人是什么感觉| 氨水是什么东西| 张菲和费玉清什么关系| 中药学是干什么的| 突然发胖要警惕什么病| 梦到老公被蛇咬是什么意思| cancer是什么意思| 5月22号是什么星座| tat是什么意思| 脚底烧热是什么原因| 13年属什么生肖| 捉代表什么生肖| 什么光没有亮度| 一什么牙刷| 博士和博士后有什么区别| 猪八戒是什么佛| 外阴瘙痒是什么病| 高血糖吃什么食物好| 桂圆和龙眼有什么区别| 三月初什么星座| 聤耳是什么意思| 达字五行属什么| 彗星是什么| 颉在姓氏里念什么| 蹉跎是什么意思| 荔枝都有什么品种| 海绵体供血不足吃什么药| 银五行属性是什么| 乙肝表面抗原高是什么意思| 为什么月经每个月提前| 什么地发现| 失眠为什么开奥氮平片| bruce是什么意思| 铁皮石斛有什么作用| 猫可以看到什么颜色| icu是什么意思| 妮字五行属什么| 部长助理是什么级别| 日龙包什么意思| 翻墙软件是什么| 卖酒需要办理什么证| 怀孕会出现什么状况| 飞机上可以带什么吃的| 一直打嗝是什么原因| 紫笋茶属于什么茶| 为什么会扁桃体发炎| 大蒜泡酒有什么功效| 前列腺钙化吃什么药| 什么是道德绑架| 叶倩文属什么生肖| 对等是什么意思| 耳朵痒用什么药最有效| 什么是混合痔| 脚发热是什么原因| 章鱼的血是什么颜色| 同字五行属什么| 细胞角蛋白19片段是什么意思| 扯证是什么意思| 晕车是什么原因| 老公生日送什么礼物好最合适| 咽喉肿痛吃什么消炎药| 梦见大狼狗是什么意思| 三焦指的是什么器官| 心脏早搏吃什么药效果好| 鹞是什么意思| 脑血栓前兆是什么症状表现| 甘草泡水喝有什么好处和坏处| pd什么意思| 1月19号是什么星座| 慷慨什么| 梅花手表属于什么档次| 1997年是什么命| 头晕有点恶心是什么原因| 彩妆是什么意思| 寒凝血瘀吃什么中成药| 得了甲亢都有什么症状| 没事找事是什么意思| 鬼压床是什么原因造成的| 小麦粉可以做什么吃的| 什么是电解质饮料| 老鸨是什么| 容易出汗是什么原因| 农历六月十二是什么日子| 大学院长是什么级别| 广州有什么山| 物竞天择是什么意思| 建档是什么意思| 卵泡回声什么意思| 米酒是什么酒| 早泄吃什么药| 生肖鼠和什么生肖最配| 菩提什么意思| 胎盘位置低有什么危险| 头发定型用什么好| 12月5号是什么星座| 眼皮老是跳是什么原因| 运六月有什么说法| 活性酶是什么| 金鸡独立是什么意思| 香火是什么意思| 办幼儿园需要什么证| 为什么头老是晕晕的| 湿厕纸是干什么用的| 天热喝什么茶好| 阴历九月是什么星座| 鼻子上长红疙瘩是什么原因| 市辖区是什么意思| 空调一级能效什么意思| 不耐受和过敏有什么区别| 牙齿浮起来是什么原因| 狗狗胰腺炎有什么症状| 下巴出汗多是什么原因| nothomme什么牌子| 醉酒当歌什么意思| 人为什么要吃盐| 刀子嘴豆腐心什么意思| 身体出汗是什么原因| 中药液是什么药| 扒灰是什么意思| 三生万物是什么意思| 打耳洞不能吃什么| 社保指什么| 尿失禁吃什么药| 百度

Monday, July 15, 2019

The dangers of conditional consistency guarantees

The ease of writing an application on top of infrastructure that guarantees consistency can not be overstated. It’s just so much easier to write an application when you can be sure that every read will return the most recent state of the data --- no matter where in the world writes to data state occur, and no matter what types of failure may occur.

Unfortunately, consistency in distributed systems comes at a cost. Other desirable system properties may be traded off in order to uphold a consistency guarantee. For example, it is well known (see the CAP theorem) that in the event of a network partition, it is impossible to guarantee both consistency and availability. One must be traded off for the other. Furthermore, in a system deployed across a wide geography, the laws of physics prevent the communication required to maintain consistency from happening instantaneously. This leads to the PACELC tradeoff: when there is a network partition (the P in PACELC), the system must decide how it will tradeoff availability (A) for consistency (C). Else (E) --- during normal operation of the system --- the system must decide how it will tradeoff latency (L) for consistency (C).

There are four points in the PACELC tradeoff space: (1) PA/EC (when there is a partition, choose availability; else, choose consistency), (2) PC/EC (choose consistency at all times), (3) PA/EL (prioritize availability and latency over consistency), and (4) PC/EL (when there is a partition, choose consistency; else, choose latency).

If you were to ask a student who just learned about the CAP theorem in a distributed systems class what guarantees they would want from a distributed system deployed for an application that needs 99.999% availability, the student would likely answer: “That’s easy! I would choose a system that prioritizes availability over consistency in the event of a network partition. But in the absence of a network partition, it is possible for a system to guarantee both availability and consistency, so I would want both those guarantees in the system I would deploy.”

This answer is natural and obvious. But at the same time, it is naive and incorrect.

The system that the student described would be a PA/EC system from PACELC --- a system that does not guarantee consistency during a network partition, but otherwise guarantees consistency. There are many applications that need several “nines” of availability. If the right PACELC system for those applications was PA/EC, then there would be many vendors competing with each other, attempting to sell the best PA/EC system. Yet in practice, the opposite is true --- it is extremely rare to find PA/EC systems in the wild. In fact, it took me several years until I came across the IMDG (in-memory data grid) market before I could find examples of real PA/EC systems.

The reason for this is that PA/EC systems are much less useful than one might initially expect. To understand why this is the case, one must understand the fundamental difference between a real guarantee and a conditional guarantee.


Real guarantees vs. conditional guarantees


Of the three desirable properties that we’ve mentioned thus far as being desirable in a distributed system --- availability, consistency, and latency --- only one of them can ever be a real guarantee: consistency. No system will ever guarantee 100% availability, nor will any system guarantee that 100% of requests will complete within a particular latency bound. Such guarantees would be impossible to uphold. A “PA” system in PACELC prioritizes availability, but cannot guarantee 100% availability. Similarly, an “EL” system in PACELC prioritizes latency, but does not make any particular 100% guarantees.

In contrast, consistency is a real guarantee. Systems that guarantee consistency are actually capable of upholding the promise of 100% consistency, and many systems do in fact provide it.

Real guarantees form the foundation of the success of modern computing. Computers are extremely complex systems. Even a simple program must involve a large number of complex components --- from registers and logic gates to cache and memory to operating systems and security all the way up to the run time environment of the program. A simple “hello world” program ought to take weeks to develop. The reason why it doesn’t is because of the power of “abstraction” in computer science. Each level of a computer system builds on top of an underlying level that abstracts away the complex details of its implementation. Instead, the underlying level presents an interface to the higher level, and inviolable guarantees about what is returned through this interface.

For example, when a program reads from a particular place in memory, it can assume that it will see the data that was last written there. In reality, the processor inside a computer may choose to execute instructions within a program out of order. Furthermore, electric or magnetic interference may cause bits to spontaneously flip in memory. In practice, complicated solutions are used to detect and correct such bit corruption, including using redundant memory bits, additional circuitry, and error correcting codes. All of this is hidden to the higher level program that wants to read this location in memory. The higher level program assumes that it will receive the data that was most recently written to that location 100% of the time. [Side note: In theory, all of the error correcting logic in storage systems still cannot yield an actual 100% guarantee. However, the chances of a corrupted data value being returned to the end user is so infinitesimally small that this guarantee is still treated like 100% for all practical purposes.]

Imagine the extra complexity that would be involved in writing a program if you could not assume that instructions from a program are processed in the specified order, or the data in memory has not been corrupted. Almost every line of code that reads data from a variable would have to be surrounded by ‘if-statements’ that check for what might be corruption in that particular context and that specifies what should be done if the read appears to not be correct. This extra code would likely increase the development cycle for a program by one to two orders of magnitude!

For a program to be “bug-free”, this guarantee must be 100%. If a read returns the correct result 99% of the time, or even 99.99% or 99.9999% of the time, the above described ‘if-statements’ and conditional logic will still be necessary. Only if the program can assume that the correct result will always be returned can the extra conditional logic be avoided. Thus, from the perspective of the developer, there is an enormous difference between a complete guarantee and an incomplete guarantee. Within the space of incomplete guarantees, it is certainly the case that 99.9999% accuracy is better than 99% accuracy. But the big jump in complexity savings for the developer is the jump between anything less than 100% and a 100% guarantee.

This is why a PA/EC system has limited utility to an application developer. A PA/EC system is a system that guarantees consistency in all cases …. except when there is a network partition. In other words, a PA/EC makes a conditional guarantee of consistency: it guarantees consistency in all cases as long as a particular condition is met: that there is no network partition.

However, we just said that the big jump in complexity savings for the developer is a jump between anything less than 100% and a 100% guarantee. Any guarantee that comes with conditions that are out of the control of the developer (such as ensuring that there will never be a network partition), is not that helpful. The developer still has to write code to handle the cases where the guarantee is not upheld.

I am not arguing that all systems must guarantee consistency. I am only pointing out that there is a big difference in developer complexity between developing on top of a system that guarantees consistency fully, and one that guarantees consistency only under certain conditions. Without a full guarantee of consistency, there is a significant amount of extra effort required to ensure the absence of corner-case bugs that may emerge days, weeks, or even years after the application is first deployed.


Conditional guarantees and PACELC


We just explained that a PA system in PACELC results in a large amount of extra effort for the application developer, in order to ensure that the application remains bug-free even when inconsistent reads occur during a network partition. If so, during normal operation, where there is a tradeoff between consistency and latency, why choose consistency? All of the effort in building an application that does not break in the face of inconsistent reads has already been paid. Why not benefit from all that effort during normal operation and get better latency as well?

All of this suggests that application developers should decide whether they want to develop on top of a system that guarantees consistency or not. If they want consistency, they should deploy on top of a PC/EC system in PACELC --- i.e. a system that guarantees consistency 100% of the time. If they are willing to go to all of the extra effort to build on top of a system that does not guarantee consistency, they should be looking to get as many benefits as possible from this effort, and should deploy on top of PA/EL system, and thereby get better availability and latency properties (even if those properties do not come with guarantees).


New consistency guarantees in Hazelcast


As I pointed out in a previous post, when deploying within a single geographic region, the latency vs. consistency tradeoff is not significant. In such environments, there is not much difference between PA/EC and PA/EL systems. Since in-memory data grids are typically deployed in a single region, PA/EC became the standard PACELC option for the IMDG market.

Nonetheless, it is interesting to note how Hazelcast --- one of the most widely used IMDG implementations --- is moving away from the PA/EC default configuration and towards the more natural PC/EC and PA/EL pairings.

In 2017, I wrote an in-depth analysis of Hazelcast’s consistency and availability guarantees. At around the same time, Kyle Kingsbury published a linearizability analysis of Hazelcast using his Jepsen testing library. These analyses led to what CEO Greg Luck tells me was 3 person-years of effort to release the first PC/EC configuration option in Hazelcast.

A quick reminder about what Hazelcast does: Many Java programs store program state inside Java collections and data structures such as Queue, Map, or Multimap. As a program scales --- both in terms of the number of clients accessing data and in terms of the amount of data stored, these data structures may get too large to fit in memory on a single server. Hazelcast provides a distributed implementation of these popular data structures, thereby enabling programs that leverage them to scale. Java programs interact with Hazelcast identically to how they interacted with the local data Java structures. However, under the covers, Hazelcast is distributing and replicating them across a cluster of machines.

Hazelcast also provides distributed implementations of Java concurrency structures such as AtomicLong, AtomicReference, Lock. Using such structures without a consistency guarantee is downright dangerous. For example, in situations for which consistency is not upheld, it is possible for multiple different processes to acquire the same lock (concurrently) or for non-atomic actions to occur on supposedly atomic data structures. In other words, lack of consistency violates the fundamental premise of these backbone Java concurrency structures.

With a PC/EC configuration option, you can now deploy Hazelcast’s distributed version of these concurrency tools --- IAtomicLong, IAtomicReference, and ILock --- and get identical correctness guarantees relative to what they provide when being used by a regular single-server Java program.

Hazelcast’s PC/EC configuration performs distributed agreement on data structure state via the Raft consensus protocol. Raft is known for achieving strong availability. Even when a network partition occurs, the majority of servers can remain available (the consistency guarantee only requires that the minority partition must lose availability).

Separately from the consistency issue, another well-known problem with distributed implementations of lock data structures is liveness. A server can acquire the lock and then fail for an indefinite period of time while holding the lock. Meanwhile the rest of the distributed system remains alive, but unable to acquire the lock and make progress. Therefore, in practice, distributed locks typically include timeouts, in order to prevent servers that fail while holding the lock from causing the rest of the system to stall indefinitely. Unfortunately, as soon as it is possible for a lock to timeout, it is possible for a process to get timed out while holding the lock, and yet be temporarily unaware that the lock timed out. In such a scenario, it is possible for two different processes to concurrently believe they have the lock, and perform concurrent side-effects that the lock was designed to prevent. Hazelcast’s distributed lock implementation includes a fencing mechanism which enables downstream code --- code that is designed to be run while locks are being held --- to participate in the locking protocol and be able to distinguish which process is correct when multiple processes concurrently believe that they hold the lock.

As far as the PA/EL option in Hazelcast, they have recently added PN Counters --- a CRDT counter implementation that enables some correctness guarantees despite the potential for inconsistent reads. In particular, when there is no consistency guarantee, it is possible for a server to read a stale value of the counter. For example, process A may update the value of a counter from 4 to 5. Afterwards, process B sees the stale value of the counter (4) and also adds one to it (to get 5). In versions of Hazelcast prior to 3.10, the final value of the counter --- even after whatever event caused the inconsistency is resolved --- would be 5. In other words, one of the two increments of the counter would be lost. With PN Counters (introduced in Hazelcast 3.10), the counter state will eventually converge to the correct value (in this case --- 6 --- that reflects the value after two increments to an initial value of 4). PN Counters also support decrements of the counter (in addition to increments), and guarantees (1) read-your-own-writes and (2) monotonic reads in addition to (3) what I described above --- the eventual convergence of the counter value to the correct value.

Furthermore, inconsistent reads in Hazelcast prior to version 3.10 --- under PA/EC or PA/EL configurations --- could potentially result in duplicate IDs being generated. Hazelcast 3.10 introduced Flake ID generators which guarantee global unique IDs even in the absence of a global consistency guarantee.


Conclusion


PA/EC systems sound good in theory, but are not particularly useful in practice. Our one example of a real PA/EC system --- Hazelcast --- has spent the past 1.5 years introducing features that are designed for alternative PACELC configurations --- specifically PC/EC and PA/EL configurations. PC/EC and PA/EL configurations are a more natural cognitive fit for an application developer. Either the developer can be certain that the underlying system guarantees consistency in all cases (the PC/EC configuration) in which case the application code can be significantly simplified, or the system makes no guarantees about consistency at all (the PA/EL configuration) but promises high availability and low latency. CRDTs and globally unique IDs can still provide limited correctness guarantees despite the lack of consistency guarantees in PA/EL configurations.

No comments:

Post a Comment

生扶什么意思 百香果有什么好处功效 踏实是什么意思 地藏王菩萨保佑什么 佳字属于五行属什么
3月14日是什么星座 做梦是什么原因 大型血小板比率偏低是什么意思 nafion溶液是什么 为什么会做噩梦
为什么要多吃鱼 一根葱十分钟什么意思 腰扭伤吃什么药 司马光和司马迁是什么关系 175是什么尺码
五行中什么生水 小分子水是什么水 腺肌瘤是什么病 老年人脚肿挂什么科 蚊子不喜欢什么味道
小孩拉肚子吃什么药好520myf.com 大姨妈吃什么水果jasonfriends.com 什么是早搏0297y7.com 磨牙吃什么药能治好hcv9jop0ns3r.cn 吃什么不会胖hcv9jop1ns3r.cn
1月15日什么星座hcv8jop5ns3r.cn 毒龙钻什么意思hcv8jop7ns5r.cn 哺乳期可以喝什么饮料hcv8jop7ns0r.cn 5点是什么时辰hcv7jop6ns9r.cn zxj是什么意思hcv9jop2ns0r.cn
什么游戏赚钱hcv8jop1ns1r.cn 手指甲看什么科室hcv9jop0ns8r.cn 什么是阻生智齿hcv8jop8ns6r.cn 白羊歌词是什么意思hcv9jop4ns3r.cn 臭虫长什么样子图片aiwuzhiyu.com
肝郁脾虚吃什么药效果最好hcv7jop7ns0r.cn 改良剂是什么hcv8jop5ns4r.cn 什么一惊hcv9jop4ns3r.cn 心梗吃什么药效果好hcv8jop7ns0r.cn 精液的主要成分是什么hcv9jop0ns8r.cn
百度