Скачать презентацию Synchronization http net pku edu cn course cs 501 2011 Hongfei Скачать презентацию Synchronization http net pku edu cn course cs 501 2011 Hongfei

010031f2dc979d2ef928a702f565a9d4.ppt

  • Количество слайдов: 81

Synchronization http: //net. pku. edu. cn/~course/cs 501/2011 Hongfei Yan School of EECS, Peking University Synchronization http: //net. pku. edu. cn/~course/cs 501/2011 Hongfei Yan School of EECS, Peking University 4/18/2011

Contents 01: 02: 03: 04: 05: 06: 07: 08: 09: 10: 11: 12: 13: Contents 01: 02: 03: 04: 05: 06: 07: 08: 09: 10: 11: 12: 13: Introduction Architectures Processes Communication Naming Synchronization Consistency & Replication Fault Tolerance Security Distributed Object-Based Systems Distributed File Systems Distributed Web-Based Systems Distributed Coordination-Based Systems 2/N

Outline 6. 1 6. 2 6. 3 6. 4 6. 5 Clock Synchronization (++) Outline 6. 1 6. 2 6. 3 6. 4 6. 5 Clock Synchronization (++) Logical Clocks (++) Mutual Exclusion Global Positioning of nodes Election Algorithms

6. 1 Clock Synchronization n Physical Clocks Global Positioning System (++) Clock Synchronization Algorithms 6. 1 Clock Synchronization n Physical Clocks Global Positioning System (++) Clock Synchronization Algorithms (++)

Why is it important ? n Need to measure accurately n n Algorithms depending Why is it important ? n Need to measure accurately n n Algorithms depending on n E. g. , auditing in e-commerce E. g. , consistency, make Correctness of distributed systems frequently hinges upon the satisfaction of global system invariants. n n E. g. , Absence of deadlocks Write access to a distributed database never granted to more than one process the sum of all account debits and ATM payments in an electronic cash system is zero Objects are only subject to garbage collection when no further reference to them exists

E. g. , UNIX make program n When each machine has its own clock, E. g. , UNIX make program n When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time.

时间简史 n 人类生活有紧密联系的太阳的运动是比较均匀 n n 天文计量,自从17世纪机械钟表发明. GMT (Greenwich Mean Time) n n 地球自传是一天,公转是一年 太阳到达天空中它出现的最高点时称为中天 时间简史 n 人类生活有紧密联系的太阳的运动是比较均匀 n n 天文计量,自从17世纪机械钟表发明. GMT (Greenwich Mean Time) n n 地球自传是一天,公转是一年 太阳到达天空中它出现的最高点时称为中天 两次连续的太阳中天之间的时间称为一个太阳日 每天有24小时,每小时有3600秒, 1/86400个太阳日是太阳秒 物理计量,20世纪 40年代 n n n 1秒是铯 133原子作 9, 192, 631, 770次跃迁所用的时间 BIH (Bureau International de l’Heure)将这些值平均起来产生国际 原子时间,简称为TAI (International Atomic Time) TAI和太阳秒计时之间的差增加到 800毫秒时使用一次闰秒,修正后 的时间系统称作统一协调时间,简称UTC (Universal Coordinated Time)

Physical Clocks n A high-frequency oscillator, counter, and holding register n n n Counter Physical Clocks n A high-frequency oscillator, counter, and holding register n n n Counter decrements on each oscillation, generates a “tick” and is reset from the holding register when it goes to 0. On a network, clocks will differ: “skew”. Two problems: n n How do we synchronize multiple clocks to the “real” time? How do we synchronize with each other?

Measuring Time n n n How long is a second? How long is a Measuring Time n n n How long is a second? How long is a day? One solar day is 86, 400 solar seconds. n Some variation in the rotational speed of the earth: mean solar second.

A Solar Day n Computation of the mean solar day. A Solar Day n Computation of the mean solar day.

