Synchronization - PowerPoint PPT Presentation

1 / 45
About This Presentation
Title:

Synchronization

Description:

Synchronization Clock Synchronization and algorithm – PowerPoint PPT presentation

Number of Views:86
Avg rating:3.0/5.0
Slides: 46
Provided by: SteveA231
Category:

less

Transcript and Presenter's Notes

Title: Synchronization


1
Synchronization
  • Clock Synchronization
  • and algorithm

2
Synchronization
  • Concentrate on how process can synchronize
  • Not simultaneously access a shared resources.
  • Multiple process can agree on the ordering of
    event/access the shared resources
  • E.g process p1 should send message m1 prior to
    pcs p2 and message m2
  • Synchronization in DS is much more difficult
    rather that in uniprocessor/multiprocessor system

3
Use of time in distributed systems
4
(No Transcript)
5
Clock Synchronizationmake example
  • When each machine has its own clock, an event
    that occurred after another event may
    nevertheless be assigned an earlier time.

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

7
Cristians Algorithm
  • Assume one machine (the time server) has
  • a WWV receiver and all other machines are
  • to stay synchronized with it.
  • Every specific seconds, each machine sends a
    message to the time server asking for the current
    time.
  • ! Time server responds with message containing
    current time, CUTC.

8
Cristian's Algorithm
  • Getting the current time from a time server.

9
Cristian's Algorithm
  • A major problem the sender clock/client is fast
    " arriving value of CUTC from the time server
    will be smaller than clients current time, C.
  • ! What to do?
  • ! One needs to gradually slow down client clock
    by adding less time per tick.
  • Normally each interrupt add 10msec
  • gt
  • 9msec per tick.
  • or
  • add 11 msec per tick to advance the time

10
Cristians Algorithm
  • Minor problem
  • the one-way delay from the server to client is
    significant and may vary considerably.
  • What to do?
  • Measure this delay and add it to CUTC.
  • The best estimate of delay is (T1 T0)/2 for the
    message propagation time.
  • Can subtract off I (the server interrupt handling
    time).
  • one way propagation time (T1 T0-I)/2
  • !

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

12
Averaging Algorithm
  • Every R seconds, each machine broadcasts its
    current time.
  • ! The local machine collects all other
  • broadcast time samples during some
  • time interval, S.
  • ! The simple algorithm algorithm
  • the new local time is set as the average of
    the value received from all other machines.

13
Averaging Algorithms
  • ! A slightly more sophisticated algorithm
    Discard
  • the m highest and m lowest to reduce the effect
    of a
  • set of faulty clocks. Average the rest.
  • ! Another improved algorithm Correct each
  • message by adding to the received time an
    estimate
  • of the propagation time from the source.
  • ! One of the most widely used algorithms in the
  • Internet is the Network Time Protocol (NTP).

14
Logical Clocks
  • All machine must agree with one time/clock.
  • Logical clock no matter its not the same to the
    real time.
  • Lamport all process must agree with the
    sequence of event occurs
  • Either input.c is older or newer then input.o

15
Logical Clock and Lamport Timestamp
  • Logical clocks
  • Order of events matters more than absolute time
  • E.g. UNIX make input.c input.o
  • Lamport timestamp
  • Synchronize logical clocks
  • Happens-before relation
  • A -gt B A happens before B
  • Two cases which determine happens-before
  • A and B are in same process, and A occurs before
    B a -gt b
  • A is send-event of message M, and B is
    receive-event of same message M
  • Transitive relation
  • If A -gt B and B -gt C, then A-gt C
  • Concurrent events
  • Neither A -gt B nor B -gt A is true

16
Lamport Algorithm
  • Assign time value C(A) such that
  • If a happens before b in the same process, C(a) lt
    C(b)
  • If a and b represent the sending and receiving of
    a message, C(a) lt C(b)
  • Lamport Algorithm
  • Each process increments local clock between any
    two successive events
  • Message contains a timestamp
  • Upon receiving a message, if received timestamp
    is ahead, receiver fast forward it clock to be
    one more than sending time
  • Extension for total ordering
  • Requirement For all distinctive events a and b,
    C(a) ? C(b)
  • Solution Break tie between concurrent events
    using process number

17
Lamport Timestamp Example
  • Clocks run at different rate

18
Solutions
  • Message C From process 2 leaves at 60 gt must
    arrive at 61 or later

Correct clocks using Lamports Algorithm
19
Example Totally-Ordered Multicast
  • Application of Lamport timestamps
  • Scenario
  • Replicated accounts in New York(NY) and San
    Francisco(SF)
  • Two transactions occur at the same time and
    multicast
  • Current balance 1,000
  • Add 100 at SF
  • Add interest of 1 at NY
  • Possible results ??

20
Inconsistent State
1000.0110001010
10001001100
1010100 1110
1100.0111001111
21
Totally Ordered Multicast
  • Use Lamport timestamps
  • Algorithm
  • Message is time stamped with senders logical
    time
  • Message is multicast (including sender itself)
  • When message is received
  • It is put into local queue
  • Ordered according to timestamp
  • Multicast acknowledgement
  • Message is delivered to applications only when
  • It is at head of queue
  • It has been acknowledged by all involved
    processes
  • Lamport algorithm (extended) ensures total
    ordering of events
  • All processes will eventually have the same copy
  • of the local queue consistent global ordering.

