0% found this document useful (0 votes)
9 views10 pages

DC Mod3mu

The document compares various algorithms for leader election and mutual exclusion in distributed systems, highlighting the Bully and Ring algorithms for leader election, and Lamport's, Ricart-Agrawala's, and Maekawa's algorithms for mutual exclusion. It emphasizes the trade-offs between speed, message complexity, and scalability for each algorithm. Additionally, it discusses the importance of logical clocks and the Raymond's Tree-Based Algorithm for token-based mutual exclusion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views10 pages

DC Mod3mu

The document compares various algorithms for leader election and mutual exclusion in distributed systems, highlighting the Bully and Ring algorithms for leader election, and Lamport's, Ricart-Agrawala's, and Maekawa's algorithms for mutual exclusion. It emphasizes the trade-offs between speed, message complexity, and scalability for each algorithm. Additionally, it discusses the importance of logical clocks and the Raymond's Tree-Based Algorithm for token-based mutual exclusion.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

DC_mod3mu

Q3. Comparison Between Bully Election Algorithm & Ring Algorithm

Use Suitable for smaller networks where quick Suitable for stable systems where processes
Case leader election is needed. do not fail frequently.

Feature Bully Algorithm Ring Algorithm

Election Initiation Any process can start the election. Only one process starts the election.

The highest-numbered process The process with the highest ID in the


Selection Method
always wins. ring wins.

Message Complexity O(N²) in worst case. O(N) in best case, O(2N) in worst case.

Coordinator The new leader immediately sends a The new leader sends a COORDINATOR
Announcement COORDINATOR message. message through the ring.

Process Failures If the highest process fails, another If multiple processes fail, the ring may
Handling election starts. break.

Not scalable due to high message


Scalability More scalable as it has fewer messages.
exchange.

Faster but expensive in terms of


Speed Slower due to message circulation.
messages.

Systems with predictable topology


Best for Systems with infrequent failures.
(ring-based networks).

4. Conclusion

 The Bully Algorithm is better for small systems where fast election is needed but has high
message complexity.

 The Ring Algorithm is more efficient in larger systems but slower due to message
circulation.

 The choice depends on the system’s needs – Bully for fast, priority-based selection, and
Ring for fair and efficient elections.

Final Verdict:

 Bully Algorithm → Priority-based, Fast but Expensive

 Ring Algorithm → Fair, Scalable but Slower


Q4.Difference Between Logical Clock and Vector Clock

Feature Logical Clock (Lamport Clock) Vector Clock

A single integer counter per process, A vector of counters, one for each
Definition
incremented with each event. process, maintaining causality.

A vector of timestamps (e.g., VC(P) =


Representation A single scalar value (e.g., LC(P) = 5).
[2,5,3]).

Ensures happens-before (→) relation Detects causal ordering and can identify
Event Ordering
but cannot detect concurrency. concurrent events.

Sender increments its clock and sends it.


Sender increments its clock, sends the
Receiver updates its clock to the
Message Passing entire vector, and receiver updates each
maximum of the received and local clock
entry to the maximum value received.
+1.

