# Chapter 5 Synchronization - PowerPoint PPT Presentation

Title:

## Chapter 5 Synchronization

Description:

### Can all clocks in a distributed system be synchronized ? ... How do we synchronize them with real-world clocks ... Synchronization ... – PowerPoint PPT presentation

Number of Views:145
Avg rating:3.0/5.0
Slides: 41
Provided by: maria69
Category:
Tags:
Transcript and Presenter's Notes

Title: Chapter 5 Synchronization

1
Chapter 5Synchronization
• PresenterMaria Riaz

2
Sequence of Presentation
• Synchronization
• Clock Synchronization
• Logical Clocks
• Global State
• Election Algorithms
• Mutual Exclusion
• Distributed Transactions

3
Synchronization Why we need it !
• Stand-alone System
• Distributes System
• Ordering of Events
• Each node in a distributed system has separate
local clock
• Notion of physical time might differ among
various nodes of the system

4
- Clock Synchronization -
• Problem due to different time values at different
nodes
• When each machine has its own clock, an event
that occurred after another event may
nevertheless be assigned an earlier time

5
Physical Clocks (1)
• Can all clocks in a distributed system be
synchronized ?
• If we start all clocks in the system with same
initial value, will they remain synchronized for
the rest of their operations ?
• Some terminology
• Skew instantaneous difference between readings
• Drift different rates of counting time
• physical variations of underlying oscillators
• variance with temperature
• even extremely small differences accumulate over
a large number of oscillations
• Drift Rate difference in reading bet. a clock
and a nominal perfect clock per unit of time
measured by the reference clock
• 10-6 seconds/sec for quartz crystals
• 10-7 - 10-8 seconds/sec for high precision quartz
crystals
• Problem
• How do we synchronize them with real-world clocks
• How do we synchronize the clocks with each other

6
Physical Clocks (2)
• Some methods to measure time
• Mean solar second measuring a large numbers of
day -- taking average -- dividing by 86400
• TAI (International Atomic Time) the mean number
of ticks of the cesium 133 clocks (since
1/1/1958) divided by 9,192,631,770
• Very small drift rate 10-13 seconds/second
• UTC broadcast by NIST from Fort Collins,

7
Clock Synchronization Algorithms (1)
• The relation between clock time and UTC when
clocks tick at different rates
• maximum drift rate (?)
• every ?t seconds, the worst case drift between
two clocks will be at most 2??t
• to guarantee two clocks never differ by more than
?, the clocks must re-synchronize every ?/2?
seconds

8
Clock Synchronization Algorithms (2)
• Centralized Algorithms
• Cristians Algorithm (1989)
• Berkeley Algorithm (1989)
• Decentralized Algorithms
• Averaging Algorithms (e.g. NTP)
• Multiple External Time Sources

9
Cristians Algorithm
• Assume one machine (the time server) has a WWV
receiver and all other machines are to stay
synchronized with it.
• Every ?/2? seconds, each machine sends a message
to the time server asking for the current time.
• Time server responds with message containing
current time, CUTC.
• Problem
• time must never run backward

10
Berkeley Algorithm
1. The time daemon asks all the other machines for
their clock values.
2. The machines answer and the time daemon computes
the average.
3. The time daemon tells everyone how to adjust
their clock.

11
Averaging Algorithms
• At the beginning of each interval, every machine
broadcasts the current time according to its
clock
• Then it starts a local timer to collect all other
broadcasts that arrive during some interval S
• The simplest algorithm is just to average the
values from all other machines
• A slightly more sophisticated algorithm
Discard the m highest and m lowest to reduce the
effect of a set of faulty clocks
• Another improved algorithm Correct each
estimate of the propagation time from the ith
source
• extra probe messages are needed to use this
scheme
• One of the most widely used algorithms in the
Internet is the Network Time Protocol (NTP)

12
- Logical Clocks -
• Mostly absolute time is not important rather
relative time is of significance
• Internal consistency and ordering of events
• If two process dont interact ? no need for
synchronization between them
• A logical clock is a
• Monotonically increasing SW counters (COULOURIS)
• Clocks on different computers that are somehow
consistent (LAMPORT)
• Potential Requirements for logical clocks
• Timestamps C(a), C(b)
• If a happens before b in the same process, C(a) lt
C(b).
• a ? b gt C(a) lt C(b)
• If a and b represent the sending and receiving of
a message, respectively, C(a) lt C(b).
• For all distinctive events a and b, C(a) ? C(b).
• Two methods for assigning logical timestamps
• Lamports Timestamps
• Vector Timestamps

13
Lamports Timestamps (1)
• Lamport defined a relation happens before. a ?
b a happens before b (1978)
• Each Process has local clock LCi
• with each local event e LCi LCi 1 e
• with each sending of a message by process Pi LCi
LCi 1 send (LCi,m)
• with each reception of a message (M,LCm) by Pj
LCj MAX(LCm, LCj ) LCj LCj 1

14
Lmaports Timestamps (2)
• Can be used to implement totally ordered
multicast
• A multicast operation by which all messages are
delivered in the same order to each receiver

15
Vector Timestamps
• Each process Pi has its own vector clock Ci
• Ci n-dimensional vector (n number of
processes)
• Notation Cij the timestamp of the last event
in Pj by which Pi has potentially been effected
• Initially
• all ci 0
• Increment Ci
• -Events
• Send msg

16
- Global State -
• Like a distributed snapshot reflecting a state
in which the system might have been
• represents the last event recorded for each
process
• Graphically represented by a cut
• Consistent for every received message, the
sender can be identified
• Cause ? Effect