Changes n Big problem: the earth’s rotation is slowing. n n Is this acceptable Changes n Big problem: the earth’s rotation is slowing. n n Is this acceptable for science and engineering? n n Use physical clocks not tied to the Earth: TAI. Hm…but then there are more seconds in a day! n n Seconds are getting longer. What are leap years for? Leap seconds are periodically added.

Leap Seconds n n TAI seconds are of constant length, unlike solar seconds. Leap Leap Seconds n n TAI seconds are of constant length, unlike solar seconds. Leap seconds are introduced when necessary to keep in phase with the sun. UTC is TAI with leap seconds.

Time Standards n International Atomic Time n n TAI is a physical time standard Time Standards n International Atomic Time n n TAI is a physical time standard that defines the second as the duration of 9, 192, 631, 770 periods of the radiation of a specified transition of the cesium atom 133. TAI is a chronoscopic timescale, i. e, a timescale without any discontinuities. It defines the epoch, the origin of time measurement, as January 1, 1958 at 00: 00 hours, and continuously increases the counter as time progresses Universal Coordinated Time (UTC) n UTC is an astronomical time standard that is the basis for the time on the "wall clock". In 1972 it was internationally agreed that the duration of the second should conform to the TAI stand, but that the number of seconds in an hour will have to be occasionally modified by inserting a leap second into UTC to maintain synchrony between the wall clock time and the astronomical phenomena, like day and night.

Physical Clocks (1/3) n n Problem: Sometimes we simply need the exact time, not Physical Clocks (1/3) n n Problem: Sometimes we simply need the exact time, not just an ordering. Solution: Universal Coordinated Time (UTC): n n Based on the number of transitions per second of the cesium 133 atom (pretty accurate). At present, the real time is taken as the average of some 50 cesium-clocks around the world. Introduces a leap second from time to compensate that days are getting longer. UTC is broadcast through short wave radio and satellite. Satellites can give an accuracy of about ± 0. 5 ms.

Physical Clocks (2/3) n n Problem: Suppose we have a distributed system with a Physical Clocks (2/3) n n Problem: Suppose we have a distributed system with a UTC-receiver somewhere in it => we still have to distribute its time to each machine. Basic principle: n n n Every machine has a timer that generates an interrupt H times per second. There is a clock in machine p that ticks on each timer interrupt. Denote the value of that clock by Cp(t) , where t is UTC time. Ideally, we have that for each machine p, Cp(t) = t, or, in other words, d. C/dt = 1.

Physical Clocks (3/3) n n In practice: 1 – ρ <= d. C/dt <= Physical Clocks (3/3) n n In practice: 1 – ρ <= d. C/dt <= 1 + ρ Goal: Never let two clocks in any system differ by more thanδ time units => synchronize at least every δ/(2ρ) seconds.

6. 1 Clock Synchronization n Physical Clocks Global Positioning System (++) Clock Synchronization Algorithms 6. 1 Clock Synchronization n Physical Clocks Global Positioning System (++) Clock Synchronization Algorithms (++)

Global Positioning System (1/2) n n Basic idea: You can get an accurate account Global Positioning System (1/2) n n Basic idea: You can get an accurate account of the time as a side-effect of GPS. Principle: Problem: Assuming that the clocks of the satellites are accurate and synchronized: n n It takes a while before a signal reaches the receiver The receiver’s clock is definitely out of synch with the satellite

Global Positioning System (2/2) n n n Δr is unknown deviation of the receiver’s Global Positioning System (2/2) n n n Δr is unknown deviation of the receiver’s clock. xr, yr, zr are unknown coordinates of the receiver. Ti is timestamp on a message from satellite i Δi = (Tnow − Ti) + Δr is measured delay of the message sent by satellite i. Measured distance to satellite i: c × Δi (c is speed of light) Real distance is di =cΔi−cΔr =sqrt ((xi − xr)2 + (yi − yr)2 + (zi − zr)2) 4 satellites => 4 equations in 4 unknowns (with Δr as one of them)

