This and upcoming lectures? What time is it? � We‚ll focus on concepts relating to time � In distributed system we need practical ways to deal with time � Time as it can be ”used„ in systems � E.g. we may need to agree that update A � Systems that present behaviors best occurred before update B understood in terms of temporal models (notably the transactional model) � Or offer a ”lease„ on a resource that expires at time 10:10.0150 � Event ordering used to ensure consistency in distributed systems (multicasts that � Or guarantee that a time critical event will update replicated data or program state) reach all interested parties within 100ms But what does time ”mean„? Lamport‚s approach � Time on a global clock? � Leslie Lamport suggested that we should reduce time to its basics � E.g. with GPS receiver � Time lets a system ask ”Which came first: � ‧ or on a machine‚s local clock event A or event B?„ � But was it set accurately? � In effect: time is a means of labeling � And could it drift, e.g. run fast or slow? events so that ‧ � What about faults, like stuck bits? � If A happened before B, TIME(A) < TIME(B) � ‧ or could try to agree on time � If TIME(A) < TIME(B), A happened before B
Drawing time-line pictures: Drawing time-line pictures: snd p (m) snd p (m) p p A B m m D D q q C rcv q (m) deliv q (m) rcv q (m) deliv q (m) � A, B, C and D are ”events„. � Could be anything meaningful to the application � So are snd(m) and rcv(m) and deliv(m) � What ordering claims are meaningful? Drawing time-line pictures: Drawing time-line pictures: snd p (m) snd p (m) p p A B A B m m D D q C q C rcv q (m) deliv q (m) rcv q (m) deliv q (m) � A happens before B, and C before D � snd p (m) also happens before rcv q (m) � ”Local ordering„ at a single process � ”Distributed ordering„ introduced by a message � Write and � Write M p q � � � snd ( m ) rcv ( m ) A B C D p q
Drawing time-line pictures: Drawing time-line pictures: snd p (m) snd p (m) p p A B A B m m D D q C q C rcv q (m) deliv q (m) rcv q (m) deliv q (m) � A happens before D � B and D are concurrent � Transitivity: A happens before snd p (m), which � Looks like B happens first, but D has no happens before rcv q (m), which happens before D way to know. No information flowed ‧ Happens before ”relation„ Logical clocks We‚ll say that ”A happens before B„, � A simple tool that can capture parts of � written A � B, if the happens before relation 1. A � P B according to the local ordering, or � First version: uses just a single integer 2. A is a snd and B is a rcv and A � M B , or � Designed for big (64-bit or more) counters 3. A and B are related under the transitive � Each process p maintains LT p , a local closure of rules (1) and (2) counter So far, this is just a mathematical � � A message m will carry LT m notation, not a ”systems tool„
Time-line with LT annotations Rules for managing logical clocks � When an event happens at a process p it snd p (m) p increments LT p . A B LT p 0 1 1 2 2 2 2 2 2 3 3 3 3 � Any event that matters to p m � Normally, also snd and rcv events (since we want receive to occur ”after„ the matching send) q C D rcv q (m) deliv q (m) � When p sends m, set LT q 0 0 0 1 1 1 1 3 3 3 4 5 5 � LT m = LT p � When q receives m , set � LT(A) = 1, LT(snd p (m)) = 2, LT(m) = 2 � LT(rcv q (m))=max(1,2)+1=3, etc ‧ � LT q = max(LT q , LT m )+1 Logical clocks Can we do better? � If A happens before B, A � B, � One option is to use vector clocks then LT(A)<LT(B) � Here we treat timestamps as a list � But converse might not be true: � One counter for each process � If LT(A)<LT(B) can‚t be sure that A � B � Rules for managing vector times differ � This is because processes that don‚t from what did with logical clocks communicate still assign timestamps and hence events will ”seem„ to have an order
Vector clocks Time-line with VT annotations � Clock is a vector: e.g. VT(A)=[1, 0] snd p (m) p � We‚ll just assign p index 0 and q index 1 A B � Vector clocks require either agreement on the VT p 0 1 1 2 2 2 2 2 2 3 3 3 3 0 0 0 0 0 0 0 0 0 0 0 0 0 m numbering, or that the actual process id‚s be VT(m)=[2,0] included with the vector D q C � Rules for managing vector clock rcv q (m) deliv q (m) � When event happens at p, increment VT p [index p ] VT q 0 0 0 0 0 0 0 2 2 2 2 2 2 0 0 0 1 1 1 1 2 2 2 3 3 4 � Normally, also increment for snd and rcv events Could also be [1,0] if we decide not to increment the clock on a � When sending a message, set VT(m)=VT p snd event. Decision depends on how the timestamps will be used. � When receiving, set VT q =max(VT q , VT(m)) Rules for comparison of VTs Time-line with VT annotations � We‚ll say that VT A � VT B if snd p (m) p � � I , VT A [i] � VT B [i] A B VT p 0 1 1 2 2 2 2 2 2 3 3 3 3 � And we‚ll say that VT A < VT B if 0 0 0 0 0 0 0 0 0 0 0 0 0 m � VT A � VT B but VT A � VT B VT(m)=[2,0 ] � That is, for some i, VT A [i] < VT B [i] D q C rcv q (m) deliv q (m) � Examples? VT q 0 0 0 0 0 0 0 2 2 2 2 2 2 0 0 0 1 1 1 1 2 2 2 3 3 4 � [2,4] � [2,4] � [1,3] < [7,3] � VT(A)=[1,0]. VT(D)=[2,4]. So VT(A)<VT(D) � [1,3] is ”incomparable„ to [3,1] � VT(B)=[3,0]. So VT(B) and VT(D) are incomparable
Introducing ”wall clock time„ Vector time and happens before � There are several options � If A � B, then VT(A)<VT(B) � ”Extend„ a logical clock or vector clock with � Write a chain of events from A to B the clock time and use it to break ties � Step by step the vector clocks get larger � Makes meaningful statements like ”B and D � If VT(A)<VT(B) then A � B were concurrent, although B occurred first„ � Two cases: if A and B both happen at same � But unless clocks are closely synchronized such process p, trivial statements could be erroneous! � If A happens at p and B at q, can trace the path � We use a clock synchronization algorithm back by which q ”learned„ VT A [p] to reconcile differences between clocks on � Otherwise A and B happened concurrently various computers in the network Synchronizing clocks Synchronizing clocks � Without help, clocks will often differ by Delay: 123ms many milliseconds p � Problem is that when a machine downloads What time is it? time from a network clock it can‚t be sure what the delay was 09:23.02921 � This is because the ”uplink„ and ”downlink„ time.windows.com delays are often very different in a network � Outright failures of clocks are rare ‧ Suppose p synchronizes with time.windows.com and notes that 123 ms � elapsed while the protocol was running ‧ what time is it now?
Synchronizing clocks Consequences? � Options? � In a network of processes, we must � P could guess that the delay was evenly split, but assume that clocks are this is rarely the case in WAN settings (downlink � Not perfectly synchronized. Even GPS has speeds are higher) � P could ignore the delay uncertainty, although small � P could factor in only ”certain„ delay, e.g. if we � We say that clocks are ”inaccurate„ know that the link takes at least 5ms in each � And clocks can drift during periods direction. Works best with GPS time sources! between synchronizations � In general can‚t do better than uncertainty in the link delay from the time source down to p � Relative drift between clocks is their ”precision„ Thought question Thought question � We are building an anti-missile system � We want them to agree on the time but it isn‚t important whether they are � Radar tells the interceptor where it should be and what time to get there accurate with respect to ”true„ time � Do we want the radar and interceptor to � ”Precision„ matters more than ”accuracy„ be as accurate as possible, or as precise as � Although for this, a GPS time source would possible? be the way to go � Might achieve higher precision than we can with an ”internal„ synchronization protocol!
Real systems? Clock synchronization � Typically, some ”master clock„ owner � To optimize for precision we can periodically broadcasts the time � Set all clocks from a GPS source or some other time ”broadcast„ source � Processes then update their clocks � Limited by uncertainty in downlink times � But they can drift between updates � Or run a protocol between the machines � Many have been reported in the literature � Hence we generally treat time as having � Precision limited by uncertainty in message delays fairly low accuracy � Some can even overcome arbitrary failures in a subset of � Often precision will be poor compared to the machines! message round-trip times For next time � Read the introduction to Chapter 14 to be sure you are comfortable with notions of time and with notation � Chapter 23 looks at clock synchronization
Recommend
More recommend