Time and global state
Time and global state
Time is a quantity often want to measure the happening of a certain event accurately. E.g.
e-commerce transaction time at merchant and bank’s computers.
Synchronize local clock with an authoritative, external source of time. Atomic oscillator
clock is the most accurate physical clock. International Atomic Time and Coordinated
Universal Time.
Network
Each node maintain a physical clock. However, they tend to drift even after an accurate
initial setting.
Clock drift: the crystal-based clock count time at different rates. Oscillator has different
frequency. Drift rate is usually used to measure the change in the offset per unit of time.
Ordinary quartz crystal clock, 1second per 11.6 days.
|S(t) –Ci(t)| <D, for i = 1,2,…N and for all real time t, namely clock Ci are
accurate to within the bound D. S is standard time.
|Ci(t) – Cj(t)| < D for i,j=1,2,…N, and for all real time t, namely, clocks Ci agree
with each other within the bound D.
KITSW Page 1
Time and global state DS III –II –CSE
In a synchronous system, bounds exist for clock drift rate, transmission delay and
time for computing of each step.
One process sends the time t on it local clock to the other in a message m. The
receiver should set its clock to t+Ttrans. It doesn’t matter whether t is accurate or
not
Synchronous system: Ttrans could range from min to max. The uncertainty
is u=(max-min). If receiver set clock to be t+min or t+max, the skew is as
much as u. If receiver set the clock to be t+(min+max)/2, the skew is at most
u/2.
mr
mt
p Time server,S
Clock synchronization using a time server
Cristian’s method: Time server, connected to a device receiving signals from UTC.
Upon request, the server S supplies the time t according to its clock.
The algorithm is probabilistic and can achieve synchronization only if the observed
round trip time is short compared with required accuracy.
From p’s point of view, the earliest time S could place the time in mt was min after p
dispatch mr. The latest was min before mt arrived at p.
KITSW Page 2
Time and global state DS III –II –CSE
mr
mt
p Time server,S
The time of S by the time p receives the
message mt is in the range of [ t+min, t+Tround –min]. P can measure the roundtrip time
then p should set its time as ( t + Tround/2 ) as a good estimation.
The width of this range is (Tround -2min). So the accuracy is +-(Tround /2-min)
Suffers from the problem associated with single server that single time server may
fail.
A client multicast is request to all servers and use only the first reply.
A faulty time server that replies with spurious time values or an imposter time
server with incorrect times.
Berkeley algorithm
Internal synchronization when developed for collections of computers running
Berkeley UNIX. A coordinator is chosen to act as the master. It periodically polls the
other computers whose clocks are to be synchronized, called slave. The salves send
back their clock values to it. The master estimate their local clock times by
observing the round-trip time similar to Cristian’s method. It averages the values
obtained including its own.
KITSW Page 3
Time and global state DS III –II –CSE
Instead of sending the updated current time back to other computers, which further
introduce uncertainty of message transmission, the master sends the amount by
which each individual slave’s clock should adjust.
The master takes a fault-tolerant average, namely a subset of clocks is chosen that
do not differ from one another by more than a specified bound.
The algorithm eliminates readings from faulty clocks. Such clocks could have a
adverse effect if an ordinary average was taken.
Cristian’s method and Berkeley algorithm are primarily for Intranets. The Network
Time Protocol(NTP) defines a time service to distribute time information over the
Internet.
KITSW Page 4
Time and global state DS III –II –CSE
1. Multicast mode: for high-speed LAN. One or more servers periodically multicasts
the time to servers connected by LAN, which set their times assuming small delay.
Achieve low accuracy.
3. Symmetric mode: used by servers that supply time in LAN and by higher level of
synchronization subnet. Highest accuracy. A pair of servers operating in symmetric
mode exchange messages bearing timing information.
KITSW Page 5
Time and global state DS III –II –CSE
Time
Server A Ti-3 Ti
In all modes, messages are delivered unreliably, using UDP Internet transport protocol.
Each message bears timestamps of recent message events: the local times when the
previous NTP message between the pair was sent and received, and the local time when the
current message was transmitted. The recipient of the NTP message notes the local time
when it receives the message.
p1
a b m1
p2 Physical
c d time
m2
p3
e f
In single process, events are ordered by local physical time. Since we cannot
synchronize physical clocks perfectly across a distributed system, we cannot use
physical time to find out the order of any arbitrary pair of events.
We will use logical time to order events happened at different nodes. Two simple
points:
If two events occurred at the same process, then they occurred in the order
in which pi observes them
KITSW Page 6
Time and global state DS III –II –CSE
Lamport (1978) called the partial ordering by generalizing these two relationships the
happened-before relation.
1 2
p1
a b m1
3 4
Physical
p2
time
c d
m2
1 5
p3
e f
a e and e a
concurrent a || e
Logical Clocks
KITSW Page 7
Time and global state DS III –II –CSE
b. On receiving (m,t), a process pj computes Lj=max(Lj,t) and then applies LC1 before
timestamping the event receive(m).
However, the converse is not true. If L(e) < L(e’), then we cannot infer that e->e’.
a->b.
L(a)<L(b)
1<2 T
E.g b and e
2>1
So we cant b->e
1 2
p1
a b m1
3 4
Physical
p2
time
c d
m2
1 5
p3
e f
KITSW Page 8
Time and global state DS III –II –CSE
Vector Clock
N processes is an array of N integers. Each process keeps its own vector clock Vi,
which it uses to timestamp local events.
(1,0,0) (2,0,0)
p1
a b m1
(2,1,0) (2,2,0)
Physical
p2
time
c d
m2
(0,0,1) (2,2,2)
p3
e f
To compare vector timestamps, we need to compare each bit. Concurrent events
cannot find a relationship.
V(b)<V(e)
The question is: can we assemble the global state of the system from local
states recorded at different real times?
Some definition
KITSW Page 10
Time and global state DS III –II –CSE
A series of events occurs at each process. Each event is either an internal action of
the process (variables updates) or it is the sending or receipt of a message over the
channel.
Ski is the state of process Pi before kth event occurs, so Ski is the initial
state of Pi.
Thus the global state corresponds to initial prefixes of the individual process
histories.
Cuts
A cut of the system’s execution is a subset of its global history that is a union of
prefixes of process histories.
The state of each process is in the state after the last event occurs in its own cut. The
set of last events from all processes are called frontier of the cut.
KITSW Page 11
Time and global state DS III –II –CSE
0 1 2 3
e1 e1 e1 e1
p1
m1 m2
p2 Physical
0 1 2 time
e2 e2 e2
Inconsistent cut: since P2 contains receiving of m1, but at P1 it does not include
sending of that message. This cut shows an effect without a cause. We will never
reach a global state that corresponds to process state at the frontier by actual
execution under this cut.
Consistent cut: it includes both the sending and receipt of m1. It includes the
sending but not the receipt of m2. It is still consistent with actual execution.
Consistent cut
A cut C is consistent if, for each event it contains, it also contains all the events that
happened-before that event.
A run is a total ordering of all the events in a global history that is consistent with
each local history’s ordering.
KITSW Page 12
Time and global state DS III –II –CSE
Record a set of process and channel states for a set of processes Pi such that even
though the combination of recorded states may never have occurred at the same
time, the recorded global state is consistent.
The algorithm records state locally at processes without giving a method for
gathering the global state.
Use of special marker message. It has a dual role, as a prompt for the receiver to save its
own state if it has not done so; and as a means of determining which messages to
include in the channel state.
else
end if
Termination Detection
2. No message is transmitted
Algorithm
KITSW Page 14
Time and global state DS III –II –CSE
KITSW Page 15