Presentation is loading. Please wait.

Presentation is loading. Please wait.

Slides for Chapter 11: Time and Global State From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 4, © Pearson Education.

Similar presentations


Presentation on theme: "Slides for Chapter 11: Time and Global State From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 4, © Pearson Education."— Presentation transcript:

1 Slides for Chapter 11: Time and Global State From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 4, © Pearson Education 2005

2 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure 11.1 Skew between computer clocks in a distributed system Clock skew: instantaneous difference between readings of different clocks Clock drift: clocks count time at different rates Quartz crystals are used for clocks – they oscillate at ‘rates’ Drift can vary from to per second Atomic oscillators drift is per second Coordinated Universal Time (UTC)

3 Synchronizing Physical Clocks zAuthoritative source (S) yUTC time S(t) zSystem P zProcess i, clock C i zSynchronization bound D>0 zExternal Synchronization:  S(t) – C i (t)  < D; xfor i= 1,2, …, N, for all time t in process i. yC i are accurate within the bound D zInternal Synchronization:  C i (t) – C j (t)  < D; xfor i= 1,2, …, N, for all time t in process i. yC i agree within the bound D Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 If a system is externally synchronized with a bound D then the system is internally synchronized with a bound 2D

4 Synchronization in a synchronous system zProcess p 1 sends a time ’t’ in message m to p 2 zLet T trans – time to transmit m from p 1 to p 2 zT trans – is subject to variations zUpper bound- max and lower bound- min zUncertainty in the message transmission time u = (max-min); yt+max or t+min? zFor t + (max+min)/2 ySkew is at most u/2 zIn general,when synchronizing N clocks the skew can be u(1-1/N) Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 p1p1 p2p2 m

5 Figure 11.2 Clock synchronization using a time server – Cristian’s Algorithm m r m t p Time server,S p requests t from S S receives m r, appends t to m t and sends m t to p When p receives m t, what is the time at S? The earliest time at which S placed t in m t is time at which p sent m r plus min The latest time at which S placed t in m t is time at which p received m t minus min S’ clock in the range (t+min, t+T round -min) Range is T round -2min and the accuracy is  (T round /2-min) Berkley algorithm The master sends the amount by which a slave’s clock requires adjustment Single server – prone to faults

6 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure 11.3 An example synchronization subnet in an NTP implementation Note: Arrows denote synchronization control, numbers denote strata. *Reliable service despite lengthy disconnected periods *Clients can resynchronize sufficiently frequently to offset drift *Protection against interference Synchronize each other from time to time Use UDP Multicast, procedure call (Cristian’s algo),

7 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure 11.4 Messages exchanged between a pair of NTP peers T i T i-1 T i-2 T i-3 Server B Server A Time mm' Time o i is the offset for each pair of messages between two servers -is an estimate of the actual offset and a delay d i. -Let o be the true offset of the clock at B relative to A -actual transmission time of m (m’) is t(t’) -T i-2 = T i-3 +t+o; T i = T i-1 +t’-o ; d i = t+t’= T i-2 -T i-3 +T i -T i-1 - o = o i +(t’-t)/2; t,t’  0  o i -d i /2 ≤o ≤ o i +d i /2

8 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure 11.5 Events occurring at three processes : Logical time and clocks 1.LC1: for any process p i : e i  e’ then e  e’; i  indicates happened before event on processor i 1.LC2: For any message m, send(m)  receive(m) 2.LC3: If e  e’ and e’  e’’ then e  e’’

9 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure 11.6 Lamport timestamps for the events shown in Figure 11.5 Totally ordered logical clocks: Event e occurs at p i with local time stamp T i Event e’ occurs at p j with local time stamp T j Logical time stamps for the events (T i, i), (T j,j) Then (T i,i) < (T j,j) iff either T i < T j or T i = T j and i

10 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure 11.7 Vector timestamps for the events shown in Figure 11.5 VC1: Initially V i [j] = 0 for i,j = 1,2, …N VC2: just before p i timestamps an event, it sets V i [i]:= V i [i]+1 VC3:p i includes the value of t = v i in every message it sends VC4: when p i receives a time stamp t in a message, it sets V i [j] := max(V i [j],t[j]), for j = 1,2,… N; takes the max of two vector stamps For vector clock V i, V i [i] is the number of events that p i has time stamped V i [j] ( j  i) is the number of events that have occurred at p j that p i has potentially been affected by. Note: p j may have time-stamped more events by this point, but no messages have arrived at p i to this effect

11 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Compare vector time stamps: V = V’ iff V[j] = V’[j] for j= 1,2, …N V≤V’ iff V[j] ≤ V’[j] for j= 1,2, …N V

12 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure 11.8 Detecting global properties p 2 p 1 message garbage object object reference a. Garbage collection p 2 p 1 wait-for b. Deadlock p 2 p 1 activate passive c. Termination Garbage: no references A message is transit has a reference to orange object – is not garbage Deadlock: Cycle with ‘wait for’ relation between processes p 1 and p 2 wait for each other – there will be no progress Detecting termination of a process is difficult. For example message from p2 to p1 may be in transit when both are perceived to be ‘passive’ A subset of processes are affected Possible that all processes have terminated A process is attempting to perform an activity A passive process is not engaged in any activity

