0% found this document useful (0 votes)
12 views13 pages

Chap 3 DC

The document discusses synchronization algorithms for physical and logical clocks in distributed systems, including Cristian’s Algorithm, Berkeley Algorithm, Lamport’s Logical Clocks, and Vector Clocks. It also covers election algorithms like the Bully and Ring algorithms, as well as mutual exclusion algorithms such as Lamport's and Ricart-Agrawala. Each algorithm is explained with its steps, advantages, and potential issues related to synchronization and coordination among distributed processes.

Uploaded by

sumeetmaurya85
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views13 pages

Chap 3 DC

The document discusses synchronization algorithms for physical and logical clocks in distributed systems, including Cristian’s Algorithm, Berkeley Algorithm, Lamport’s Logical Clocks, and Vector Clocks. It also covers election algorithms like the Bully and Ring algorithms, as well as mutual exclusion algorithms such as Lamport's and Ricart-Agrawala. Each algorithm is explained with its steps, advantages, and potential issues related to synchronization and coordination among distributed processes.

Uploaded by

sumeetmaurya85
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

1.

Physical Clocks Algorithms


Physical clocks in distributed systems need synchronization to maintain
consistency in event ordering and coordination.
Clock Synchronization Algorithms:
1. Cristian’s Algorithm (UTC Time-Server Based)
o A client requests time from a time server with an accurate UTC
source.
o The server responds with the current UTC time.
o The client adjusts the received time by adding an estimate of the
one-way delay (assumed as half of the Round Trip Time - RTT).
o Issue: Asymmetric delays in communication paths can introduce
errors.

2. Berkeley Algorithm (Master-Client Model)


o A master node polls all other nodes for their local times.
o The master calculates the average time (excluding faulty nodes).
o It then instructs all nodes to adjust their clocks accordingly.
o The system gets synchronized, but not necessarily with UTC.
o Issue: Different nodes have different delays when communicating
with the master.
2. Logical Clocks Algorithms
Logical clocks are used when absolute time is not required, but event ordering
must be maintained.
Types of Logical Clocks:
1. Lamport’s Logical Clocks
o Defines a "happens-before" relation (→) between events.
o If an event a occurs before b in the same process, then a → b.
o If process P1 sends a message m to P2, then send(m) →
receive(m).
o Each process maintains a counter C.
o Before executing an event, C is incremented.
o When sending a message, its timestamp is C.
o When receiving a message, the local clock is updated to
max(C_local, timestamp of message) + 1.

Figure . (a) Three processes, each with its own clock. The clocks run at different
rates.
Figure (b) Lamport’s algorithm corrects the clocks.
2. Vector Clocks
o Each process maintains a vector VC[i] for n processes.
o VC[i] represents the knowledge of events from other processes.
o When an event occurs locally: VC[i]++
o When sending a message: The sender includes its vector clock.
o When receiving a message: VC = pairwise-max(VC, received_VC),
then VC[i]++.
o Provides causality tracking and helps in detecting concurrent
events.
3. Election Algorithms
Election algorithms help select a coordinator in distributed systems.
Types of Election Algorithms:
1. Bully Algorithm
o The process with the highest ID initiates the election.
o It sends an ELECTION message to all higher-ID processes.
o If no higher process responds, it wins and becomes the new
leader.
o If a higher process responds, it takes over the election.
o The new leader announces its victory to all processes.
2. Ring Algorithm
o Processes are arranged in a logical ring.
o A process detecting coordinator failure sends an election message
to its neighbor.
o Each node adds its ID and forwards the message.
o When the message returns to the sender, the highest ID is chosen
as the leader.
o The leader then broadcasts its identity.
4. Lamport Mutual Exclusion Algorithm
A distributed approach to mutual exclusion using logical timestamps.
Steps:
1. Requesting the Critical Section (CS)
o A process Pi sends a REQUEST message (timestamp, Pi) to all
processes.
o Each receiving process places the request in a queue and sends a
REPLY.
2. Executing the CS
o Pi enters CS only when:
▪ It has received replies from all other processes.
▪ Its request is the oldest in the queue.
3. Releasing the CS
o When Pi exits CS, it sends a RELEASE message to all.
o Each process removes Pi's request from its queue.
Performance:
5. Ricart-Agrawala Algorithm
A non-token-based mutual exclusion algorithm optimizing message overhead.
Steps:
1. Requesting the CS
o A process sends a request (timestamp, process ID) to all processes.
o If a process is not in CS and not requesting, it sends an OK reply.
o If in CS, it queues the request.
o If also requesting, it compares timestamps:
▪ Lower timestamp wins.
▪ The process with a higher timestamp waits.
2. Executing the CS
o A process enters CS after receiving OK from all processes.
3. Releasing the CS
o It sends OK messages to all waiting processes.
1. A process wanting to enter critical sections (cs) sends a message with (cs
name, process id, current time) to all processes (including itself).
2. When a process receives a cs request from another process, it reacts
based on its current state with respect to the cs requested. There are
three possible cases:
3. If the receiver is not in the cs and it does not want to enter the cs, it
sends an OK message to the sender.
4. If the receiver is in the cs, it does not reply and queues the request.
5. If the receiver wants to enter the cs but has not yet, it compares the
timestamp of the incoming message with the timestamp of its message
sent to everyone. {The lowest timestamp wins.} If the incoming
timestamp is lower, the receiver sends an OK message to the sender. If
its own timestamp is lower, the receiver queues the request and sends
nothing.
6. After a process sends out a request to enter a cs, it waits for an OK from
all the other processes. When all are received, it enters the cs.
7. Upon exiting cs, it sends OK messages to all processes on its queue for
that cs and deletes them from the queue.

You might also like