1
1
+++
2
2
title = " (笔记)Distributed Systems for fun and profit"
3
3
date = 2021-06-12T13:08:54
4
- lastmod = 2022-02-24T14:18:39+ 08:00
5
- tags = [" distributed_system" ]
6
- categories = [" distributed_system" ]
4
+ lastmod = 2024-12-30T22:17:29- 08:00
5
+ tags = [" distributed_system" , " book " ]
6
+ categories = [" distributed_system" , " book " ]
7
7
draft = false
8
8
toc = true
9
9
+++
@@ -26,13 +26,7 @@ source: <http://book.mixu.net/distsys/>
26
26
27
27
关于 ` availability ` , 计算公式是:
28
28
29
- <style >.org-center { margin-left : auto ; margin-right : auto ; text-align : center ; }</style >
30
-
31
- <div class =" org-center " >
32
-
33
- Availability = uptime / (uptime + downtime)
34
-
35
- </div >
29
+ > Availability = uptime / (uptime + downtime)
36
30
37
31
38
32
### <span class =" section-num " >2.2</span > Failt tolerance {#failt-tolerance}
@@ -46,11 +40,11 @@ Availability = uptime / (uptime + downtime)
46
40
1 . 节点数(你想要更多的存储空间, 更强的计算能力, 自然需要更多的节点)
47
41
2 . 节点间的距离(信息传输, 光速是上限)
48
42
49
- 从设计系统的角度来考虑这两个限制:
43
+ 从设计系统的角度来考虑这两个限制:
50
44
51
- - 节点数越多, 出错(failure)的概率就越高(降低可用性, 增加了管理成本)
52
- - 节点数越多, 节点之间的通信就越多(限制节点数与性能之间的线性增长)
53
- - 距离越大, 节点通信的延迟就大(性能下降)
45
+ - 节点数越多, 出错(failure)的概率就越高(降低可用性, 增加了管理成本)
46
+ - 节点数越多, 节点之间的通信就越多(限制节点数与性能之间的线性增长)
47
+ - 距离越大, 节点通信的延迟就大(性能下降)
54
48
55
49
56
50
### <span class =" section-num " >2.3</span > Abstraction and model {#abstraction-and-model}
@@ -60,11 +54,11 @@ Availability = uptime / (uptime + downtime)
60
54
- Abstraction: it make things more manageable by removing real-world aspects that are not relevant to solving a problem.
61
55
- Model: it describes the key properties of a distributed system in a precise manner.
62
56
63
- 基于不同维度, 可以总结出不同的 Model:
57
+ 基于不同维度, 可以总结出不同的 Model:
64
58
65
- - System model(asynchronous/synchronous)
66
- - Failure model(crash-fail, partitions, Byzantine)
67
- - Consistency model(strong, eventual)
59
+ - System model(asynchronous/synchronous)
60
+ - Failure model(crash-fail, partitions, Byzantine)
61
+ - Consistency model(strong, eventual)
68
62
69
63
70
64
### <span class =" section-num " >2.4</span > Partition and replicate {#partition-and-replicate}
@@ -74,7 +68,7 @@ Availability = uptime / (uptime + downtime)
74
68
- partitioning: data set can be split over multiple nodes to allow for more parallel processing.
75
69
- replication: data set can be copied or cached on different nodes to reduce the distance between the client and the server and for greater fault tolerence.
76
70
77
- {{< figure src="/ox-hugo/part-repl.png" link="/ox-hugo/part-repl.png" >}}
71
+ {{< figure src="/ox-hugo/part-repl.png" link="/ox-hugo/part-repl.png" >}}
78
72
79
73
- partitioning: 相当每个节点存储一部分数据, 所有节点的数据汇总起来就是该系统存储的总数据. 但是某个节点挂了, 该节点的数据就丢了
80
74
- replication: 不同节点都存储同一份数据, 这样就可以减少读取不同数据的开销, 以及避免某个节点挂了, 导致部分数据不可用的情况. 但是需要更多的存储空间且不同节点之间数据的同步又是个大问题, 可以说是按下葫芦浮起瓢
@@ -100,21 +94,21 @@ Availability = uptime / (uptime + downtime)
100
94
- 通过网络通信, 可能出现某种不确定性或消息丢包
101
95
- 没有共享内容或共享锁
102
96
103
- 上面的特定会带来诸多的影响:
97
+ 上面的特定会带来诸多的影响:
104
98
105
- - 每个节点都并发运行程序
106
- - 本地为先: 每个节点都可以快速访问他们的本地状态, 而所有关于全局状态的信息都有可能是过时的
107
- - 节点可能挂掉, 并从故障中恢复回来
108
- - 消息可能延迟或丢失(不同于节点故障, 通常很难区分节点故障或网络故障)
109
- - 节点间的时钟可能不同步(本地时间与全局时间不一定对应, 且很难观察到异常)
99
+ - 每个节点都并发运行程序
100
+ - 本地为先: 每个节点都可以快速访问他们的本地状态, 而所有关于全局状态的信息都有可能是过时的
101
+ - 节点可能挂掉, 并从故障中恢复回来
102
+ - 消息可能延迟或丢失(不同于节点故障, 通常很难区分节点故障或网络故障)
103
+ - 节点间的时钟可能不同步(本地时间与全局时间不一定对应, 且很难观察到异常)
110
104
111
- 通过定义一个模型(model)来标识实现一个分布式系统需要交互的环境与机制:
105
+ 通过定义一个模型(model)来标识实现一个分布式系统需要交互的环境与机制:
112
106
113
- > a set of assumptions about the environment and facilities on which a distributed system is implemented
107
+ > a set of assumptions about the environment and facilities on which a distributed system is implemented
114
108
115
- A robust system model is one that makes the weakest assumptions: any algorithm written for such a system is very tolerant of different environments, since it makes very few and very weak assumptions.
109
+ A robust system model is one that makes the weakest assumptions: any algorithm written for such a system is very tolerant of different environments, since it makes very few and very weak assumptions.
116
110
117
- 模型需要越少的假设条件, 可以适应的环境就越多. 等价交换, fair enough.
111
+ 模型需要越少的假设条件, 可以适应的环境就越多. 等价交换, fair enough.
118
112
119
113
120
114
#### <span class =" section-num " >3.2.1</span > Nodes in our system model {#nodes-in-our-system-model}
@@ -125,9 +119,9 @@ Availability = uptime / (uptime + downtime)
125
119
- 可以存储数据到volatile memory(例如内存)或stable state(日志或磁盘)
126
120
- 拥有时钟(可以准的或者是不准的)
127
121
128
- 有很多的故障模型(failure models) 描述了节点挂掉(fail)的方式, 实际中, 大部分的系统都假设是个crash-recovery failure model, 即节点可能挂掉, 但是能从某个状态中恢复回来.
122
+ 有很多的故障模型(failure models) 描述了节点挂掉(fail)的方式, 实际中, 大部分的系统都假设是个crash-recovery failure model, 即节点可能挂掉, 但是能从某个状态中恢复回来.
129
123
130
- > A crash-recovery failure model: that is, nodes can only fail by crashing, and can(possibly) recover after crashing at some later point.
124
+ > A crash-recovery failure model: that is, nodes can only fail by crashing, and can(possibly) recover after crashing at some later point.
131
125
132
126
133
127
#### <span class =" section-num " >3.2.2</span > Communication links in our system model {#communication-links-in-our-system-model}
@@ -137,7 +131,8 @@ communication links 不知道应该怎么翻译, 通讯链路? 不译也罢
137
131
communication links 用于沟通不同的节点, 允许信息在双向流动. 部分算法假设网络是可靠的: 消息永不丢失并且永不延迟. 虽说这样假设有些许道理, 但是通常我们都是假设网络是不可靠, 因此消息可能丢失或者延迟.
138
132
139
133
节点故障 vs 网络分区故障:
140
- [ ![ ] ( /ox-hugo/system-of-2.png )] ( /ox-hugo/system-of-2.png )
134
+
135
+ {{< figure src="/ox-hugo/system-of-2.png" link="/ox-hugo/system-of-2.png" >}}
141
136
142
137
143
138
#### <span class =" section-num " >3.2.3</span > Timing/ordering assumptions {#timing-ordering-assumptions}
@@ -179,21 +174,22 @@ FLP impossibility result 定义了一个最坏情况, 在允许节点失效的
179
174
- Availability: node failures do not prevent survivors from continuing to operate.
180
175
- Partition tolerance: the system continues to operate despite message loss due to network and/or node failure.
181
176
182
- 最多只能有两个属性被满足, 如下图:
177
+ 最多只能有两个属性被满足, 如下图:
183
178
184
- {{< figure src="/ox-hugo/CAP.png" link="/ox-hugo/CAP.png" >}}
179
+ {{< figure src="/ox-hugo/CAP.png" link="/ox-hugo/CAP.png" >}}
185
180
186
- 同时满足三个属性情况是无法实现的, 即中间交集处. 而满足两个属性的系统模型有如下三个:
181
+ 同时满足三个属性情况是无法实现的, 即中间交集处. 而满足两个属性的系统模型有如下三个:
187
182
188
- - CA(consistency + availability): 弱化分区, 保证一致性和可用性, 也变成单机程序, 个人认为Oracle就是其中典范
189
- - CP(consistency + partition tolerance): 弱化可用性, 可能出现无法提供可用结果的情形, 允许少数节点不可用. 典型算法就是Paxos
190
- - AP(availability + partition tolerance): 弱化一致性, 节点之间可能失去联系, 导致全局数据不一致. 典型例子就是诸多的NoSql
183
+ - CA(consistency + availability): 弱化分区, 保证一致性和可用性, 也变成单机程序, 个人认为Oracle就是其中典范
184
+ - CP(consistency + partition tolerance): 弱化可用性, 可能出现无法提供可用结果的情形, 允许少数节点不可用. 典型算法就是Paxos
185
+ - AP(availability + partition tolerance): 弱化一致性, 节点之间可能失去联系, 导致全局数据不一致. 典型例子就是诸多的NoSql
191
186
192
- CA 和CP 模型都提供强一致的模型, 唯一的差别是, CA系统不允许任何节点故障, 因为CA系统无法区别节点故障和网络故障, 为了避免状态不一致, 只能停写; 而对于 ` 2f+1 ` 个节点的CP系统, 允许 ` f ` 个节点故障, 是因为其能通过 single-copy consistency 机制, 能保证状态能达到最终一致, 避免出现状态不一致, 从而支持部分节点不可用
187
+ CA 和CP 模型都提供强一致的模型, 唯一的差别是, CA系统不允许任何节点故障, 因为CA系统无法区别节点故障和网络故障, 为了避免状态不一致, 只能停写;
188
+ 而对于 ` 2f+1 ` 个节点的CP系统, 允许 ` f ` 个节点故障, 是因为其能通过 single-copy consistency 机制, 能保证状态能达到最终一致, 避免出现状态不一致, 从而支持部分节点不可用
193
189
194
- 因此, 选择了网络分区, 就需要在高可用和强一致性之间作取舍, 而系统设计即是在基于不同的场景, 作出不同的取舍.
190
+ 因此, 选择了网络分区, 就需要在高可用和强一致性之间作取舍, 而系统设计即是在基于不同的场景, 作出不同的取舍.
195
191
196
- 同样, 强一致性和高性能也存在矛盾, 要保证强一致性, 自然需要节点之间通信达到共识, 这自然会拉高延迟, 这也要系统设计者作出取舍.
192
+ 同样, 强一致性和高性能也存在矛盾, 要保证强一致性, 自然需要节点之间通信达到共识, 这自然会拉高延迟, 这也要系统设计者作出取舍.
197
193
198
194
199
195
### <span class =" section-num " >3.5</span > Consistency model {#consistency-model}
@@ -314,7 +310,7 @@ Time is a source of order. 时间可以解析成以下三种形式:
314
310
不过, 工程实践中的确有程序使用这样的模型:
315
311
316
312
- Facebook的[ Cassandra] ( https://en.wikipedia.org/wiki/Apache_Cassandra ) : 假设时钟是同步的, 因为它使用时间戳来处理写冲突, 以最新的时间为准
317
- - Google的[ Spanner] ( https://research.google.com/archive/spanner.html ) : 使用` TrueTime ` API, 保证时间同步的条件下, 又消除了时间漂移的最坏情况.
313
+ - Google的[ Spanner] ( https://research.google.com/archive/spanner.html ) : 使用= TrueTime= API, 保证时间同步的条件下, 又消除了时间漂移的最坏情况.
318
314
319
315
320
316
#### <span class =" section-num " >4.3.2</span > Time with a "Local-clock" assumption {#time-with-a-local-clock-assumption}
@@ -389,7 +385,7 @@ Vector clock是Lamport clock 的扩展, 对于有 `N` 个节点的分布式系
389
385
390
386
使用全序关系也是可能的, 但是为了协调全局顺序, 会付出高昂的性能代价.
391
387
392
- 如果你对时间_顺序_同步性要求没有那么高 , 你可以获得相当的性能提升. 那么, 什么时候需要顺序来保证正确性呢? 后面提到 ` CALM定理 ` 会为你提供答案.
388
+ 如果你对时间/顺序/同步性要求没有那么高 , 你可以获得相当的性能提升. 那么, 什么时候需要顺序来保证正确性呢? 后面提到 ` CALM定理 ` 会为你提供答案.
393
389
394
390
说到底, 又是取舍的话题, 下面的情景只存在电影中:
395
391
@@ -479,7 +475,7 @@ Vector clock是Lamport clock 的扩展, 对于有 `N` 个节点的分布式系
479
475
- synchronous primary/backup replication
480
476
- asynchronous primary/backup replication
481
477
482
- 前者需要两条消息(update + ack), 而后者只需要一条消息(update). 主_从复制非常常见 , MySQL 复制使用的就是主_从复制 , MySQL 支持三种模式复制:
478
+ 前者需要两条消息(update + ack), 而后者只需要一条消息(update). 主/从复制非常常见 , MySQL 复制使用的就是主/从复制 , MySQL 支持三种模式复制:
483
479
484
480
- 同步: 客户端请求, 先写入主机, 然后同步到所有备机, 成功后响应客户端, 在此之间, 阻塞客户端(性能最差)
485
481
- 异步: 客户端请求, 先写入主机, 然后响应客户端, 再同步备机(同步备机前主机挂, 则丢失数据)
@@ -651,4 +647,4 @@ reported by the followers)
651
647
652
648
## <span class =" section-num " >6</span > 5. Replication: Accepting Diveragence {#5 -dot-replication-accepting-diveragence}
653
649
654
- 笔记待续
650
+ 笔记待续
0 commit comments