22
  • Global state
  • local state of each process
  • eg database records (not temporary records)
  • with messages are in transit ( have been sent
    but not delivered)

23
Distributed Snapshot Intro
  • Reflects the state in which a system might have
    been
  • Chandy and Lamport (1985)
  • If it is recorded that Q recd a msg from P
  • then it should also be recorded that P sent it
  • However, If Ps sending is recorded, but not
    that of Q receiving it, thats allowed
  • Assumption processes are connected to each
    other via uni-directional point-to-point channels
  • Any process can initiate the algorithm
  • Use a marker with the message to initiate
    communication

24
Global State (1)
  1. A consistent cut
  2. An inconsistent cut

25
Global State (2)
  1. Organization of a process and channels for a
    distributed snapshot

26
ALGORITHM
  • Any process can initiate the algorithm.
  • 2. Initiating process P starts by recording its
    own local state. Then it sends a marker
  • along each of its outgoing channels.
  • 3. When a process Q receives a marker through an
    incoming channel C
  • If Q hasnt already saved its local state,
  • Q first records its local state and then sends
    a marker along each of its own outgoing
    channels.
  • If Q has already recorded its state earlier,
    the marker on channel C is an indicator that Q
  • should record the state of the channel.
  • 4. A process is done when it has received a
    marker on each of its coming channels. The
  • local state of the process and the state of each
    of its incoming channels are sent to the
  • initiating process.

27
Global State (3)
  • Process Q receives a marker for the first time
    and records its local state
  • Q records all incoming message
  • Q receives a marker for its incoming channel and
    finishes recording the state of the incoming
    channel

28
  • When Q finishes its role in the snapshot it can
    send one of the two messages to it predecessor
  • DONE or CONTINUE
  • A DONE message is sent if
  • All of Qs successors have returned a DONE
  • Q has not received any message
  • ElSE
  • CONTINUE message will sent to its predecessor

29

Election Algorithms
  • Need to find one process that is the coordinator
  • Assume
  • Each process has a unique identifier
  • network address for example
  • One process per machine
  • Every process knows the process number of every
    other process
  • Processes dont know which processes are down
    and which ones are still running
  • End result of the algorithm all processes agree
    on who is the new coordinator/leader
  • Bully algorithm Ring Algorithm

30
Bully Algorithm (Garcia-Molina)
  • A process notices that coordinator is not
    responding
  • it starts an election (any process can start
    one)
  • Election algorithm
  • P sends an ELECTION message to processes with
    higher numbers
  • If no one responds, P wins the election
  • If some process with higher process number
    responds
  • Ps job is done, that process takes over
  • the receiver sends an OK message to P
  • receiver starts an election process
  • Eventually all processes give up, except one
  • This process sends out a message saying that it
    is the new COORDINATOR
  • A process that was down, when it comes back up
    starts a new election of its own

31
The Bully Algorithm (1)
  • The bully election algorithm pcs 7 as
    coordinatorgt crashed
  • Process 4 is the first on noticed the crashed gtgt
    send ELECTION process to 5, 6 and 7 (higher pcs)
  • Process 5 and 6 respond, telling 4 to stop
  • Now 5 and 6 each hold an election

32
The Bully Algorithm (2)
  1. Process 6 tells 5 to stop
  2. Process 6 wins and tells everyone

33
Ring Algorithm (1)
  • Does NOT use a token
  • Assume
  • processes are ordered
  • each process knows its successor
  • and the successors successor, and so on (needed
    in case of failures)
  • Process P detects that the coordinator is dead
  • sends an ELECTION message to its successor
  • includes its process number in the message
  • each process that receives it
  • adds its own process number and then forwards it
    to its successor
  • eventually it gets back that message
  • now what does it do?

34
Ring Algorithm (2)
  • The process that initiated it, then sends out a
    message saying COORDINATOR
  • the process with highest number in list is the
    leader
  • when this comes back, then process P deletes it

35
A Ring Algorithm(1)
  • Election algorithm using a ring.

We start with 6 processes,     connected in a
logical ring.
Process 6 is the leader,     as it has the
highest number.
36
A Ring Algorithm(2)
Process 6 fails.
37
A Ring Algorithm(3)
Process 3 notices that Process 6 does not respond
So it starts an election, sending a message
containing its id to the next node in the ring.
38
A Ring Algorithm(4)
Process 5 passes the message on,     adding its
own id to the message
39
A Ring Algorithm(5)
Process 0 passes the message on,     adding its
own id to the message.
40
A Ring Algorithm(6)
Process 1 passes the message on,     adding its
own id to the message.
41
A Ring Algorithm(7)
Process 4 passes the message on,     adding its
own id to the message
42
A Ring Algorithm(8)
When Process 3 receives the message back,     it
knows the message has gone around the ring,    
    as its own id is in the list.
Picking the highest id in the list,     it
starts the coordinator message         "5 is the
leader" around the ring
43
A Ring Algorithm(9)
Process 5 passes on the coordinator message
44
A Ring Algorithm(10)
Process 0 passes on the coordinator message.
45
A Ring Algorithm(11)
Process 1 passes on the coordinator message.
Write a Comment
User Comments (0)
About PowerShow.com