Module 4
Module 4
System Model
A system model in a distributed system refers to the set of assumptions and abstractions that
describe how different components of the system behave and interact with each other. Below
are several common models
Lamport’s Algorithm
When it comes to distributed mutual exclusion and synchronisation, Lamport's Algorithm is a
distributed algorithm that is used to create a logical sequence of events in a distributed
system. It is most famous for offering a way to create logical clocks for event tracking in
systems where real clocks might not be in sync.
Here are key aspects of Lamport’s algorithm:
1. Logical Clocks:
Lamport's logical clock is a way of ensuring the sequence of events in a distributed
system respects a partial order. It assigns a number to each event that occurs in the
system, ensuring that events are ordered in a way that respects causality.
Lamport introduced a counter for each process, and this counter is incremented every
time an event occurs in that process.
2. Event Ordering:
According to Lamport's algorithm, there are two important rules to maintain event
ordering:
1. If an event e1e1e1 happens before event e2e2e2 (causally), then the timestamp
of e1e1e1 must be less than the timestamp of e2e2e2.
2. If two events are unrelated (no causal relation), their timestamps are assigned
arbitrarily, as long as the first rule is still respected.
This way, Lamport's algorithm allows the system to maintain a logical ordering of events,
even if they occur at different times on different machines.
3. Mutual Exclusion with Lamport’s Algorithm:
Lamport’s algorithm can also be applied to mutual exclusion, i.e., ensuring that no two
processes access a shared resource simultaneously. The idea is to use the logical clocks to
communicate and request access to a shared resource.
The basic steps of Lamport’s mutual exclusion algorithm are as follows:
Requesting access: A process sends a request message to all other processes,
containing the timestamp of its current event (its logical clock).
Granting access: Each process compares the timestamp in the request message to its
own timestamp. If the incoming request has a smaller timestamp, the process queues
the request. If the timestamp is equal or greater, the process grants access to the
resource by sending a "grant" message back.
Critical Section: A process enters the critical section once it has received a grant from
all other processes.
Release: After finishing, the process sends a message to all other processes indicating
that it has left the critical section, allowing others to enter.
4. Clock Adjustment:
The logical clock of a process is adjusted as follows: If a process ppp receives a
message from another process qqq, the logical clock of ppp is updated to be the
maximum of its own logical clock and the timestamp in the message (to account for
events that may have happened earlier at qqq).
Advantages of Lamport’s Algorithm:
Simple and efficient for determining the order of events in distributed systems.
Provides a way to handle synchronization in distributed systems, where it is difficult
or impossible to have a common global clock.
Works in asynchronous systems with no shared memory or physical clocks.
Limitations:
Does not capture causality perfectly: Lamport’s logical clocks can distinguish if one
event happened before another, but they cannot always tell whether two events are
independent or concurrent if they don’t have a causal relation.
Potential for message delays: In a real-world system, message delays or network
partitions might complicate the precise order of events.
Ricart–Agrawala algorithm:
Performance
o For each CS execution, Ricart-Agrawala algorithm requires (N − 1) REQUEST
messages and (N − 1) REPLY messages.
o Thus, it requires 2(N − 1) messages per CS execution.
o Synchronization delay in the algorithm is T .
o Most mutual exclusion algorithms use a static approach to invoke mutual exclusion.
o These algorithms always take the same course of actions to invoke mutual exclusion
no matter what is the state of the system.
o These algorithms lack efficiency because they fail to exploit the changing conditions
in the system.
o An algorithm can exploit dynamic conditions of the system to improve the
performance.
o For example, if few sites are invoking mutual exclusion very frequently and other
sites invoke mutual exclusion much less frequently, then
A frequently invoking site need not ask for the permission of less frequently
invoking site every time it requests an access to the CS.
It only needs to take permission from all other frequently invoking sites.
o Singhal developed an adaptive mutual exclusion algorithm based on this observation.
o The information-structure of the algorithm evolves with time as sites learn about the
state of the system through messages.
Challenges
o The design of adaptive mutual exclusion algorithms is challenging:
o How does a site efficiently know what sites are currently actively invoking mutual
exclusion?
o When a less frequently invoking site needs to invoke mutual exclusion, how does it
do it?
o How does a less frequently invoking site makes a transition to more frequently
invoking site and vice-versa.
o How to insure that mutual exclusion is guaranteed when a site does not take the
permission of every other site.
o How to insure that a dynamic mutual exclusion algorithm does not waste resources
and time in collecting systems state, offsetting any gain.
Quorum-Based Mutual Exclusion Algorithms
Quorum-based mutual exclusion algorithms are different in the following two ways:
Step-by-Step Process:
1. Requesting Access:
o When a process PiP_iPi wants to enter the critical section, it sends a request
to its parent in the tree.
o The request message includes the process's logical timestamp and indicates
the process’s desire to enter the critical section.
2. Token Movement:
o The token starts at a process (initially, the root of the tree). The token is passed
down the tree according to the structure, allowing processes to access the
critical section one at a time.
o A process with the token grants the right to enter the critical section only to
the process holding the token.
o After completing the critical section, the token is passed down to one of the
child processes that has requested the critical section.
3. Release and Passing:
o Once a process PiP_iPi finishes executing in the critical section, it passes the
token to its children, if they have requested the critical section. If no child has
requested the critical section, the token is passed to the parent or another child.
4. Reclaiming the Token:
o If a process loses its connection to the tree (for example, if its parent fails or if
the tree structure is reorganized), the algorithm ensures that the token can still
be passed among remaining processes, maintaining mutual exclusion. A
failure detection and recovery mechanism is generally required to handle such
situations.
1. Mutual Exclusion:
o The algorithm ensures that only one process at a time can access the critical
section, thus preventing race conditions and maintaining data consistency.
2. Deadlock-Free:
o Since the token keeps circulating in the tree, a process that requests the critical
section will eventually receive the token. Hence, deadlock is avoided.
3. Starvation-Free:
o Every process that requests the critical section will eventually receive the
token, preventing starvation (where a process might be indefinitely denied
access to the critical section).
4. Fairness:
o The algorithm ensures fairness by passing the token according to a strict
ordering based on request times. This means processes are granted access to
the critical section in the order they request it.
5. Efficient Token Circulation:
o The token is passed in a way that limits unnecessary communication,
minimizing network overhead. Since only parent-child communication is
required, the algorithm is more efficient compared to broadcast-based
approaches.
6. Scalability:
o The tree structure allows the algorithm to scale well in large systems. The
token only needs to move within the tree, which is a more efficient
communication pattern compared to other algorithms where tokens might have
to be passed through all processes.
7. Fault Tolerance:
o While Raymond's algorithm assumes a reliable communication network and
no node failures, it is possible to implement fault-tolerant versions where the
system detects a failure and regenerates the token or reconfigures the tree
structure. However, failure handling adds complexity to the basic algorithm.