6. 1 Clock Synchronization n Physical Clocks Global Positioning System (++) Clock Synchronization Algorithms 6. 1 Clock Synchronization n Physical Clocks Global Positioning System (++) Clock Synchronization Algorithms (++)

Clock Synchronization n Internal: n n processors run clock sync protocol, e. g. : Clock Synchronization n Internal: n n processors run clock sync protocol, e. g. : broadcasting their clock readings each processor receives set of values from others (may differ) algorithm would pick a synchronized value from the set External: n n satellite system launched by military in early 1990's, became public and inexpensive can think of satellites broadcasting the time small radio receiver picks up signals from three satellites and triangulates to determine position same computation also yields extremely accurate clock (milliseconds)

Clock Synchronization Algorithms n Cristian’s Algorithm (1989) n n n The time server is Clock Synchronization Algorithms n Cristian’s Algorithm (1989) n n n The time server is passive E. g. , The Network Time Protocol The Berkeley Algorithm (1989) n The time server is active

Cristian's Algorithm (1/2) n Getting the current time from a time server. Cristian's Algorithm (1/2) n Getting the current time from a time server.

Cristian's Algorithm (2/2) n Two problems n n One major, time must never run Cristian's Algorithm (2/2) n Two problems n n One major, time must never run backward n When slowing down, the interrupt routine adds less msec to the time until the correction has been made n Be advanced gradually by adding more msec at each interrupt One minor, it takes a nonzero amount of time for the time server’s replay to get back to the sender n (T 1 – T 0) / 2 n (T 1 – T 0 – I )/2 n A series of measurement to be averaged n The message that came back fastest

Network Time Protocol (RFC 1305) n NTP是用来使计算机时间同步化的一种协议, n n n 它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供 高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒), 且可介由加密确认的方式来防止恶毒的协议攻击。 NTP如何 Network Time Protocol (RFC 1305) n NTP是用来使计算机时间同步化的一种协议, n n n 它可以使计算机对其服务器或时钟源(如石英钟,GPS等等)做同步化,它可以提供 高精准度的时间校正(LAN上与标准间差小于1毫秒,WAN上几十毫秒), 且可介由加密确认的方式来防止恶毒的协议攻击。 NTP如何 作 n n n NTP获得UTC的时间来源可以是原子钟、天文台、卫星,也可以从Internet上获取。 n 时间按NTP服务器的等级传播。按照离外部UTC 源的远近将所有服务器归入不 同的Stratun(层)中。 n Stratum-1在顶层,有外部UTC接入,而Stratum-2则从Stratum-1获取时间, Stratum-3从Stratum-2获取时间,以此类推,但Stratum层的总数限制在 15以内。 n 所有这些服务器在逻辑上形成阶梯式的架构相互连接,而Stratum-1的时间服务 器是整个系统的基础。 计算机主机一般同多个时间服务器连接, n 利用统计学的算法过滤来自不同服务器的时间,以选择最佳的路径和来源来校 正主机时间。 n 即使主机在长时间无法与某一时间服务器相联系的情况下,NTP服务依然有效 运转。 为防止对时间服务器的恶意破坏,NTP使用了识别(Authentication)机制,检查来对 时的信息是否是真正来自所宣称的服务器并检查资料的返回路径,以提供对抗干扰 的保护机制。

NTP Architecture 1 2 3 3 • Arrows denote synchronization control, numbers denote strata. NTP Architecture 1 2 3 3 • Arrows denote synchronization control, numbers denote strata. • Reconfigure when servers become unreachable

Synchronization Measures of NTP n Multicast mode n n Procedure-call mode n n n Synchronization Measures of NTP n Multicast mode n n Procedure-call mode n n n Intend for use on a high speed LAN Assuming a small delay Low accuracy but efficient Similar to Christian’s Higher accuracy than multicast Symmetric mode n The highest accuracy

