# Concurrent Reading and Writing using Mobile Agents

Document Sample

```					                     Time and Clock

Primary standard = rotation of earth
De facto primary standard = atomic clock

(1 atomic second = 9,192,631,770 orbital transitions of
Cesium 133 atom.
86400 atomic sec = 1 solar day – 3 ms (requires leap second
correction each year)

Coordinated Universal Time (UTC) = GMT ± number of hours
Global positioning system: GPS

Location and precise time
computed by triangulation

Right now GPS time is nearly
14 seconds ahead of UTC, since
It does not use leap sec. correction

Per the theory of relativity, an
Locally compensated by the

A system of 32 satellites broadcast accurate spatial
corordinates and time maintained by atomic clocks
What does “concurrent” mean?

Simultaneous? Happening at the same time? NO.
There is nothing called simultaneous in the physical world.

Alice
Explosion 2

Explosion 1
Bob
Physical clock synchronization

Question 1.
Why is physical clock synchronization important?

Question 2.
With the price of atomic clocks or GPS coming down,
should we care about physical clock synchronization?
Classification

Types of Synchronization            Types of clocks

Unbounded 0, 1, 2, 3, . . .
 External Synchronization
Bounded 0,1, 2, . . . M-1, 0, 1, . . .
 Internal Synchronization
 Phase Synchronization

Unbounded clocks are not realistic, but are easier to
deal with in the design of algorithms. Real clocks are
always bounded.
Terminologies
What are these?
Drift rate 
Clock skew 
c                       Š                     Resynchronization interval R
l
o                                   clock 1
c
clock 2
k
Max drift rate  implies:
drift rate= 
t
i                                             (1- ) ≤ dC/dt < (1+ )
m
e
Challenges
Newtonian time
R         R                           (Drift is unavoidable)
Accounting for propagation delay
Accounting for processing delay
Faulty clocks
Internal synchronization
Step 1. Read every clock in the system.
Berkeley Algorithm
Step 2. Discard outliers and substitute
them by the value of the local clock.
A simple averaging algorithm
Step 3. Update the clock using the
that guarantees mutual
average of these values.
consistency |c(i) - c(j)| < 
Resynchronization interval will depend on
the drift rate.
Internal synchronization
Lamport and Melliar-Smith’s
Assume n clocks, at most t are faulty
averaging algorithm handles
byzantine clocks too
Step 1. Read every clock in the system.
c                         c-
Step 2. Discard outliers and substitute them by the
i               j
value of the local clock.
Step 3. Update the clock using the average of
c+            c-2            these values.
k
Synchronization is maintained if   n > 3t
A faulty clocks exhibits 2-faced      Why?
or byzantine behavior
Internal synchronization
Lamport & Melliar-Smith’s
algorithm (continued)         The maximum difference between
the averages computed by two
c                       c-   non-faulty nodes is (3t/ n)
i             j

To keep the clocks synchronized,
c+          c-2
k
k                         3t/ n < 

So,    3t < n
Cristian’s method
External Synchronization

Client pulls data from a time server
Time
server         every R unit of time, where R <  / 2.
(why?)

For accuracy, clients must compute
the round trip time (RTT), and
compensate for this delay
(Too large RTT’s are rejected)
Network Time Protocol (NTP)
Time    Level 0               - least accurate
server
Level 1
Procedure call
Level 1
Level 1                     - medium accuracy
Peer-to-peer mode
- upper level servers use
this for max accuracy
Level 2

Level 2
Level 2

The tree can reconfigure itself if some node fails.
P2P mode of NTP
Let Q’s time be ahead of P’s time by .
Then

T2        T3
Q                               T2 = T1 + TPQ + 
T4 = T3 + TQP - 

y = TPQ + TQP = T2 +T4 -T1 -T3 (RTT)
P
T1                  T4         = (T2 -T4 -T1 +T3) / 2 - (TPQ - TQP) / 2

x          Between y/2 and -y/2

So, x- y/2 ≤  ≤ x+ y/2

Ping several times, and obtain the smallest value of y. Use it to calculate 
Problems with Clock
1. What problems can occur when a clock value is

2. What problems can occur when a clock value is
moved back from 180 to 175?
Sequential and Concurrent events

Sequential = Totally ordered in time.
Total ordering is feasible in a single process that has
only one clock. This is not true in a distributed system.

Two issues are important here:
 How to synchronize physical clocks ?

 Can we define sequential and concurrent events
without using physical clocks, since physical clocks cannot be perfectly
synchronized?
Causality

Causality helps identify sequential and concurrent
events without using physical clocks.

Joke  Re: joke ( implies causally ordered before or
happened before)

Local ordering: a  b  c (based on the local clock)
Defining causal relationship

Rule 1. If a, b are two events in a single process P, and
the time of a is less than the time of b then a  b.

Rule 2. If a = sending a message, and b = receipt of
that message, then a  b.

Rule 3.      abbc ac
Example of causality

ad    since   (a  b  b  c  c  d)                 h
d
ed    since   (e  f  f  d)             t   g       c
i
f
m           b
(Note that  defines a PARTIAL order).     e
a       e

Is g f or f g? NO.They are concurrent.           P       Q       R

.

Concurrency = absence of causal order
Logical clocks
Each process maintains its logical
LC is a counter. Its value respects
clock as follows:
causal ordering as follows

LC1. Each time a local event takes
a  b  LC(a) < LC(b)
place, increment LC.
LC2. Append the value of LC to outgoing
Note that LC(a) < LC(b) does             messages.
NOT imply a  b.                      LC3. When receiving a message, set LC
to 1 + max (local LC, message LC)
Total order in a distributed
system
Total order is important for some      Let a, b be events in processes
applications like scheduling (first-      i and j respectively. Then
come first served). But total order
does not exist! What can we do?        a << b iff
-- LC(a) < LC(b) OR
-- LC(a) = LC(b) and i < j
Strengthen the causal order  to
define a total order (<<) among
a  b  a << b, but the
events. Use LC to define total
converse is not true.
order (in case two LC’s are equal,
process id’s will be used to break
the tie).

The value of LC of an event is called its timestamp.
Vector clock
Causality detection can be an
important issue in applications                 joke

like group communication.          A                            B

Re: joke

Logical clocks do not detect            joke              Re: joke
causal ordering. Vector clocks
do.                                                C

a  b  VC(a) < VC(b)             C may receive Re:joke
Implementing VC
{Sender process i}                ith component of VC

1. Increment VC[i].
1,1,0           2,1,0
0,0,0
2. Append the local VC to every outgoing
message.
0,0,0
0,1,0                                           2,2,4
3. When a message with a vector timestamp T
0,0,0
arrives    from   i,   first   increment   the       jth
0,0,1        0,0,2           2,1,3   2,1,4
component VC[j] of the local vector clock,
and then update the local vector clock as
follows:

k: 0 ≤ k ≤N-1:: VC[k] := max (T[k], VC[k]).
Vector clocks
Example
0    1   2   3    4   5   6    7

Vector Clock of an event in a system of 8 processes
[3, 3, 4, 5, 3, 2, 1, 4] <
Let a, b be two events.                                  [3, 3, 4, 5, 3, 2, 2, 5]

Define. VC(a) < VC(b) iff                            But,

i : 0 ≤ i ≤ N-1 : VC(a)[i] ≤ VC(b)[i], and
[3, 3, 4, 5, 3, 2, 1, 4] and
 j : 0 ≤ j ≤ N-1 : VC(a)[j] < VC(b)[j],                [3, 3, 4, 5, 3, 2, 2, 3]
VC(a)       < VC(b)  a  b                             are not comparable

Causality detection
Mutual Exclusion

p0         CS

p1         CS

p2         CS

p3         CS
Why mutual exclusion?
Some applications are:

1. Resource sharing
2. Avoiding concurrent update on shared data
3. Controlling the grain of atomicity
4. Medium Access Control in Ethernet
5. Collision avoidance in wireless broadcasts
Specifications
ME1. At most one process in the CS. (Safety property)
ME3. Every process trying to enter its CS must eventually succeed.
This is called progress. (Liveness property)

Progress is quantified by the criterion of bounded waiting. It measures
a form of fairness by answering the question:
Between two consecutive CS trips by one process, how many times
other processes can enter the CS?

There are many solutions, both on the shared memory model and the
message-passing model
Message passing solution:
Centralized decision making
Client
do true 
send request;
enter critical section (CS)
busy: boolean                           send release;
queue                                 <non-CS activities>
od
req                   release
request received and busy  enqueue sender
release received and queue is empty  busy:= false
to the head of the queue
od

- Centralized solution is simple.
- But the server is a single point of failure. This is BAD.
- ME1-ME3 is satisfied, but FIFO fairness is not guaranteed. Why?

Can we do better? Yes!
Decentralized solution 1:
Lamport’s algorithm
{Life of each process}
1. Broadcast a timestamped request to all.
2.   Request received  enqueue sender in local Q;.                Q0                       Q1
0               1
Not in CS  send ack
In CS  postpone sending ack (until exit
from CS).
3. Enter CS, when
2               3
Q2                       Q3
(ii) You have received ack from all processes
4. To exit from the CS,                                         Completely connected topology
(i) Delete the request from Q, and                    Can you show that it satisfies
all the properties (i.e. ME1, ME2,
(ii) Broadcast a timestamped release                  ME3) of a correct solution?
5. Release received  remove sender from local Q.

```
DOCUMENT INFO
Shared By:
Categories:
Tags:
Stats:
 views: 0 posted: 2/25/2012 language: pages: 28