Satellite server distributed system clock (NTP server) set up and design

Satellite server distributed system clock (NTP server) set up and design

Satellite server distributed system clock (NTP server) set up and design

This article provides support and raw materials from the Anhui Beijing-Technology - may refer to more elaborate micro ♥ ahjzsz 

Distributed systems are defined by Tanenbaum, "Distributed Systems is a group of independent computers, in the" Distributed Systems - Principles and examples "in the user as a single, coherent system emerge."

Block chain by building global distributed systems, data storage and try new decentralized organizational structure to achieve.

First, locate the distributed system is mainly to scalability, availability and location. Block chain is no exception. Geographical scalability, the value stored in a global network / area information protection, including tamper-resistant / zero downtime in the non-availability of a centralized architecture. Implemented in the block in the future are to use these distributed systems.

0. Contents

X. block chain and distributed systems

1. Introduction (synchronous and overall process overview)

2. Clock synchronization

2-1. Physical clock (clock and clock offset)

2-2. Clock synchronization algorithm (Network Time Protocol (NTP) / Berkeley algorithm)

3. Logic clock

3-1. Lamport's logical clock (totally ordered multicast)

3-2. Vector clock (causal order multicast)

4. Exclusive Control

4-1. Focus algorithm

4-2. Dispersal algorithm

4-3. Distributed Algorithms

5. Election Algorithm

5-1. Bully algorithm

5-2. Loop algorithm

6. strand and prevents synchronization of a distributed system

6-1. And a clock synchronization block chain (chain block and a physical / logical clock)

6-2. And a block chain exclusive control algorithm (PoW · PoS · BFT in the exclusive control algorithm)

6-3. Chain block and leader election algorithm (PoW · PoS · BFT leader in the selection algorithm)

1. Introduction (synchronous and overall process overview)

And centralized systems, distributed systems on time to agree is not easy.

In the former case, the order may be determined based on the relationship absolute global shared clock, but in the latter case, the error due to the clock value and the corresponding time, it is difficult to share absolute time.

However, the order absolute time is not absolutely necessary, if the order is relatively fixed, usually sufficient.

Herein, the synchronization between nodes will be explained in the following order.

Clock synchronization How did it happen?

Vector using the logical clock and clock relative ranking method

About Distributed Systems consistency exclusion control algorithm

Leadership election algorithm on a distributed system

2. Clock synchronization

2-1. Physical clock

Clock and clock skew

Most computers have a retention time circuit , such a device is called "clock." This is based on the frequency of vibration , the vibration type by the crystal, a cutting method, and the tension increases the stress at the defined precisely machined quartz.

Although this frequency is fairly stable, but can not guarantee that all crystals of different computers to run at exactly the same frequency. Synchronization time difference caused thereby is called clock skew.

In this case, particularly in the real-time system, how to make multiple clock and clock synchronization reality and how to synchronize clocks is a problem.

The first time in the real world based on the mean solar seconds, but now the transition time is defined as 9,192,631,770 cesium 133 times 1 second, and the definition of the International Atomic Time and Universal Coordinated Time (UTC). In order to provide an accurate UTC time to those in need, and the time provided using WWV ± 10 millisecond accuracy.

2-2. Clock synchronization algorithm

However, most machines do not WWV receiver. Therefore, each machine will take time and management tracking algorithm so that all machines can be synchronized time.

Incidentally, to determine whether the error needs to be resynchronized, i.e. clock offset, measured as follows.

The number of interrupts (ticks) H is defined for each machine counts per second due to the crystal resonator, and C represents that the value of the clock. Provided Cp (t) represents the value of the machine clock, when the UTC time as t.

If p is defined as the amount of deviation is defined to allow the maximum clock drift rate, it is assumed to operate within the following ranges.

1-p 《= dC/dt 《= 1+p

That is, after the previous sync from the start after At seconds, the clock up to two separate 2pΔt.

When the deviation is greater than & ensure that no operation is performed during, each must be at least & / 2p resynchronization software.

Network Time Protocol (NTP)

Is common in many of the agreements, [Cris Ti AN, 1989] first proposed method is a method for the server to communicate with customers. Since the time server having a WWV receiver or having an accurate clock, so it can provide the current time. In communicating with the server, it is important that the propagation delay of the delay time of the report message, but by estimating the delay, where the error can be minimized. Currently, it is known NTP accuracy can be achieved in the range of 1 to 50 ms.

Berkeley algorithm

In many algorithms such as the NTP time server is passive and only answer queries. On the other hand, in Berkeley algorithm, the time server receives the time held each participating node, based on the average and further change its own time. When the time value does not have to have a relationship with the real world, it is easy to agree on the same current time, and it is this algorithm is effective.

3. Logic clock