13 Global states and Consistent Cuts zSystem consists of N processes p 1, p 2, … p N zHistory of p i : history(p i ) = h i = zHistory till kth event h i k = zEach event – internal state transformation action or communication action zS i k is the state of process i immediately after kth event yS i 0 is the initial state of p i zGlobal history of system is the union of individual process histories zAny set of states of the individual processes form a global state yS = (s 1 +s 2 …s N ) xWhich process states occurred at the same time? xGlobal state: initial prefixes of the individual process histories Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

14 Global States and consistent Cuts zA cut of the system’s execution is a subset of its global history that is a union of prefixes of process histories: Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

15 Figure 11.9 Cuts m 1 m 2 p 1 p 2 Physical time e 1 0 Consistent cut Inconsistent cut e 1 1 e 1 2 e 1 3 e 2 0 e 2 1 e 2 2 S = (s 1 +s 2 …s N ) - state corresponding to a cut C. There are two cuts above, C 1 and C 2 … The events e 1 0 and e 2 0 happen before the cut C 1, * is the frontier of C 1 ** is an inconsistent cut * is the frontier of C 2 ** is a consistent cut

16 Cut Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 m 1 m 2 p 1 p 2 Physical time e 1 0 Consistent cut Inconsistent cut e 1 1 e 1 2 e 1 3 e 2 0 e 2 1 e 2 2 C 1 : on p 2, the receipt of message m 1 is included, but on p 1 the sending of message m 1 is not included; C 1 is showing an effect without a cause - inconsistent C 2 :Includes sending and receiving events of m 1 ; C 2 includes the sending of m 2. Receipt is an effect, and it takes time for the message to arrive - consistent. A Cut is consistent if for each event e in the frontier, it also contains all events that happened before e, for all events e  C, f  e  f  C

17 Cut zA consistent global state corresponds to a consistent cut zExecution of a distributed system can be characterized as S 0  S 1  S 2  S 3 ... yEach transition – xOne event at any one process or xConcurrent events (NO happened-before) zRun is a total ordering of all events in a global history zConsistent run or linearization is an ordering of events in a global history such that all events are consistent with the happened before relation  on H. zIf there is a linearization that passes through state S and then state S’, then S is said to be reachable from S Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

18 Global State predicates zGlobal state predicates are useful in evaluating a condition. yExamples : x An object is garbage xA set of processes are deadlocked xProcesses have terminated zGlobal state predicate is function that maps from the set of global states of processes in the system to {True, False} zWhen a system reaches a state in which the Predicate is True, it remains True in all states reachable from that state. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

19 Safety and livenes zS 0 is the original state of the system. z  is the property that the global system is deadlocked x  is an undesirable property ySafety: x  evaluates to False for all states S i reachable from S 0 z  is the property of reaching a termination yLiveness x  evaluates to True for some state S L reachable from S 0 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

20 Figure Chandy and Lamport’s ‘snapshot’ algorithm zDetermines global states of a distributed system zRecords consistent global state yFor a set of processes p i xProcess and Channel states are recorded Snapshot zThe algorithm xAssumes no failures (channels and processes) –A message sent from process is eventually received by another Unidirectional channels provide FIFO delivery A path exists between any two processes Global snapshot can initiated by any process The snapshot is non-interfering Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

21 Figure Chandy and Lamport’s ‘snapshot’ algorithm Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 pipi incoming channels outgoing channels pipi pjpj Each process records its state and for each incoming channel, a set of messages sent to it Marker message: * is a prompt for the receiver or save its state *is an indicator of which messages to include in channel state.

22 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure Chandy and Lamport’s ‘snapshot’ algorithm Marker receiving rule for process p i On p i ’s receipt of a marker message over channel c: if (p i has not yet recorded its state) it records its process state now; records the state of c as the empty set; turns on recording of messages arriving over other incoming channels; else p i records the state of c as the set of messages it has received over c since it saved its state. end if Marker sending rule for process p i After p i has recorded its state, for each outgoing channel c: p i sends one marker message over c (before it sends any other message over c).

23 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure Two processes and their initial states

24 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure The execution of the processes in Figure 11.11

25 Termination zA process receiving the marker message records its state, within a finite time, and sends marker messages on each of its outgoing channels, within a finite time zA path of communication channels exists between any two processes p i and p j y p j will records its state a finite state after p i zIt is a strongly connected graph of processes and channels yAll processes record their state and the states of incoming messages, a finite time after the initiation Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

26 Figure Reachability between states in the snapshot algorithm S init S final S snap actual execution e 0,e 1,... recording begins ends pre-snap: e ' 0,e ' 1,...e ' R-1 post-snap: e ' R,e ' R+1,...