Concurrency
Cannot detect concurrent events. Can detect concurrent events (`A
Detection

Memory High (vector of size n, where n is the


Low (single integer per process).
Overhead number of processes).

O(n) (entire vector updated and


Complexity O(1) (only one timestamp updated).
compared).

Maintaining causality, detecting


Ordering of events in distributed
Use Case conflicts in version control (Git,
databases, distributed logs.
DynamoDB).

Example:

 Logical Clock (Lamport):


If P1 sends a message to P2, timestamps are:

o P1: LC = 5 → Sends message

o P2 receives it and updates LC = max(3,5) +1 = 6

 Vector Clock:
If P1 sends a message to P2, vector timestamps might be:

o P1: [2,0,0] → Sends message

o P2 receives it and updates to max([2,0,0], [1,1,0]) → [2,1,0]

Key Takeaways:

 Logical clocks are simpler but lack concurrency detection.

 Vector clocks provide better causality tracking but require more memory and computation
Q5. Comparison of Lamport’s, Ricart-Agrawala’s, and Maekawa’s Non-Token-Based Mutual
Exclusion Algorithms

Ricart-Agrawala’s
Feature Lamport’s Algorithm Maekawa’s Algorithm
Algorithm

Uses timestamps to order Uses direct request-reply Uses quorum-based


Approach requests and ensure messages for access communication for better
fairness. control. scalability.

Message O(3N) (request, reply, O(√N) (requesting only a


O(2(N-1)) (request, reply).
Complexity release). subset).

Number of
Messages per 3N messages. 2(N-1) messages. 2√N messages.
Request

Process requests access


Process sends a request to Process requests access
Request from all others and enters
all others and waits for N-1 from a quorum (subset) of
Handling CS only after receiving all
replies. processes.
replies.

Replies are sent based on If a process is not in CS, it Replies come only from
Reply timestamp priority; replies immediately; the quorum group,
Mechanism delayed if another process otherwise, it delays the reducing message
is in CS. reply. overhead.

Maintains fairness but may


Ensures FIFO ordering Less fairness due to
Fairness not follow strict FIFO
using timestamps. quorum-based decisions.
ordering.

Similar to Lamport’s but Higher concurrency, as


Low (only one process can
Concurrency optimized due to fewer only quorum members
access CS at a time).
messages. grant access.

Low – Failure of a process Moderate – Some failures


Failure Low – If a process crashes,
before sending replies are tolerable due to
Tolerance election is needed.
blocks others. quorum overlap.

High – Requires
Low – Requires Moderate – Still needs
communication with only
Scalability communication with all global communication but
a subset, making it more
processes. fewer messages.
scalable.

No deadlocks (requests are


Deadlock No deadlocks (timestamps Possible deadlocks due to
prioritized based on
Possibility resolve conflicts). quorum overlaps.
timestamps).

Conclusion
Best Choice For Algorithm

Strict FIFO Ordering Lamport’s Algorithm

Lower Message Complexity Ricart-Agrawala’s Algorithm

Scalability & Concurrency Maekawa’s Algorithm

 Lamport’s Algorithm is best when fairness and ordering are critical.

 Ricart-Agrawala’s Algorithm is more efficient than Lamport’s.

 Maekawa’s Algorithm is best for large distributed systems due to lower message
complexity.

Need for Election Algorithm in Distributed Systems

1. No Shared Memory:

o In distributed systems, each computer (or node) has its own memory.

o They communicate only through message passing over a network.

2. Need for a Coordinator:

o Some tasks (e.g., synchronization, resource management) need a central


coordinator.

o This coordinator helps organize and manage activities among all nodes.

3. Equal Status of Nodes:

o All nodes in the system are equal (uniform); any one can act as a coordinator.

o A leader (coordinator) is chosen among them when needed.

4. Handling Failures:

o If the current coordinator fails or crashes, the system must elect a new one.

o This is done using an Election Algorithm.

5. What Election Algorithm Does:

o It selects one active node to become the new coordinator.

o The chosen node is usually the one with the highest priority or ID.

6. Ensures Continuity:

o Prevents system breakdown when a coordinator fails.

o Ensures that system functions (like clock sync, task assignment) continue smoothly.

7. Example Use Case:


o Berkeley Clock Synchronization: The elected coordinator synchronizes the clocks of
all processes.

Summary:

Election algorithms help distributed systems choose a leader (coordinator) when needed, especially
after failures, ensuring reliability, order, and coordination among independent nodes.

Logical Clocks:

① If two processes don’t interact, there is no need to synchronize them.

② What usually matters is that processes agree on the order in which events occur rather than the
real-time at which they occurred.

① Absolute time is not important.


② Use logical clocks.

 Logical time is not based on timing but on the ordering of events.

 They can only advance/forward, not in reverse.

 Non-interacting processes can’t share a logical clock.

 Computers generally obtain logical time using interrupts to update a software clock.
The more interrupts, the higher the overhead.

 The most common logical clock synchronization edge for D.S. (Distributed Systems) is
Lamport’s algorithm.
It is used in situations when ordering is important, not time.

Here is the handwritten content from the image in clean text format:

 All co-operating processes can agree on order of events.

 Physical clock depends on time of day.

 No central time source.

 Each system maintains its own logical clock.

 No total ordering of events.

 Assign sequence number to messages.


 No concept of happened-when.

Happened-before:

a→b

(message sent → message receipt)

Event a happened before event b.

If a → b and b → c, then a → c (transitive property).


Time of a < time of b.

Assign "clock" value to each event:

If a → b then clock(a) < clock(b)


Since time can’t run backward.

If a and b occur on different processes that do not exchange messages, then neither a → b
nor b → a are true.
Then, they are concurrent events.

The processes which are participating in communication are using it.


As well, events belonging to each process are participating — then give ordering.

If a & b are events in the same process, a occurs before b, then a → b is true.

Bad ordering is:

 e → h but 5 > 2

 f → k but 6 > 2

Lamport's Algorithm

Each message carries a timestamp of the sender’s clock when a message arrives:

 If receiver’s clock < message timestamp:


→ Set system clock to (message timestamp + 1)
 Else:
→ Do nothing.

 Clock must be advanced between any two events in the same process.

The algorithm for sender:

time = time + 1;

timestamp = time;

send (message, time_timestamp)

Raymond's Tree-Based Algorithm (Simple Version)

🔹 Step-by-step: Requesting the Token (to enter the Critical Section)


1. When a process (Pi) wants to enter the critical section:

o If it doesn’t have the token and its request queue is empty,


it sends a REQUEST to the node (process) it thinks holds the token.

o Then, it adds its own name to its request queue.

2. When any process (Pj) gets a REQUEST:

o It adds the request to its queue.

o If it hasn’t already forwarded a request, it sends a REQUEST to its own holder (up
the tree).

3. When the token holder (Pr) gets the REQUEST:

o It sends the token to the process at the front of its request queue.

o It updates its “holder” to point to that process.

4. When a process (Pj) gets the token:

o It removes the top entry from its request queue.

o It sends the token to the process in that entry.

o It updates its holder to point to the new token holder.

🔹 Execute the Critical Region (Simple Version)

✅ When a process Pi enters the critical section:

1. It can enter only if:

o It has the token, and

o Its own name is at the top of its request queue.

2. Before entering, it removes its own name from the queue and starts executing the critical
section.

✅ After Pi finishes executing the critical section:

1. If there are more requests in its queue:

o It removes the topmost request (next process).

o It sends the token to that process.

o It also updates its holder to point to that process.

2. If the queue is still not empty after that:

o It sends a REQUEST to the process now holding the token


(as it means more requests are pending).
This is an example of Raymond's Tree-Based Algorithm for mutual exclusion in a distributed system.
The diagram shows how a token is passed to grant permission to enter a critical section.

🌳 Concept Overview:

 A logical tree is formed with processes as nodes.

 Only one process holds the token (required to enter the critical section).

 Each node maintains:

o A Holder (H): the node from which it expects to get the token.

o A Request Queue (req-que): queue of requesting nodes.

🔍 Diagram Breakdown:

(a) P1 Holding Token, P3 is Requesting Token

 P1 currently holds the token, so it can enter the critical section.

 P3 wants the token, so:

o It sends a request to its holder: H3 = P2.

o P2 receives the request and forwards it to its holder: H2 = P1.

 Request chain: P3 → P2 → P1

 Each process updates its req-que to reflect who made the request:

o req-que of P3 = P3

o req-que of P2 = P3
o req-que of P1 = P2

(b) P3 After Receiving the Token

 P1 sends the token to P2.

 Then P2 forwards it to P3, because P3 initiated the request.

 Now P3 holds the token and can enter the critical section.

 The Holder (H) of all nodes gets updated to reflect the new path to token:

o H1 = P2

o H2 = P3

o H3 = P3

o H4 = P2

o H5 = P3

o H6 = P3

✅ Key Points:

 Only one token exists in the system.

 Requests travel up the tree toward the current holder.

 Token is passed down the request path.

 The tree is dynamically updated by changing holders to create shorter paths.

Would you like a summary note or diagram explanation for easier revision?

You might also like