Getting the current time from a time server n n n A can estimate Getting the current time from a time server n n n A can estimate its offset relative to B as θ = T 3 + [(T 2 – T 1) + (T 4 – T 3)]/2 – T 4 = [(T 2 - T 1) + (T 3 – T 4)]/2 For the delay, δ = [(T 4 - T 1) + (T 3 – T 2)]/2

Symmetric Mode Sync. Implementation n NTP servers retain 8 most recent pairs < θi, Symmetric Mode Sync. Implementation n NTP servers retain 8 most recent pairs < θi, δi> The value θi of that corresponds to the minimum value δi is chosen to estimate θ A NTP server exchanges with several peers in addition to with parent n Peers with lower stratum numbers are favored n Peers with the lowest synchronization dispersion are favored n n The timekeeping quality at a particular peer is determined by a sum of weighted offset differences, called the dispersion. The total dispersion to the root due to all causes is called the synchronization dispersion.

The Berkeley Algorithm a) b) c) The time daemon asks all the other machines The Berkeley Algorithm a) b) c) The time daemon asks all the other machines for their clock values The machines answer The time daemon tells everyone how to adjust their clock

Outline 6. 1 6. 2 6. 3 6. 4 6. 5 Clock Synchronization (++) Outline 6. 1 6. 2 6. 3 6. 4 6. 5 Clock Synchronization (++) Logical Clocks (++) Mutual Exclusion Global Positioning of nodes Election Algorithms

6. 2 Logical Clocks n n Lamport’s Logical Clocks (++) Vector Clocks (++) 6. 2 Logical Clocks n n Lamport’s Logical Clocks (++) Vector Clocks (++)

Happen-Before (HB) Relation n n Problem: We first need to introduce a notion of Happen-Before (HB) Relation n n Problem: We first need to introduce a notion of ordering before we can order anything. denotes HB relation n HB 1: If process pi : e comes before e`, then e e` n HB 2: For any message m, n n HB 3: IF e, e’ and e” are events such that n n send(m) receive(m) e e` and e` e”, then e e” Note: this introduces a partial ordering of events in a system with concurrently operating processes.

Happen-before relation n Example n n a || e Shortcomings n n Not suitable Happen-before relation n Example n n a || e Shortcomings n n Not suitable to processes collaboration that does not involve messages transmission Capture potential causal ordering

Events occurring at three processes Events occurring at three processes

Logical Clocks (1/2) n n Problem: How do we maintain a global view on Logical Clocks (1/2) n n Problem: How do we maintain a global view on the system’s behavior that is consistent with the happened before relation? Solution: attach a timestamp C(e) to each event e, satisfying the following properties: n n n P 1: If a and b are two events in the same process, and a->b, then we demand that C(a) < C(b). P 2: If a corresponds to sending a message m, and b to the receipt of that message, then also C(a) < C(b). Problem: How to attach a timestamp to an event when there’s no global clock => maintain a consistent set of logical clocks, one per process.

Logical Clocks (2/2) n Solution: Each process Pi maintains a local counter Ci and Logical Clocks (2/2) n Solution: Each process Pi maintains a local counter Ci and adjusts this counter according to the following rules: n n n 1: For any two successive events that take place within Pi, Ci is incremented by 1. 2: Each time a message m is sent by process Pi, the message receives a timestamp ts(m) = Ci. 3: Whenever a message m is received by a process Pj, Pj adjusts its local counter Cj to max{Cj, ts(m)}; then executes step 1 before passing m to the application. Property P 1 is satisfied by (1); Property P 2 by (2) and (3). Note: it can still occur that two events happen at the same time. Avoid this by breaking ties through process IDs.

Logical Clocks - Example n Note: Adjustments take place in the middleware layer: Logical Clocks - Example n Note: Adjustments take place in the middleware layer:

Example: Totally Ordered Multicasting (1/2) n Problem: We sometimes need to guarantee that concurrent Example: Totally Ordered Multicasting (1/2) n Problem: We sometimes need to guarantee that concurrent updates on a replicated database are seen in the same order everywhere: n n P 1 adds $100 to an account (initial value: $1000) P 2 increments account by 1% There are two replicas Result: in absence of proper synchronization: replica #1 $1111, while replica #2 $1110.

Example: Totally Ordered Multicasting (2/2) n n n Solution: Process Pi sends timestamped message Example: Totally Ordered Multicasting (2/2) n n n Solution: Process Pi sends timestamped message msgi to all others. The message itself is put in a local queuei Any incoming message Pj is queued in queuej, according to its timestamp, and acknowledged to every other process. Pj passes a message msgi to its application if: (1) msgi is at the head of queuej (2) And has been acknowledged by each other process. n Note: all messages are delivered in the same order to each receiver. In addition, we assume that messages from the same sender are received in the order they were sent, and that no message are lost.

6. 2 Logical Clocks n n Lamport’s Logical Clocks Vector Clocks 6. 2 Logical Clocks n n Lamport’s Logical Clocks Vector Clocks

Vector Clocks (1/2) n Observation: Lamport’s clocks do not guarantee that if C(a) < Vector Clocks (1/2) n Observation: Lamport’s clocks do not guarantee that if C(a) < C(b) that a causally preceded b: n Observation: n n Event a: m 1 is received at T = 16. Event b: m 2 is sent at T = 20. We cannot conclude that a causally precedes b. The problem is that Lamport clocks do not capture causality. Causality can be captured by means of vector clocks.

Vector Clocks (2/2) n Solution: n n n Each process Pi has an array Vector Clocks (2/2) n Solution: n n n Each process Pi has an array VCi[1. . n], where VCi[j] denotes the number of events that process Pi knows have taken place at process Pj. When Pi sends a message m, it adds 1 to VCi[i], and sends VCi along with m as vector timestamp vt(m). Result: upon arrival, recipient knows Pi’s timestamp. When a process Pj delivers a message m that it received from Pi with vector timestamp ts(m), it (1) updates each VCj[k] to max{VCj[k], ts(m)[k]} (2) increments VCj[j] by 1.

Causally Ordered Multicasting (1/2) n n Observation: We can now ensure that a message Causally Ordered Multicasting (1/2) n n Observation: We can now ensure that a message is delivered only if all causally preceding messages have already been delivered. Adjustment: Pi increments VCi[i] only when sending a message, and Pj “adjusts” VCj when receiving a message (i. e. , effectively does not change VCj[j]). Pj postpones delivery of m until: • ts(m)[i] = VCj[i] + 1. • ts(m)[k] ≤ VCj[k] for k ≠ i.

Causally Ordered Multicasting (2/2) n n Example 1: Example 2: Take VC 2 = Causally Ordered Multicasting (2/2) n n Example 1: Example 2: Take VC 2 = [0, 2, 2], ts(m) = [1, 3, 0] from P 0. What information does P 2 have, and what will it do when receiving m (from P 0)?

n Observation: n n n A distributed computation consists of a set of processes n Observation: n n n A distributed computation consists of a set of processes that cooperate to achieve a common goal. A main characteristic of these computations is that the processes do not already share a common global memory and that they communicate only by exchanging messages over a communication network. Asynchronous distributed system model: n n n http: //net. pku. edu. cn/~course/cs 501/2008/reading/a_tour_vc. html message transfer delays are finite yet unpredictable which includes systems that span large geographic areas and are subject to unpredictable loads. Causality : given two events in a distributed computation, a crucial problem is knowing whether they are causally related.

An example of a distributed computation An example of a distributed computation

Causal broadcast n Causal broadcast states that the order in which processes deliver messages Causal broadcast n Causal broadcast states that the order in which processes deliver messages to application processes cannot violate the precedence order of the corresponding broadcast events. n n More precisely, if two broadcast messages m and m´ are such that broadcast(m) —> broadcast(m´), then any process must deliver m before m´. If the broadcasts of m and m´are concurrent, then processes are free to deliver m and m´in any order. This means that when a process delivers a message m to a process, all messages whose broadcasts causally precede the broadcast of m have already been delivered to that process.

