Download presentation
Presentation is loading. Please wait.
Published by帖谈 卜 Modified over 7 years ago
1
Logical time Causality between events is fundamental to the design of parallel and distributed systems. In distributed systems, it is not possible to have global physical time. It is only possible to achieve an approximation of it. For many applications in distributed systems, what usually matters is not that all tasks agree on exactly the real time, but rather they agree on the order in which events occur
2
Synchronising Logical Clocks
happens before If a and b are events in the same process, and a occurs before b, then a b is true. If a is the event of a message being sent by one process, and b is the event of the message being received by another process, then a b is also true. A message cannot be received before it is sent, or even at the same time that it is sent, since it takes a finite amount of time to arrive. 2
3
Happen before is a transitive relation
if a b and b c, then a c Need a way to represent time such that for every event, say a, a time value c(a) can be assigned on which all processes agree. These time values must have the property that if a b, then c(a) < c(b). Logical clock is the device which is used to record the time for a process. The time which is assigned to an event is based on the value of the logical clock. The logical clock is a counter like variable. 3
4
logical clock loopforever if an event occurs in the process
then assign the value of clock to the event; clock := clock + 1 endif if a message m is received then clock : = max(time(m), clock) + 1; assign the value of clock to the receiving message event endloop 4
5
P1 P2 A (0) Send to P2 (1) Receive from P1 (2) C (2) D (3) E (3)
5
6
total order Some events in different processes cannot be ordered according to the time. This is the case when the timestamps of two events from different processes are the same. In order to be able to give an order in this situation, the identifier of the processes are used. A timestamp is a pair (time, process-identifier). The identifiers of the processes are unique Assume that the timestamps for a and b are (Ta, Ida) and (Tb, Idb) respectively. a b if Ta < Tb a b if Ta = Tb and Ida < Idb The identifier is used to break the tie when two events from different processes have the same clock value. Totally ordered logical clock imposes an order between each pair of events in the system. 6
7
Partially ordered logical clock
For some applications, giving an order between each event is neither necessary nor desirable. Does not express the causal relations of the events in the system. Debugging a distributed program. Partially ordered logical clock allows us to find the causal relation among the processes. The timestamp of the events in a system which uses the partially ordered logical clock is a set of timestamps. Each element in the set is a timestamp of the process which has causal relation with the process. P1 P2 (1, P1) (2, P1) (3, P1) (4, P1) (5, P1) (1, P2) (4, P2) (5, P2) crash P1 < P2 7
8
The following rules are used to maintain the timestamp.
Let c denotes the time stamp of a process; and c(i) represents the timestamp of the process whose identifier is i. The following rules are used to maintain the timestamp. initialisation When a process starts execution, the time is initialised to an empty set. ticking Whenever a process p performs an event, it increments c(p) by one. process creation Whenever a process p creates a set of process pj,..., pm, they each inherit the current time from p; i.e. x:{j..m}. c(x) = c(p). process termination Whenever a child process terminates, the time of the parent process merges with the time of the child by maximising the counter values. sending Whenever a process p sends a message, that message carries the current value of the time. receiving Upon receiving a message, the receiving process merges its time with the time carried by the message by maximising the counter values. " 8
9
process s process t process r process q {} process p 9
10
process s process t a{(p, 1)} process r process q {} process p 10
11
e {(p,2)} process s process t a{(p, 1)} process r process q {}
process p 11
12
e {(p,2)} process s process t h {(p,1), (r,1)} a{(p, 1)} process r
process q {} process p 12
13
k {(p,1), (r,1), (t,1)} process t e {(p,2)} process s h {(p,1), (r,1)}
a{(p, 1)} process r process q {} process p 13
14
f {(p,3), (r,1), (s,1)} i {(p,3), k {(p,1), (r,1), (s,1)}
(r,1), (t,1)} e {(p,2)} process s process t h {(p,1), (r,1)} a{(p, 1)} process r process q {} process p 14
15
l {(p,3), (r,2), (s,1), (t,1)} f {(p,3), (r,1), (s,1)} i {(p,3),
k {(p,1), (r,1), (s,1)} (r,1), (t,1)} e {(p,2)} process s process t h {(p,1), (r,1)} a{(p, 1)} process r process q {} process p 15
16
l {(p,3), (r,2), (s,1), (t,1)} f {(p,3), (r,1), (s,1)} i {(p,3),
k {(p,1), (r,1), (s,1)} (r,1), (t,1)} b {(p, 1), (q, 1)} e {(p,2)} process s process t h {(p,1), (r,1)} a{(p, 1)} process r process q {} process p 16
17
c {(p,4), (q,2), l {(p,3), (r,2), (r,1), (s,1)} (s,1), (t,1)}
g {(p,4), (r,1), (s, 1)} f {(p,3), (r,1), (s,1)} i {(p,3), k {(p,1), (r,1), (s,1)} (r,1), (t,1)} b {(p, 1), (q, 1)} e {(p,2)} process s process t h {(p,1), (r,1)} a{(p, 1)} process r process q {} process p 17
18
m {(p,5), (q,3), (r,2), (s,1), (t,1)} d {(p,4), (q,3), (r,1), (s,1)}
c {(p,4), (q,2), l {(p,3), (r,2), (r,1), (s,1)} (s,1), (t,1)} g {(p,4), (r,1), (s, 1)} f {(p,3), (r,1), (s,1)} i {(p,3), k {(p,1), (r,1), (s,1)} (r,1), (t,1)} b {(p, 1), (q, 1)} e {(p,2)} process s process t h {(p,1), (r,1)} a{(p, 1)} process r process q {} process p 18
19
Compared with totally ordered logical clock, partially ordered logical clock is more expressive.
Partially ordered logical clocks may be impractical and expensive for long-live computations. There is no upper bound on the size of the timestamp. The number of item in the timestamp set is only limited by the number of processes created at run time. 19
20
Review How does a totally ordered logical clock work?
What is the main feature of a totally ordered logical clock? How does a partially ordered logical clock work? What is the main feature of a partially ordered logical clock? Which kind of logical time system do you need if you are required to develop an auditing system to monitor the execution of a distributed system develop a scheme for controlling the access to the shared resources in a distributed system
21
Further reading Leslie Lamport. Time, clocks, and the ordering of events in a distributed system. Communications of the ACM, 21:558–565, 1978. C. Fidge. Logical time in distributed computing systems. IEEE Computer, pages 28-33, July 1991
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.