Skip to content

Commit d81e69f

Browse files
committed
Fix incorrect tag and delete duplicated post.
1 parent 4d9fab7 commit d81e69f

File tree

3 files changed

+43
-233
lines changed

3 files changed

+43
-233
lines changed

content/en/post/2021/how_to_design_a_reliable_distributed_timer.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
+++
22
title = "How To Design A Reliable Distributed Timer"
33
date = 2021-08-05T09:19:36
4-
lastmod = 2022-02-24T14:01:37+08:00
4+
lastmod = 2024-12-30T22:16:46-08:00
55
tags = ["distributed_system", "timer"]
66
categories = ["distributed_system"]
77
draft = false
@@ -183,4 +183,4 @@ Wish you have fun and profit
183183
## <span class="section-num">4</span> Reference {#reference}
184184

185185
- [Paper: Hashed and Hierarchical Timing Wheels: Efficient Data Structures for Implementing a Timer Facility](http://www.cs.columbia.edu/~nahum/w6998/papers/ton97-timing-wheels.pdf)
186-
- [Hashed and Hierarchical Timing Wheels](https://blog.acolyer.org/2015/11/23/hashed-and-hierarchical-timing-wheels/)
186+
- [Hashed and Hierarchical Timing Wheels](https://blog.acolyer.org/2015/11/23/hashed-and-hierarchical-timing-wheels/)

content/zh/post/2021/distributed_system_for_fun_and_profit.md

Lines changed: 41 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
+++
22
title = "(笔记)Distributed Systems for fun and profit"
33
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"]
77
draft = false
88
toc = true
99
+++
@@ -26,13 +26,7 @@ source: <http://book.mixu.net/distsys/>
2626
2727
关于 `availability`, 计算公式是:
2828

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)
3630
3731

3832
### <span class="section-num">2.2</span> Failt tolerance {#failt-tolerance}
@@ -46,11 +40,11 @@ Availability = uptime / (uptime + downtime)
4640
1. 节点数(你想要更多的存储空间, 更强的计算能力, 自然需要更多的节点)
4741
2. 节点间的距离(信息传输, 光速是上限)
4842

49-
从设计系统的角度来考虑这两个限制:
43+
从设计系统的角度来考虑这两个限制:
5044

51-
- 节点数越多, 出错(failure)的概率就越高(降低可用性, 增加了管理成本)
52-
- 节点数越多, 节点之间的通信就越多(限制节点数与性能之间的线性增长)
53-
- 距离越大, 节点通信的延迟就大(性能下降)
45+
- 节点数越多, 出错(failure)的概率就越高(降低可用性, 增加了管理成本)
46+
- 节点数越多, 节点之间的通信就越多(限制节点数与性能之间的线性增长)
47+
- 距离越大, 节点通信的延迟就大(性能下降)
5448

5549

5650
### <span class="section-num">2.3</span> Abstraction and model {#abstraction-and-model}
@@ -60,11 +54,11 @@ Availability = uptime / (uptime + downtime)
6054
- Abstraction: it make things more manageable by removing real-world aspects that are not relevant to solving a problem.
6155
- Model: it describes the key properties of a distributed system in a precise manner.
6256

63-
基于不同维度, 可以总结出不同的 Model:
57+
基于不同维度, 可以总结出不同的 Model:
6458

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)
6862

6963

7064
### <span class="section-num">2.4</span> Partition and replicate {#partition-and-replicate}
@@ -74,7 +68,7 @@ Availability = uptime / (uptime + downtime)
7468
- partitioning: data set can be split over multiple nodes to allow for more parallel processing.
7569
- 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.
7670

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" >}}
7872

7973
- partitioning: 相当每个节点存储一部分数据, 所有节点的数据汇总起来就是该系统存储的总数据. 但是某个节点挂了, 该节点的数据就丢了
8074
- replication: 不同节点都存储同一份数据, 这样就可以减少读取不同数据的开销, 以及避免某个节点挂了, 导致部分数据不可用的情况. 但是需要更多的存储空间且不同节点之间数据的同步又是个大问题, 可以说是按下葫芦浮起瓢
@@ -100,21 +94,21 @@ Availability = uptime / (uptime + downtime)
10094
- 通过网络通信, 可能出现某种不确定性或消息丢包
10195
- 没有共享内容或共享锁
10296

103-
上面的特定会带来诸多的影响:
97+
上面的特定会带来诸多的影响:
10498

105-
- 每个节点都并发运行程序
106-
- 本地为先: 每个节点都可以快速访问他们的本地状态, 而所有关于全局状态的信息都有可能是过时的
107-
- 节点可能挂掉, 并从故障中恢复回来
108-
- 消息可能延迟或丢失(不同于节点故障, 通常很难区分节点故障或网络故障)
109-
- 节点间的时钟可能不同步(本地时间与全局时间不一定对应, 且很难观察到异常)
99+
- 每个节点都并发运行程序
100+
- 本地为先: 每个节点都可以快速访问他们的本地状态, 而所有关于全局状态的信息都有可能是过时的
101+
- 节点可能挂掉, 并从故障中恢复回来
102+
- 消息可能延迟或丢失(不同于节点故障, 通常很难区分节点故障或网络故障)
103+
- 节点间的时钟可能不同步(本地时间与全局时间不一定对应, 且很难观察到异常)
110104

111-
通过定义一个模型(model)来标识实现一个分布式系统需要交互的环境与机制:
105+
通过定义一个模型(model)来标识实现一个分布式系统需要交互的环境与机制:
112106

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
114108
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.
116110

117-
模型需要越少的假设条件, 可以适应的环境就越多. 等价交换, fair enough.
111+
模型需要越少的假设条件, 可以适应的环境就越多. 等价交换, fair enough.
118112

119113

120114
#### <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)
125119
- 可以存储数据到volatile memory(例如内存)或stable state(日志或磁盘)
126120
- 拥有时钟(可以准的或者是不准的)
127121

128-
有很多的故障模型(failure models) 描述了节点挂掉(fail)的方式, 实际中, 大部分的系统都假设是个crash-recovery failure model, 即节点可能挂掉, 但是能从某个状态中恢复回来.
122+
有很多的故障模型(failure models) 描述了节点挂掉(fail)的方式, 实际中, 大部分的系统都假设是个crash-recovery failure model, 即节点可能挂掉, 但是能从某个状态中恢复回来.
129123

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.
131125
132126

133127
#### <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 不知道应该怎么翻译, 通讯链路? 不译也罢
137131
communication links 用于沟通不同的节点, 允许信息在双向流动. 部分算法假设网络是可靠的: 消息永不丢失并且永不延迟. 虽说这样假设有些许道理, 但是通常我们都是假设网络是不可靠, 因此消息可能丢失或者延迟.
138132

139133
节点故障 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" >}}
141136

142137

143138
#### <span class="section-num">3.2.3</span> Timing/ordering assumptions {#timing-ordering-assumptions}
@@ -179,21 +174,22 @@ FLP impossibility result 定义了一个最坏情况, 在允许节点失效的
179174
- Availability: node failures do not prevent survivors from continuing to operate.
180175
- Partition tolerance: the system continues to operate despite message loss due to network and/or node failure.
181176

182-
最多只能有两个属性被满足, 如下图:
177+
最多只能有两个属性被满足, 如下图:
183178

184-
{{< figure src="/ox-hugo/CAP.png" link="/ox-hugo/CAP.png" >}}
179+
{{< figure src="/ox-hugo/CAP.png" link="/ox-hugo/CAP.png" >}}
185180

186-
同时满足三个属性情况是无法实现的, 即中间交集处. 而满足两个属性的系统模型有如下三个:
181+
同时满足三个属性情况是无法实现的, 即中间交集处. 而满足两个属性的系统模型有如下三个:
187182

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
191186

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 机制, 能保证状态能达到最终一致, 避免出现状态不一致, 从而支持部分节点不可用
193189

194-
因此, 选择了网络分区, 就需要在高可用和强一致性之间作取舍, 而系统设计即是在基于不同的场景, 作出不同的取舍.
190+
因此, 选择了网络分区, 就需要在高可用和强一致性之间作取舍, 而系统设计即是在基于不同的场景, 作出不同的取舍.
195191

196-
同样, 强一致性和高性能也存在矛盾, 要保证强一致性, 自然需要节点之间通信达到共识, 这自然会拉高延迟, 这也要系统设计者作出取舍.
192+
同样, 强一致性和高性能也存在矛盾, 要保证强一致性, 自然需要节点之间通信达到共识, 这自然会拉高延迟, 这也要系统设计者作出取舍.
197193

198194

199195
### <span class="section-num">3.5</span> Consistency model {#consistency-model}
@@ -314,7 +310,7 @@ Time is a source of order. 时间可以解析成以下三种形式:
314310
不过, 工程实践中的确有程序使用这样的模型:
315311

316312
- 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, 保证时间同步的条件下, 又消除了时间漂移的最坏情况.
318314

319315

320316
#### <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` 个节点的分布式系
389385

390386
使用全序关系也是可能的, 但是为了协调全局顺序, 会付出高昂的性能代价.
391387

392-
如果你对时间_顺序_同步性要求没有那么高, 你可以获得相当的性能提升. 那么, 什么时候需要顺序来保证正确性呢? 后面提到 `CALM定理` 会为你提供答案.
388+
如果你对时间/顺序/同步性要求没有那么高, 你可以获得相当的性能提升. 那么, 什么时候需要顺序来保证正确性呢? 后面提到 `CALM定理` 会为你提供答案.
393389

394390
说到底, 又是取舍的话题, 下面的情景只存在电影中:
395391

@@ -479,7 +475,7 @@ Vector clock是Lamport clock 的扩展, 对于有 `N` 个节点的分布式系
479475
- synchronous primary/backup replication
480476
- asynchronous primary/backup replication
481477

482-
前者需要两条消息(update + ack), 而后者只需要一条消息(update). 主_从复制非常常见, MySQL 复制使用的就是主_从复制, MySQL 支持三种模式复制:
478+
前者需要两条消息(update + ack), 而后者只需要一条消息(update). 主/从复制非常常见, MySQL 复制使用的就是主/从复制, MySQL 支持三种模式复制:
483479

484480
- 同步: 客户端请求, 先写入主机, 然后同步到所有备机, 成功后响应客户端, 在此之间, 阻塞客户端(性能最差)
485481
- 异步: 客户端请求, 先写入主机, 然后响应客户端, 再同步备机(同步备机前主机挂, 则丢失数据)
@@ -651,4 +647,4 @@ reported by the followers)
651647

652648
## <span class="section-num">6</span> 5. Replication: Accepting Diveragence {#5-dot-replication-accepting-diveragence}
653649

654-
笔记待续
650+
笔记待续

0 commit comments

Comments
 (0)