Causal delivery of broadcast messages Causal delivery of broadcast messages

Outline 6. 1 6. 2 6. 3 6. 4 6. 5 Clock Synchronization (++) Outline 6. 1 6. 2 6. 3 6. 4 6. 5 Clock Synchronization (++) Logical Clocks (++) Mutual Exclusion Global Positioning of nodes Election Algorithms

6. 3 Mutual Exclusion n n n Overview A Centralized Algorithm A Decentralized Algorithm 6. 3 Mutual Exclusion n n n Overview A Centralized Algorithm A Decentralized Algorithm A Distributed Algorithm A Token Ring Algorithm A Comparison of the Four Algorithm

Terminology n n In concurrent programming a critical section (CS) is a piece of Terminology n n In concurrent programming a critical section (CS) is a piece of code that accesses a shared resource that must not be concurrently accessed by more than one thread of execution. Mutual exclusion (ME, often abbreviated to mutex) algorithms are used in concurrent programming to avoid the simultaneous use of a common resource, such as a global variable, by pieces of computer code called critical sections.

Applications use ME n Observation: If a data item is replicated at various sites, Applications use ME n Observation: If a data item is replicated at various sites, we expect that only one of the sites updates it at a time. This gives rise to the problem of ME, which requires that only one of the contending processes be allowed, at a time, to enter its CS. n Replicated databases n n Protocols that control access to replicated data and ensure data consistency in case of network partitioning are called replica control protocols. A transaction (an access request to data) is the basic unit of user computation in a database. All replica control protocols require that mutual exclusion must be guaranteed between two write operations and a read and write operation. Distributed shared memory (DSM) is an abstraction used for sharing data between computers that do not share physical memory.

Performance Metrics of DME Algorithm n Message Complexity (MC) n n Synchronization Delay (SD) Performance Metrics of DME Algorithm n Message Complexity (MC) n n Synchronization Delay (SD) n n The number of messages exchanged by a process per CS entry. the average time delay in granting CS, which is the period of time between the instant a site invokes mutual exclusion and the instant when it enters CS. A good DME algorithm must be n n n safe (it shall ensure mutual exclusion), live (the system should make progress towards the execution of CS and a deadlock situation shall not occur) and fair (it shall not be biased against or in favor of a node and each request shall eventually be satisfied). low MC and SD. high fault tolerance and availability n n The fault tolerance is the maximal number of nodes that can fail before it becomes impossible for any node to enter its CS. Its availability is the probability that the CS can be entered in the presence of failures.

Mutual Exclusion n n Prevent simultaneous access to a resource Two different categories: n Mutual Exclusion n n Prevent simultaneous access to a resource Two different categories: n n Permission-based approach n A Centralized Algorithm n A Decentralized Algorithm n A Distributed Algorithm Token-based approach n A Token Ring Algorithm

Centralized Algorithm n Use a central coordinator to simulate how it is done in Centralized Algorithm n Use a central coordinator to simulate how it is done in a one-processor system Step 1: Process 1 asks the coordinator for permission to access a shared resource. Permission is granted. Step 2: Process 2 then asks permission to access the same resource. The coordinator does not reply. Step 3: When process 1 releases the resource, it tells the coordinator, which then replies to 2.

A Decentralized Algorithm n Use a distributed hash table (DHT). n n n Hashes A Decentralized Algorithm n Use a distributed hash table (DHT). n n n Hashes to a node. Each resource has n coordinators (called replicas in the book). A limit m (> n/2) is pre-defined. A client acquires the lock by sending a request to each coordinator. n n If it gets m permissions, then it gets it. If a resource is already locked, then it will be rejected (as opposed to just blocking. )