27 Distributed Debugging Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 In a distributed system it is not possible to observe the states of all processes sumilataneously Chandy and Lamport’s algorithm collects states in a distributed fashion The challenge: trace information over time to establish whether a required safety condition has been met or violated Assumptions: the algorithm is centralized - all processes send their states to a monitor process - the monitor lies outside the system - the monitor’s main job is to observe the execution of processes Objective: whether a global system predicate  was definitely True or whether it was possibly True (might have occurred).

28 Debugging zPossibly: Suppose one consistent global state, S is extracted and  (S) is found to be true. yPossibly  : There is a consistent global state S through which a linearization of H passes such that  (S) is True. zDefinitely: applies to the actual execution y- all linearizations are considered yDefinitely  : for all linearizations L of H, there is a consistent global state S through which L passes such that  (S) is True. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

29 Collecting the state zInitially, each process p i (i=1,2, …N) sends its initial state to the monitor. zSubsequently, state messages are sent to the monitor zMonitor maintains a queue, Q i for each process p i zThe monitoring process delays normal execution, but it does not interfere zSeveral optimizations can be incorporated to reduce overheads yE.g, send state only when changes happen, send only relevant portion the state Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

30 Observations zConsistent global states are assembled by the monitor to evaluate  zProcesses include their vector clock values with state messages yMonitor can distinguish between consistent and inconsistent states Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

31 Figure Vector timestamps and variable values for the execution of Figure 11.9 m 1 m 2 p 1 p 2 Physical time Cut C 1 (1,0)(2,0)(4,3) (2,1)(2,2)(2,3) (3,0) x 1 = 1x 1 = 100x 1 = 105 x 2 = 100x 2 = 95x 2 = 90 x 1 Cut C 2 At time t=0, x 1 =x 2 =0; the requirement is  x 1 -x 2  ≤ 50 Consider the inconsistent Cut C 1, the monitor process would find that the constraint  x 1 -x 2  ≤ 50 is broken as the collected states at the monitor show x 1 = 1 and x 2 =100. For the consistent cut C 2, the collected states at the monitor show x 1 = 105 and x 2 =90. * Vector time stamps of the state messages must be examined.

32 Consistent Global States zS = (s 1 +s 2 …s N ) – global state as seen by the monitor zV(s i ) – vector timestamp of state s i received from p i zS is a consistent global state iff yV(s i )[i]  V(s j )[i] for i,j = 1,2, … N xNumber of p i ‘s events known to p j when it last sent s j is ≤ number of events that had occurred at p i when it last sent s i yThe monitor process can establish whether a global state is consistent by using vector timestamps. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

33 Figure The lattice of global states for the execution of Figure Sij = global state after i events at process 1 and j events at process 2 S 00 S 10 S 20 S 21 S 30 S 31 S 32 S 22 S 23 S 33 S 43 Level Nodes: global states Edges: possible transitions between states m 1 m 2 p 1 p 2 Physical time Cut C 1 (1,0)(2,0)(4,3) (2,1)(2,2)(2,3) (3,0) x 1 = 1x 1 = 100x 1 = 105 x 2 = 100x 2 = 95x 2 = 90 x 1 Cut C 2 S ij is in level (i+j) A linearization traverses the lattice from any global state to any global state reachable from it in the next level

34 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 p 1 p 2 Physical p1p1 p2p2 p3p3 (0,1,1) (0,1,0) (1,2,0)(1,3,0) (1,0,0) (0,1,2) (1,3,3) (2,1,2)(3,1,2) (3,4,3)

35 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 S 00 S 10 S 20 S 21 S 30 S 31 S 32 S 22 S 23 S 33 S 43 S 22 is reachable from S 20, but not from S 30 Level possibly  : monitor starts at the initial state and steps through all consistent states reachable from that point;  is evaluated at each stage; it stops if  evaluates to True. definitely  : monitor process finds a set of states through which all linearizations must pass; evaluates  at each of these states; if  evaluates to True at each of these states then definitely .

36 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure Algorithms to evaluate possibly  and definitely 

37 Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 Figure Evaluating definitely  If F = (  S  False);  T = (  S  True) ? – Level F F F FT F The monitor begins to process states, starting at the initial state, (s 1 0, s 2 0,… s N 0 ) Maintains the set States – those states at current state that may be reached on a linearization from the initial state, by traversing only states for which  evaluates to False. definitely  cannot be asserted as long as such linearization exists. If a level with no such linearization is reached, then definitely . One level 4: the state to right of F is not considered since it may be reached via a state for which  evaluates to True.  evaluates to True at level 5 then definitely .

38 Cost Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005 k events/process, N processes Theoretically O(k N ) comparisons; All events are not significant There are techniques to reduce number of states

39 Exercises zExercise problems 11.9 to zExercise problems 11.1 to 11.8 are also important, though trivial. Instructor’s Guide for Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edn. 4 © Pearson Education 2005

40 a b cd ef m 1 m 2 (2,0,0)(1,0,0) (2,1,0)(2,2,0) (2,2,2) (0,0,1) p 1 p 2 p 3 Physical time p 2 holds resource r 2 and p 4 hosts resource r 4 p4p4


Download ppt "Slides for Chapter 11: Time and Global State From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 4, © Pearson Education."

Similar presentations


Ads by Google