So far, although we describe a relatively synchronous clock and the actual clock time synchronization as an absolute reference method, but is usually performed only on. Here, the logic of a clock for determining the relative order.

3-1. Lamport clock logic

In order to clock synchronization logic, Lamport defined happen-before relation is named. A → b represents the expression "a occurs before b", which means that the event occurs first, and then all processes agree that the event will occur b. Prior to happen - it can be observed in the following two cases directly to the relationship.

If a and b are the same process occurs before the event and a b, then a → b is true.

2. If the event is a message sent by one process, and b is the event message is received by another process, then a → b is true. You can not receive the message prior to sending the message, even if the message also requires a finite non-zero time.

Because a relationship before the relationship is in transition, if a → b and b → c, it can be shown that a → c. If the event x, y appear in different processes do not exchange messages, then x → y and y → x is not true, and these events are considered to be concurrent. (Unknown relationship happened before.)

Using logical clock, to measure the relative allocation of all the time by the same process for each event time a C (a). If the time values ​​are a → b, by adding the correction value to the time thereof, such that C (a) "C (b). Time by assigning values ​​shown in FIG follows, a relationship can be grasped before.

 

Lamport clock logic, if a → b, it can be shown that C (a) "C (b), if C (a)" C (b) does not necessarily hold the a → b. In other words, a → b is C (a) "C (b) the requirement, and is not a sufficient condition. Lamport clock logic adds improvements, it is a vector clock, that can meet the necessary and sufficient conditions.

Totally ordered multicast

For more information, see the contents of a "distributed system consistency" in an article

In many cases, it is necessary to perform a complete and orderly multicast between duplicate copies. In other words, all messages are to be passed to each recipient in the same order. Lamport clock logic may be used to achieve complete ordered multicast in a fully distributed system.

When the process receives a message, it will be based on the time stamp into the local order queue. Multicast recipient to confirm another process. If you adjust the local clock in accordance with the Lamport algorithm, all have the same process is actually a copy of the local queue. Only when the message at the head of the queue is confirmed and all other processes, the process can have a queue of messages to the application is running, therefore, all messages are transmitted to everywhere in the same order. In other words, we have established a fully ordered multicast.

3-2. Clock vector

Use vector clocks, Lamport logical clock can not grasp grasp of causality. Suppose the event clock is the VC a vector (a), the following step is performed, such that a → b becomes VC (a) "VC (b) the necessary and sufficient conditions.

Before sending a message via the network, the nodes Pi VCi vector clock [i] was added 1, or operation of some internal events.

2. If the process to send a message m to Pi Pj, Pi is performed after a step before the m vector stamp TS (m) is set equal to VCi.

3. Upon receiving the message m, the process Pj step 1, the message distributed application, and each k updates its own clock vector, as follows: VCj [k] ← max {VCj [k], ts (m) [k]}.

 

Multicast causation

By using the vector clock, slightly weaker than the above may be implemented fully ordered causal multicast ordered multicast.

By comparing the values ​​of the vector clock and master relationship occurs before, for a specific event x, other events may be classified as past events, concurrent events and future events. For example, In the figure, when the event as a reference point d, past events are a, b, c, i, is concurrent events j, l, m, future events is f, g, h.

In this case, assuming a causal ordered multicast past events and the causal sequence of events in which all causal relations to be consistent in all the process, but on the order of concurrent events is irrelevant. In this way, different logical Lamport clock, the clock can be used to control the vector causality.

4. Exclusive Control

Concurrent operation and collaboration between multiple processes operate distributed systems is essential, but when in order to ensure exclusive access to a resource, not in an inconsistent state in order to access the same resource simultaneously by multiple processes, require distributed exclusively algorithm.

Distributed exclusive control algorithm can be divided into two types.

Token-based solutions

Based rights approach

