Department of Computer Science and Engineering (RA)
COURSE NAME: PARALLEL &DISTRIBUTED
COMPUTING
COURSE CODE: 22CS4106 R
TOPIC: CAUSALITY AND TIME IN
DISTRIBUTED SYSTEMS
CO-3 Session - 5
AIM OF THE SESSION
To familiarize students with the basic concept of Mandelbrot set computation
INSTRUCTIONAL
OBJECTIVES
This Session is designed to:
1. Understand the mathematical foundations
2. Explore the role of complex numbers
3. Implement the Mandelbrot algorithm
4. Visualize and interpret the results
LEARNING OUTCOMES
At the end of this session, you should be able to:
1. Students will be able to comprehend Fractal geometry
2. Students will be able to apply complex number operations
3. Students will be able to develop computational skills
4. Students will be able to analyze and visualize data
2
1. CAUSALITY IN DISTRIBUTED SYSTEMS:
• causality refers to the relationship between events.
• event means: (e.g., message sent, state change)
• In a distributed system, processes or nodes may execute in parallel and
communicate asynchronously. As a result, events in one process can influence events
in another. Causality helps to define and track the relationship between events,
specifically whether one event causes another.
3 methods:
1.Causal Relationship
2.Causal Ordering
3.Vector Clocks or Lamport Timestamps
• A causal relationship indicates that one event in the system (e.g., message sent, state
change) causes another event, which is critical in understanding system behavior
and ensuring correctness.
3
CAUSAL RELATIONSHIP
• Causal relationships help in determining the sequence of events across different nodes of a
distributed system.
Explanation:
1.Event A occurs on Node 1. This event is the cause.
2.Event B happens on Node 1, which is caused by Event A (i.e., Event B happens after Event A).
3.Event C occurs on Node 2. It happens due to some other action, but its relationship to Event A is established through
the causal chain.
Causal Relationship Key Points:
•Causal order means that Event A must happen before Event B for the causal relationship to exist.
•Causal consistency ensures that the order of events is maintained, even if there are network delays or failures.
4
CAUSAL RELATIONSHIP EXAMPLE
• Consider a simple example of two processes, P1 and P2, communicating over a network.
• Process P1 sends a message to Process P2.
• Process P2 receives the message and takes an action based on it.
• Event Timeline:
• Event 1: P1 sends a message to P2.
• Event 2: P2 receives the message and processes it.
• Here, Event 1 (P1 sending the message) causally influences Event 2 (P2 receiving the message). In other words, Event 1
→ Event 2.
5
CAUSAL ORDERING
• Def: Causal ordering refers to the concept of maintaining the sequence of events that occur in a
distributed system, ensuring that if one event causally affects another, this order is preserved across the
system.
Key Concepts:
• Logical Clocks in Causal Ordering: To track causal relationships across distributed systems, we use
logical clocks (e.g., Lamport's Logical Clock or Vector Clocks).
• Logical clocks help ensure that we can track the "happens-before" relationships between events that
occur on different processes, even though the processes are not synchronized in real-time.
• Vector Clocks or Lamport Timestamps are commonly used to enforce(apply) causal ordering in
distributed systems. These algorithms track the logical order of events and maintain causal relationships
across nodes.
6
7
CONTI...
8
9
EXAMPLE OF CAUSAL ORDERING
Time →
P1: [1] --> (sends message) --> [2] --> (receives message)
P2: [1] --> (receives message from P1) --> [2] --> (sends message to P3)
P3: [1] --> (receives message from P2) --> [2] --> (sends
message
•Each tohas
process P1)a local clock.
•The timestamp increases at each event.
•Lamport timestamps ensure that causally related events have their timestamps ordered correctly,
i.e., process P1sends a message (timestamp 1), which is received by P2(timestamp 2).
10
• In a distributed system, each node (or process) maintains its own logical clock in the form of a
vector. The vector keeps track of the local time of each node and is updated whenever an event
occurs.
• In distributed systems, vector clocks are a mechanism for capturing the causal relationships
between events that occur in different processes.
• They are a more advanced way of tracking causality compared to Lamport timestamps(logical
clock), and they help to understand not just the order of events but also the causal dependencies
between them.
• While Lamport clocks provide a simple way to track event ordering, vector
clocks are more advanced.
11
KEY CONCEPTS
1.Causality and Vector Clocks:
• Vector clocks are a way of maintaining causal ordering of events across multiple
processes in a distributed system.
• Each process in the system maintains a vector of integers, where each index in
the vector corresponds to the logical time of an event at a specific process.
12
3.Rules for Updating Vector Clocks:
• Local Events: When a process P1 & p2 performs an event (e.g., a
computation), it increments its own counter in the vector clock.
• Message Sending: When a process sends a message, it includes its current
vector clock in the message.
• Message Receiving: When a process receives a message, it updates its vector
clock by taking the element-wise maximum of its own vector clock and the
sender’s vector clock, then increments its own counter.
13
14
STEPS FOR THE EXAMPLE:
15
CHECKING FOR CAUSAL RELATIONSHIPS
16
TIME IN DISTRIBUTED SYSTEMS
• Time in distributed systems is a critical concept, as it plays a central
role in coordinating processes across multiple machines or nodes.
17
KEY CONCEPTS IN TIME IN DISTRIBUTED SYSTEMS:
• Global Clock vs. Local Clocks:
• In a centralized system, all nodes typically share a single global clock.
• In a distributed system, each node has its own local clock. However, these clocks are not
perfectly synchronized due to network delays and other issues.
• Clock Synchronization:
• Clock drift: Each node’s local clock may run slightly faster or slower than others, which makes
synchronization between nodes important.
• Time synchronization protocols like NTP (Network Time Protocol) or Berkeley Algorithm
help synchronize local clocks.
• Logical Clocks:
• Since physical clocks are not perfectly synchronized in distributed systems, logical clocks are
used to keep track of events in a causal manner.
• Lamport Timestamps and Vector Clocks are two common logical clock algorithms.
18
1. PHYSICAL CLOCKS AND SYNCHRONIZATION
• In distributed systems, physical clocks are typically used, but each machine or node has its own local clock. These clocks
may drift over time, and even if they started synchronized, the drift makes them unreliable for determining global time.
• Example:
• Imagine three computers A, B, and C, each with a local clock:
• Clock A: 10:00:00
• Clock B: 10:00:02
• Clock C: 10:00:01
• Because these clocks are unsynchronized, it becomes difficult to determine if events happen simultaneously across
machines.
• Solution: Clock Synchronization protocols like NTP try to reduce the clock drift, ensuring all clocks are synchronized
with a global reference (e.g., UTC). However, perfect synchronization is not always possible, and slight drifts remain.
19
2. LOGICAL CLOCKS
• Logical clocks are used when the precise physical time does not matter, but the order of events does. These are used to
ensure causality between events in a distributed system.
• Lamport Timestamps
• Lamport clocks are used to order events based on logical time.
• Each event is assigned a timestamp, which is incremented locally at each machine.
• Whenever a message is sent, it includes its timestamp, which allows receiving machines to update their logical clocks.
• Example:
• Imagine two processes in different computers, A and B:
• Process A sends a message to Process B at time 1.
• Process B receives the message and updates its time to 2, then sends a reply back.
• Process A receives the reply at time 3.
• The event ordering using Lamport timestamps would look like this:
• A1 (send) → B1 (receive)
• B2 (send) → A2 (receive)
20
CONTI...
• Lamport Clock Update Rule:
• Local time is updated by incrementing its timestamp.
• Message passing: A timestamp is included, and when receiving a message, the logical time is updated to
the maximum of the local time or the timestamp in the message + 1.
Vector Clocks
Vector clocks are an improvement over Lamport clocks to capture more fine-grained causality. Instead of a
single timestamp, each process keeps a vector of timestamps that tracks the state of all other processes.
• A vector clock for process A might look like: [A:3, B:2, C:1], meaning process A has seen 3 events, B has
seen 2, and C has seen 1.
Example:
Process A sends a message to Process B. When Process B receives the message, it updates its vector clock,
taking the maximum value from both its local clock and the received clock.
21
3. CAUSAL ORDERING OF EVENTS
• One critical aspect of time in distributed systems is to determine whether events are causally related.
• Causal Relationship: If one event causes another, the first event should happen before the second one.
• Using logical clocks (like Lamport or vector clocks), we can check if one event happened before another or
if two events are independent.
• Example:
• Let’s consider two events, E1 and E2, across different processes:
• E1 happens before E2: If the timestamp of E1 < timestamp of E2, then E1 causally affects E2.
• Concurrent events: If timestamps of E1 and E2 are unordered, then they happened concurrently (i.e.,
there’s no causal relationship between them).
22
4. REAL-TIME VS. EVENT-TIME
• Real-time is the clock time when events happen (e.g., 10:00:00).
• Event-time refers to the logical ordering of events in a system, which may or may not correspond to real-
time.
Summary of Concepts:
• Physical Clocks: Each node has its own clock, and synchronization is needed.
• Logical Clocks: Using timestamps or vectors to maintain causal order between events.
• Clock Synchronization: Ensuring all nodes have a roughly synchronized time.
• Causal Ordering: Using logical clocks to ensure events are ordered correctly in distributed systems.
23
LOGICAL TIME
24
A FRAMEWORK FOR A SYSTEM OF LOGICAL
CLOCKS
25
A FRAMEWORK FOR A SYSTEM OF LOGICAL CLOCKS
26
IMPLEMENTING LOGICAL CLOCKS
27
VECTOR TIME
28
VECTOR TIME
29
VECTOR TIME
30
VECTOR TIME
31
VECTOR TIME - COMPARING VECTOR
TIMESTAMPS
32
VECTOR TIME - PROPERTIES OF VECTOR TIME
33
34
PHYSICAL CLOCK SYNCHRONIZATION: NTP
35
36
37
38
39
40
41
42
43
THANK YOU
Team – Parallel and Distributed
Computing
44