17
Global State (2)
• Organization of a process and channels for a
distributed snapshot
• Process Q receives a marker (start) for the first
time and records its local state
• Q records all incoming message
• Q receives a marker (end) for its incoming
channel and finishes recording the state of the
incoming channel
• final recorded state

18
- Election Algorithms -
• Election algorithms
• algorithms for electing a coordinator (using this
as a generic name for the special process)
• attempt to locate the process with the highest
process number and designate it as coordinator
• Bully Algorithm
• Ring Algorithm
• Goal
• ensure that when an election starts, it concludes
with all processes agreeing on who the new
coordinator is to be

19
Bully Algorithm
• A process P detects failure of coordinator and
holds an election to be the coordinator
• All process with ID gt P response
• If P receives such a response, it will step back
• Processes having ID gt P can hold electionsand
repeat same procedure
• If no response from any process with higher ID,
election holder becomes the new coordinator
• Example
• Process 4 holds election
• Process 5 and 6 respond, telling 4 to stop
• Now 5 and 6 each hold an election
• Process 6 tells 5 to stop
• Process 6 wins and tells everyone

20
Ring Algorithm
• Process detects failure of coordinator
• Send message to neighbor with its ID
• Neighbor adds its ID and pass along
• When all process have added their ID, the one
with highest ID becomes the coordinator
• The message is rotated once again so everyone
knows

21
- Mutual Exclusion -
• Centralized Algorithm
• Distributed Algorithm
• Token Ring Algorithm

22
Centralized Algorithm
1. Process 1 asks the coordinator for permission to
enter a critical region. Permission is granted
2. Process 2 then asks permission to enter the same
critical region. The coordinator does not reply
3. When process 1 exits the critical region, it
tells the coordinator, when then replies to 2

23
Distributed Algorithm
1. Two processes want to enter the same critical
region at the same moment
2. Process 0 has the lowest timestamp, so it wins
3. When process 0 is done, it sends an OK also, so 2
can now enter the critical region

24
Token Ring Algorithm
• unordered group of processes on a network
• logical ring constructed in software
• A token is passed along the ring to allow access
to the critical section

25
Comparison
Algorithm Messages per entry/exit Delay before entry (in message times) Problems
Centralized 3 2 Coordinator crash
Distributed 2 ( n 1 ) 2 ( n 1 ) Crash of any process Group communication
Token ring 1 to ? 0 to n 1 Lost token, process crash
• A comparison of three mutual exclusion algorithms

26
- Distributed Transactions -
• Basic (Flat) Transactions Limitations
• Alternatives
• Distributed Transactions
• Nested Transactions
• Problems
• Concurrency Control
• Synchronization

27
The Transaction Model (1)
• Updating a master tape is fault tolerant

28
The Transaction Model (2)
Primitive Description
BEGIN_TRANSACTION Make the start of a transaction
END_TRANSACTION Terminate the transaction and try to commit
ABORT_TRANSACTION Kill the transaction and restore the old values
WRITE Write data to a file, a table, or otherwise
• Examples of primitives for transactions

29
ACID - Four Characteristics
• Atomic to the outside world, the transaction
happens indivisibly
• Consistent the transaction does not violate
system invariants
• Isolated concurrent transactions do not
interfere with each other
• Durable once a transaction commits, the changes
are permanent

30
Limitations of Flat Transactions
• Main limitation do not allow partial results to
be committed or aborted
• updating all of the hyperlinks to a webpage W,
which moved to a new location

BEGIN_TRANSACTION reserve WP -gt JFK reserve JFK -gt Nairobi reserve Nairobi -gt MalindiEND_TRANSACTION (a) BEGIN_TRANSACTION reserve WP -gt JFK reserve JFK -gt Nairobi reserve Nairobi -gt Malindi full gt ABORT_TRANSACTION (b)
31
Classification of Transactions
1. A nested transaction
2. A distributed transaction

32
Private Workspace
• Make a copy of the original workspace and perform
all operation in the copied private space
before committing
• read only ? no need for private copy

a) The file index and disk blocks for a
three-block file b) The situation after a
transaction has modified block 0 and appended
block 3 b) After committing
33
x 0 y 0 BEGIN_TRANSACTION x x 1 y y 2 x y y END_TRANSACTION (a) Log x 0 / 1 (b) Log x 0 / 1 y 0/2 (c) Log x 0 / 1 y 0/2 x 1/4 (d)
• a) A transaction
• b) d) The log before each statement is executed

34
Concurrency Control (1)
• General organization of managers for handling
transactions

35
Concurrency Control (2)
• General organization of managers for handling
distributed transactions

36
Synchronization
• Two operations are serializable if the order of
operations does not change the outcome i.e., the
operations do not conflict
• properly schedule conflicting operations (two
• Mechanism for synchronization
• Mutual Exclusion mechanisms on shared data (i.e
locking)
• Two-Phase Locking
• Strict Two-Phase Locking
• Explicitly ordering operations using timestamps
• Pessimistic Timestamp Ordering

37
Two-phase locking
• A transaction T is granted a lock if there is no
conflict
• The scheduler will never release a lock for data
item x, until the data manager acknowledges it
has performed the operation for which the lock
was set
• Once the scheduler has released a lock on behalf
of a transaction T, it will never grant another
lock on behalf of T

38
Strict two-phase locking
• In centralized 2PL a single site is responsible
for granting and releasing locks
• In primary 2PL each data item is assigned a
primary copy
• In distributed 2PL the schedulers on each
machine not only take care that locks are granted
and released, but also that the operation is
forwarded to the (local) data manager

39
Pessimistic Timestamp Ordering
• Concurrency control using Timestamps

40
Thank you !
• Questions ?