In the Token based solution, it is easy to avoid Starva TI ON (do not allow access to the resource for a long time) and dead locks (Processes wait for each other's progress). A representative example is the Token Ring algorithm. However, when the process of holding an extraordinary stop and Token Token is lost, it is necessary only to generate a new Token, this complexity is a serious drawback.

Many other decentralized control algorithm based on exclusive rights approach, and there are many different ways to obtain permission, we will be separately explained in detail.

4-1 Centralized algorithm

By functional analog single-processor system, you can easily access a single distributed system exclusive control. In a centralized algorithm, a process is designated as the coordinator, and when a process accesses a shared resource, the request message is sent to the coordinator in order to obtain permission. If other processes not access the shared resources, the coordinator returns a permission response, and after receiving the reply, the requesting process to execute the process.

It is easy to see that the algorithm ensures exclusive access to resources, but it has serious drawbacks single point of failure. While this may be a performance bottleneck in large systems, but the benefits of this simplicity can still make up for these shortcomings.

4-2. Dispersal algorithm

Assuming that all will be repeated n times. In the dispersal algorithm, when the process of accessing resources, require the approval of the majority of m "n / 2. If you get most of the approval, the process of obtaining licenses and can be treated.

Although the program addresses the single points of failure centralized algorithm, but if there are too many nodes attempt to access, there is another problem that the node can not get enough votes can not obtain sufficient performance.

4-3. Distributed Algorithms

In this algorithm, the sequence of events on the assumption that all systems can be defined as complete and orderly relations. As the base, use Lamport clock logic described in the previous chapter, and that no message will be lost.

当进程尝试访问共享资源时,它会创建一条消息,其中包含资源名称,自己的进程号和当前逻辑时钟,并将其发送给所有其他进程。当接收到该请求消息时,根据其自身状态执行以下操作。

1. 如果收件人未访问该资源且未尝试访问该资源,则收件人会向发件人返回“确定”消息。

2. 如果收件人已在访问资源,请不要回复并执行排队请求。

3. 如果收件人正在尝试访问资源但尚未完成,请将输入消息中的时间戳与发送给其他进程的消息中的时间戳进行比较,并将较低的一个作为获胜者。如果收到的消息具有小的时间戳,则收件人返回OK消息。如果自己的消息具有较小的时间戳,则接收方将不会将输入消息排队。

显然,如果它不像process1或2那样冲突,这个算法就能正常工作。即使在冲突的情况下,也只建立了唯一一个进程可以访问的条件。

与集中式算法一样,该算法可以保证独占控制,不会出现死锁或饥饿。 此外,没有单点故障。 尽管如此,单点故障被故障n位置特征所取代。 它可以通过回复权限或拒绝权限并引入超时来解决,但也会出现其他问题,例如需要多播通信原语。 不幸的是,目前尚未设计出超越集中式算法的分布式算法,并且仍在研究中。

当比较各个算法时,变为如下。

 

5.领导者选举算法

许多分布式算法需要一个特殊的过程,它具有领导者作为协调者或发起者的角色。哪个过程是领导者,唯一过程是否可以成为领导者是一个重要问题,研究人员在过去几十年中一直在努力。

5–1. 欺负算法

当协调员失败并且任何进程P注意到该情况时,P根据以下过程激活选举。

· P向所有具有比其自身更高数值的进程发送ELECTION消息。

· 如果没有人回复,P将赢得选举并成为协调员。

· 如果来自具有高于P的数值的过程的答案,则将替换它。 P的工作结束了。

使用该算法,可以唯一地确定协调器。但是,该算法需要大量的消息和数据流量,可以说是冗余的。作为替代方案,存在环算法。

5–2. 环算法

与一般环算法不同,该算法不使用Token。发现协调器不工作的任何进程构造一个包含其自己的进程号的ELECTION消息,并将该消息发送给其后继者(环网中的下一个节点)。如果继任者失败,请跳过。如果没有比您更高的数值的节点,您的消息将仍然返回给您自己的进程号,因此它将被指定为协调员。

在该算法中,执行具有减少数量的消息的领导者选举,但是还可以通过将消息的目的地设置到两个相邻节点来实现具有较少量数据流量的算法。

6.阻止链和同步作为分布式系统

因此,在作为分布式系统之一的块链中,进程之间的同步如何发生?

6–1. 区块链和时钟同步

块链和逻辑时钟

首先,考虑是否可以使用区块链中的物理时钟来掌握绝对时间关系。如第2章所述,参与网络的每个节点并不总是保持正确的物理时钟,并且应该存在时钟偏差。由于比特币区块链的平均生成时间是10分钟,因此认为即使一定程度的大时钟偏差也是可接受的。然而,当节点散布在世界各地时难以同步各个物理时钟,并且还可能存在伪装时钟的节点。通过引入网络时间协议(NTP)来重新同步节点之间的正确时间是一项困难的技术。

区块链和逻辑时钟

因此,准备逻辑时钟而不是物理时钟是切合实际的。实际上,通过在块中加入时间标记,可以制备出与Lamport逻辑时钟非常相似的机制。

如[比特币:点对点电子现金系统Satoshi Nakamoto]中所述,对作为矿工的区块执行写操作的每个节点本身具有作为时间戳服务器的角色。每个时间戳通过在其哈希中包含前一个时间戳来形成链。但是,无法保证这些节点保持正确的物理时钟。时间戳的数值,即每个事务的顺序和时间相对模糊。

由于时钟的这种模糊性,有可能会进行双重付款。但是,在比特币区块链中,只有最长的链是合法的,在次要验证后丢弃不正确的交易。因此,区块的顺序随着时间的流逝唯一确定。随着每个时间戳的增加,前一个时间戳被加强。

总之,在区块链中的模糊时间戳下,事务的顺序一致性是不准确的。然而,利用链式连接的简单机制,每个交易的发生前关系随着时间的推移而建立。此外,还有一种激励结构,以便矿工转移到良好,交易不一致的顺序不会发生。

可以说,实现类似于Lamport的逻辑时钟的时钟同步方法,因为事务之间的相对顺序关系,即发生在之前的关系变得更清楚。

对于大多数交易,没有因果关系,因此如果您引入向量时钟并采用因果关系排序的概念,则可以极大地放松订单关系的约束。然而,在区块链中,由于结构本身默认共享所有块的顺序关系,所以保持总排序(相对于在一段时间之后的块)。

6–2. 区块链和独占控制算法

即使在作为分布式系统的区块链中,也需要排除控制。在区块链网络中,每个节点并行地异步操作。此时,要共享的区块链本身的信息不应该不一致。

PoW·PoS中的独占控制算法

如第4章所述,分布式排他控制算法可分为以下两种类型。

· 基于Token的解决方案

· 基于权限的解决方案

PoW和PoS是基于权限的,其中,可以说它是类似于分布式算法的机制。那么,您什么时候获得访问资源的权限?是的,就在你找到一个随机数时。

在PoW中,只有当找到在哈希值后跟0后跟n为0的随机数时,才可以执行有效的新块写操作。执行操作的矿工将其广播给所有矿工并分享。

通常,当节点找到一个nonce并创建一个比他自己更早的块时,minor会同步该信息并移动以搜索下一个nonce值。这是因为如果您使用最长链被认为合法的规则搜索下一个nonce值,它们可以获得更多利润。尽管PoS优先为具有较大硬币持有量的人提供资源访问,但基本排除控制算法结构也类似于分布式算法。

但是,严格来说,不执行排除控制。这是为了在公共时间内同步并形成共识10分钟,直到下一个区块为止。当两个或更多个节点同时找到随机数值时,写入操作以非独占状态执行。此时,由于只有最长的链被认为是合法的,因此区块链网络中的信息与时间的流逝保持一致。叉子发生的一个问题是因为没有执行严格的排他控制而且没有确认最终结果。

BFT类型的独占控制算法

另一方面,通过BFT类型,基于许可的分散算法执行排他控制。该算法解决了分叉和终结问题,这是PoW中与分布式算法类似的问题。

在BFT类型中,只有一个名为Proposer,Orderer等的节点有权生成新区块。创建区块时,您可以从所有参与节点收集投票,获得超过2/3的同意,您才有权创建新块。此时,有必要同意超过2/3而不是多数的原因是处理拜占庭故障,有关此问题的详细信息在“分布式系统中的容错”一文中有所描述。

在BFT类型算法中,与PoW等不同,只有一个节点可以获得对区块链的独占访问权限,因此不会立即确定fork和finality。但是,任何人都可以作为矿工参与网络的财产往往会丢失。

6–3. 区块链和领导者选择算法

PoW,PoS和领导者选择算法

区块链上的领导者选择算法类似于独占控制算法的机制。在比特币中,用于选举领导者的算法,即,新创建块的节点是PoW。

PoW允许添加一个块作为一个好的领导者,为比特币网络提供有计算复杂性和发现nonce的节点。每个成为领导者的矿工都会尝试为比特币网络做出贡献,因为更容易早期同步到首先发现现时的节点并开始搜索下一个块的现时值更有可能获得奖励。尽管存在链条完全由硬叉分支的问题,但是通过基于博弈论准备非常简单的激励结构,在块链网络中实现作为分布式系统的同步。

在以太坊的情况下,由于块生成的时间很短,因此倾向于发生更多的分叉。关于这一点,通过采用unkle块的概念,我们实现了一种结构,即使产生不合法的链条也会给予一定的奖励。

将来引入未来的PoS允许优先生成具有大硬币保持量的节点的块作为引导者。这是一种解决/改善PoW中必要电量变得巨大且易受51%攻击的问题的算法。这是一种基于博弈论的选举算法,如果一个节点持有大量硬币,就不会采取破坏网络等恶意行为。

BFT和领导者选择算法

BFT类型算法的问题在于如何选择将投票给块生成的领导者作为Proposer或Orderer。

在PBFT采取的HyperLedger当中,原为可信赖的机构才会注册为Orderer。 但这是集中式的领导者选择方法,与分布式系统存在着明显的区别。

Tendermint协议当中,领导者以循环方式被选出,以通过与不同验证者的轮换交替来提出建议。 此时,领导候选者是基于PoS,并且可以说是可以在分布式系统中实现领导者选择的算法之一。

 

Guess you like

Origin www.cnblogs.com/yfcs999/p/1232jsfs.html