n=5 m=3 1. Send lock requests 2. Receive responses. Blue succeeds. 3. Release if n=5 m=3 1. Send lock requests 2. Receive responses. Blue succeeds. 3. Release if failed.

Coordinator Failure n If a coordinator fails, replace it. n n n This amounts Coordinator Failure n If a coordinator fails, replace it. n n n This amounts to a resetting of the coordinator state, which could result in violating mutual exclusion. How many would have to fail? n n But what about the lock state? 2 m - n What is the probability of violation?

Probability of Violation n Let p be the probability of failure during some time Probability of Violation n Let p be the probability of failure during some time t. The probability that k out of n coordinators reset is: To violate mutual exclusion, you need at least 2 m-n failures. With node participation for 3 hours, t of 10 seconds, and n = 32 and m = 0. 75 n, the Pv < 10 -40.

A Distributed Algorithm 1. 2. 3. When a process wants a resource, it creates A Distributed Algorithm 1. 2. 3. When a process wants a resource, it creates a message with the name of the resource, its process number, and the current (logical) time. It then reliably sends the message to all processes and waits for an OK from everyone. When a process receives a message: A. B. C. If the receiver is not accessing the resource and is not currently trying to access it, it sends back an OK message to the sender. n “Yes, you can have it. I don’t want it, so what do I care? ” If the receiver already has access to the resource, it simply does not reply. Instead, it queues the request. n “Sorry, I am using it. I will save your request, and give you an OK when I am done with it. ” If the receiver wants to access the resource as well but has not yet done so, it compares the timestamp of the incoming message with the one contained in the message that it has sent everyone. The lowest one wins. 1. If the incoming message has a lower timestamp, the receiver sends back an OK. n 2. If it’s own message has a lower timestamp, it queues it up. n 4. “I want it also, but you were first. ” “Sorry, I want it also, and I was first. ” When done using a resource, send an OK on its queue and delete them all from the queue.

Step 1 Step 2 Timestamp Step 3 Accesses resource Two processes (0 and 2) Step 1 Step 2 Timestamp Step 3 Accesses resource Two processes (0 and 2) want to access a shared resource at the same moment. Process 0 has the lowest timestamp, so it wins. When process 0 is done, it sends an OK also, so 2 can now go ahead.

Evaluation n How many messages are required? More or less than centralized? n n Evaluation n How many messages are required? More or less than centralized? n n n More scalable? How much work per node, per lock? Is it better than centralized? How many points of failure? n n One request and OK from everyone else, so 2(n-1). We have replaced a poor one with a worse one. Can we figure out how to handle failure?

A Token Ring Algorithm n n (a) An unordered group of processes on a A Token Ring Algorithm n n (a) An unordered group of processes on a network. (b) A logical ring constructed in software.

n n n When ring is initiated, give process 0 the token. Token circulates n n n When ring is initiated, give process 0 the token. Token circulates around the ring in point-to-point messages. When a process wants to enter the CS, it waits till it gets the token, enters, holds the token, exits, passes the token on. Starvation? Lost tokens? Other crashes?

A Comparison of the Four Algorithms A Comparison of the Four Algorithms

Outline 6. 1 6. 2 6. 3 6. 4 6. 5 Clock Synchronization (++) Outline 6. 1 6. 2 6. 3 6. 4 6. 5 Clock Synchronization (++) Logical Clocks (++) Mutual Exclusion Global Positioning of nodes Election Algorithms

Global Positioning of Nodes n n Problem: How can a single node efficiently estimate Global Positioning of Nodes n n Problem: How can a single node efficiently estimate the latency between any two other nodes in a distributed system? Solution: construct a geometric overlay network, in which the distance d(P, Q) reflects the actual latency between P and Q.

Computing Position (1/2) n n Observation: a node P needs m + 1 distance Computing Position (1/2) n n Observation: a node P needs m + 1 distance meausres to compute its own position in a m-dimensional space. Consider two-dimensional case: Solution: P needs to solve three equations in two unknowns (x. P, y. P):

