mod-2
mod-2
MOD-2
MOD-2
19 May 2024 05:33 PM
10.
Logical Clock
• In distributed systems, it is not possible to have global physical time
• It is possible to realize only an approximation of it .
• As asynchronous distributed computations make progress in spurts, it turns out that the logical time, which advances in jumps, is sufficient to capture the
fundamental monotonicity distributed systems property(order) associated with causality in
• Causality (or the causal precedence relation) among events in a distributed system is a powerful concept in reasoning, analysing, and drawing inferences about
a computation .
• The knowledge of the causal precedence relation among the events of processes helps solve a variety of problems in distributed systems .
• However, in distributed computing systems, the rate of occurrence of events is several magnitudes higher and the event execution time is several magnitudes
smaller.
• Consequently, if the physical clocks are not precisely synchronized, the causality relation between events may not be accurately captured
• Network Time Protocols which can maintain time accurate to a few tens of milliseconds on the Internet, are not adequate to capture the causality relation in
distributed systems.
• However, in a distributed computation, generally the progress is made in spurts and the interaction between processes occurs in spurts
• In a system of logical clocks, every process has a logical clock that is advanced using a set of rules.
• Every event is assigned a timestamp and the causality relation between events can be generally inferred from their timestamps.
• The timestamps assigned to events obey the fundamental monotonicity property; that is, if an event a causally affects an event b, then the timestamp of a is
smaller than the timestamp of b.
Downloaded
MOD-2 Page 1 by Arathi Pc ([email protected])
lOMoARcPSD|55070525
Scalar Time - Explain the rules used to update clocks in scalar time representation.
• Time domain is the set of non-negative integers.
• The logical local clock of a process pi and its local view of the global time are squashed into one integer variable Ci .
• Rules R1 and R2 to update the clocks are as follows:
○ R1: Before executing an event (send, receive, or internal), process pi executes the following: Ci := Ci + d (d > 0)
▪ In general, every time R1 is executed, d can have a different value; however, typically d is kept at 1.
○ R2: Each message piggybacks the clock value of its sender at sending time.
• When a process pi receives a message with timestamp Cmsg , it executes the following actions:
○ Ci := max(Ci, Cmsg )
○ Execute R1.
○ Deliver the message.
Vector Time
• In the system of vector clocks, the time domain is represented by a set of n-dimensional non-negative integer vectors.
• Each process pi maintains a vector vti [1..n], where vti[i] is the local logical clock of pi and describes the logical time progress at process pi .
• vti[j] represents process pi ’s latest knowledge of process pj local time.
• If vti[j]=x, then process pi knows that local time at process pj has progressed till x.
• The entire vector vti constitutes pi ’s view of the global logical time and is used to timestamp events.
• Process pi uses the following two rules R1 and R2 to update its clock:
○ R1: Before executing an event, process pi updates its local logical time as follows:
▪ vti [i] := vti [i] + d ; (d > 0)
○ R2: Each message m is piggybacked with the vector clock vt of the sender process at sending time.
• On the receipt of such a message (m,vt), process pi executes the following sequence of actions:
1. Update its global logical time as follows: 1 ≤ k ≤ n : vti[k] := max(vti[k], vt[k])
2. Execute R1.
3. Deliver the message m.
Downloaded
MOD-2 Page 2 by Arathi Pc ([email protected])
lOMoARcPSD|55070525
Bully Algorithm
• There are 3 types of messages in bully algorithm:
○ Election message – announces an election
○ Ok message – response to an election message
○ Coordinator message – announce the identity of the elected process
Steps:-
1. A process can begin an election by sending an election message to processes with high priority number and waiting for ok messages in response.
2. If none arrives within time T, the process considers itself as the coordinator and sends a coordinator message to all processes with lower identifiers
announcing this.
3. Otherwise the other process start election for a coordinator.
4. If coordinator does not respond to it within a time interval T, then it is assumed that coordinator has failed.
5. Now process P sends election message to every process with high priority number.
6. It waits for responses, if no one responds within time interval T, then process P elects itself as a coordinator.
7. Then it sends a message to all lower priority number processes that it is elected as their new coordinator.
8. If a process that was previously down/failed comes back it take over the coordinator job.
9. Biggest guy always wins hence the name bully algorithm.
10.
• EG: Pid's 0,4,2,1,5,6,3,7, P7 was the initial coordinator and crashed, Illustrate Bully algorithm, if P4 initiates election , Calculate total number of election
messages and coordinator message.
Downloaded
MOD-2 Page 3 by Arathi Pc ([email protected])
lOMoARcPSD|55070525
• If the arrived identifier is greater, then it forwards the message to its neighbour.
• If the arrived identifier is smaller, then it substitutes its own identifier in the message and forwards it.
• If the received identifier is that of the receiver itself, then this process’s identifier must be the greatest, and it becomes the coordinator.
• The coordinator marks itself as a coordinator and sends an elected message to its neighbour.
EG:
EG: In a ring topology 7 processes are connected with different ID's as shown: P20->P5->P10 >P18->P3->P16->P9 If process P10 initiates election after how many
message passes will the coordinator be elected and known to all the processes. What modification will take place to the election message as it passes through all the
processes? Calculate total number of election messages and coordinator messages
Downloaded
MOD-2 Page 4 by Arathi Pc ([email protected])
lOMoARcPSD|55070525
Global State
• A distributed computing system consists of spatially separated processes that do not share a common memory and communicate asynchronously with each other by
message passing over communication channels.
• Each component of a distributed system has a local state.
• The state of a process is characterized by the state of its local memory and a history of its activity.
• The state of a channel is characterized by the set of messages sent along the channel and the messages received along the channel.
• The global state of a distributed system is a collection of the local states of its components.
System Model
• The system consists of a collection of n processes p1, p2, ..., pn that are connected by channels.
• There are no globally shared memory and physical global clock and processes communicate by passing messages through communication channels.
• Cij denotes the channel from process pi to process pj and its state is denoted by SCij .
• The actions performed by a process are modelled as three types of events:
○ Internal events,
○ the message send event and
○ the message receive event.
• For a message mij that is sent by process pi to process pj ,
○ let send(mij) and rec(mij) denote its send and receive events.
○ At any instant, the state of process pi , denoted by LSi , is a result of the sequence of all the events executed by pi till that instant.
• For an event e and a process state LSi , e∈LSi iff e belongs to the sequence of events that have taken process pi to state LSi .
• For an event e and a process state LSi , e∉LSi iff e does not belong to the sequence of events that have taken process pi to state LSi .
• For a channel Cij , the following set of messages can be defined based on the local states of the processes pi and pj
○ Transit: transit(LSi , LSj) = {mij |send(mij) ∈ LSi ꓥ rec(mij) ∉ LSj }
• Thus, if a snapshot recording algorithm records the state of processes pi and pj as LSi and LSj , respectively, then it must record the state of channel Cij as transit
(LSi_LSj).
• In FIFO model, each channel acts as a first-in first-out message queue and thus, message ordering is preserved by a channel.
• In non-FIFO model, a channel acts like a set in which the sender process adds messages and the receiver process removes messages from it in a random order.
• A system that supports causal delivery of messages satisfies the following property:
○ “For any two messages mij and mkj , if send(mij) → send(mkj), then rec(mij) → rec(mkj)”
• Cut C1 is inconsistent because message m1 is flowing from the FUTURE to the PAST. Cut C2 is consistent and message m4 must be captured in the state of channel
C21.
• Note that in a consistent snapshot, all the recorded local states of processes are concurrent; that is, the recorded local state of no process casually affects the
recorded local state of any other process.
Downloaded
MOD-2 Page 5 by Arathi Pc ([email protected])
lOMoARcPSD|55070525
Correctness:
○ Due to FIFO property of channels, it follows that no message sent after the marker on that channel is recorded in the channel state. Thus, condition C2 is
satisfied.
○ When a process pj receives message mij that precedes the marker on channel Cij , it acts as follows: If process pj has not taken its snapshot yet, then it includes
mij in its recorded snapshot. Otherwise, it records mij in the state of the channel Cij . Thus, condition C1 is satisfied.
Complexity:
○ The recording part of a single instance of the algorithm requires O(e) messages and O(d) time, where e is the number of edges in the network and d is the
diameter of the network.
Termination Detection
• A fundamental problem in distributed systems is to determine if a distributed computation has terminated.
• The detection of the termination of a distributed computation is non-trivial since no process has complete knowledge of the global state, and global time does not
exist.
• A distributed computation is considered to be globally terminated if every process is locally terminated and there is no message in transit between any processes.
• A “locally terminated” state is a state in which a process has finished its computation and will not restart any action unless it receives a message.
• In the termination detection problem, a particular process (or all of the processes) must infer when the underlying computation has terminated.
• Messages used in the underlying computation are called basic messages, and messages used for the purpose of termination detection (by a termination detection
algorithm) are called control messages.
• A termination detection (TD) algorithm must ensure the following:
○ 1. Execution of a TD algorithm cannot indefinitely delay the underlying computation; that is, execution of the termination detection algorithm must not freeze
the underlying computation.
○ 2. The termination detection algorithm must not require addition of new communication channels between processes.
Downloaded
MOD-2 Page 6 by Arathi Pc ([email protected])
lOMoARcPSD|55070525
• The last process to terminate will have the largest clock value. Therefore, every process will take a snapshot for it, however, it will not take a snapshot for any other
process.
• Correctness:
Downloaded
MOD-2 Page 7 by Arathi Pc ([email protected])
lOMoARcPSD|55070525
• Correctness:
○ A: set of weights on all active processes
○ B: set of weights on all basic messages in transit
○ C: set of weights on all control messages in transit
○ Wc : weight on the controlling agent
• Two waves of signals generated one moving inward and other outward through the spanning tree.
• Initially, a contracting wave of signals, called tokens, moves inward from leaves to the root.
• If this token wave reaches the root without discovering that termination has occurred, the root initiates a second outward wave of repeat signals.
• As this repeat wave reaches leaves, the token wave gradually forms and starts moving inward again, this sequence of events is repeated until the termination is
detected.
• Initially, each leaf process is given a token.
• Each leaf process, after it has terminated sends its token to its parent.
• When a parent process terminates and after it has received a token from each of its children, it sends a token to its parent.
• This way, each process indicates to its parent process that the subtree below it has become idle.
• In a similar manner, the tokens get propagated to the root.
• The root of the tree concludes that termination has occurred, after it has become idle and has received a token from each of its children.
• Eg:
Apply spanning tree-based termination detection algorithm in the following scenario. The nodes are processes 0 to 6. Leaf nodes 3, 4, 5, and 6 are each given tokens
T3, T4, T5 and T6 respectively. Leaf nodes 3,4, 5 and 6 terminate in the order, but before terminating node 5,it sends a message to node
Downloaded
MOD-2 Page 8 by Arathi Pc ([email protected])
lOMoARcPSD|55070525
Downloaded
MOD-2 Page 9 by Arathi Pc ([email protected])