Computing Position (2/2) Computing Position (2/2)

Szyamniak et al. , 2004 n As it turns out, with well-chosen landmarks, m Szyamniak et al. , 2004 n As it turns out, with well-chosen landmarks, m can be as small as 6 or 7, with d^(P, Q) being no more than a factor 2 different from the actual latency d(P, Q) for arbitrary nodes P and Q.

Outline 6. 1 6. 2 6. 3 6. 4 6. 5 Clock Synchronization (++) Outline 6. 1 6. 2 6. 3 6. 4 6. 5 Clock Synchronization (++) Logical Clocks (++) Mutual Exclusion Global Positioning of nodes Election Algorithms

Election Algorithms n n n The Bully Algorithm A Ring Algorithm Superpeer Selection Election Algorithms n n n The Bully Algorithm A Ring Algorithm Superpeer Selection

Election Algorithms n n n Principle: An algorithm requires that some process acts as Election Algorithms n n n Principle: An algorithm requires that some process acts as a coordinator. The question is how to select his special process dynamically. Note: In many systems the coordinator is chosen by hand (e. g. file servers). This leads to centralized solutions => single point of failure. Question: Is a full distributed solution, n i. e. one without a coordinator, always more robust than any centralized/coordinated solution?

Election by Bullying (1/2) n n n Principle: Each process has an associated priority(weight). Election by Bullying (1/2) n n n Principle: Each process has an associated priority(weight). The process with the highest priority should always be elected as the coordinator. Issue: How do we find the heaviest process? Any process can just start an election by sending an election message to all other processes (assuming you don’t know the weights of the others). If a process Pheavy receives an election message from a lighter process Plight, it sends a take-over message to Plight is out of the race. If a process doesn’t get a take-over message back, it wins, and sends a victory message to all other processes.

Election by Bullying (2/2) Question: We’re assuming something very important here – what? Election by Bullying (2/2) Question: We’re assuming something very important here – what?

Election in a Ring (1/2) n Principle: Process priority is obtained by organizing processes Election in a Ring (1/2) n Principle: Process priority is obtained by organizing processes into a (logical) ring. Process with the highest priority should be elected as coordinator. n n n Any process can start an election by sending an election message to its successor. If a successor is down, the message is passed on to the next successor. If a message is passed on, the sender adds itself to the list. When it gets back to the initiator, everyone had a chance to make its presence known. The initiator sends a coordinator message around the ring containing a list of all living processes. The one with the highest priority is elected as coordinator.

Election in A Ring (2/2) Question: Does it matter if two processes initiate an Election in A Ring (2/2) Question: Does it matter if two processes initiate an election? Question: What happens if a process crashes during the election?

Elections in Large-Scale Systems n n The algorithms we have been discussing so far Elections in Large-Scale Systems n n The algorithms we have been discussing so far generally apply to relatively small distributed systems. Moreover, the algorithms concentrate on the selection of only a single node.

Superpeer Selection n Issue: How do we select superpeers such that: n n n Superpeer Selection n Issue: How do we select superpeers such that: n n n n Normal nodes have low-latency access to superpeers Superpeers are evenly distributed across the overlay network There is be a predefined fraction of superpeers Each superpeer should not need to serve more than a fixed number of normal nodes DHT: Reserve a fixed part of the ID space for superpeers. Example: if S superpeers are needed for a system that uses m-bit identifiers, simply reserve the k = ⌈ log 2 S⌉ leftmost bits for superpeers. With N nodes, we’ll have, on average, 2 k−m. N superpeers. Routing to superpeer: Send message for key p to node responsible for p AND 11· · · 1100· · · 00

Superpeer Selection in an m-dimensional geometric space n n Moving tokens in a two-dimensional Superpeer Selection in an m-dimensional geometric space n n Moving tokens in a two-dimensional space using repulsion forces. When a token is held by a node for a given amount of time, that node will promote itself to superpeer.