SlideShare a Scribd company logo
Subject: Distributed systems
Department of computer science and
Engineering
Prof. S. Anbu
Sep’10, 2021
 This algorithm is used to determine the partial ordering of
events in a distributed system and also to detect causality
violations.
 Assume the processes are running P0,P1 and
P2.
 At 1’o clock, The first process P0 send a message to P1. This message
reaches P1 only at 6 pm in the evening.
 At 2’0 clock, the first process P0 send an another message to the
process p3. It reaches P3 at 3 pm.
 The processPp3 also sends one message to process P2 at 4 ‘o clock.
This message reaches P1 at 5 pm.
 The important thing about this situation is that , the message from P2
arrives at P1, before the first message from P0 reaches p1 i.e the
first message arrives only at 6 pm. ( late arrival)
 This timing problem should be solved .
Vector clock algorithm
 The process P0 gives one apple to P1.
 Immediately P0 sends a message to P2 that P1 has one apple
 So P2 sends a message to P1 to eat that apple.
 But the real situation is, P1 not yet received that apple. So how does
he eat it?
 This example illustrates a causality violation.
 A causality violation occurs when a message ordering problem results
in one host taking an action based on information that another host
should have received, but not yet received.
 In this case , P2 is trying to invoke a method ( eat( ) ) on P1, because
P2 wrongly assumes that P1 has an apple.
 Each process in a system should have knowledge of other processes
running in the system to find the causality violations. i.e An array of
knowledge is needed by each process.
 Lamport logical lock is not sufficient to solve this problem, because it
tracks only the total number of events in the system
 So a new communication mechanism is needed to solve this causality
violation problem. What is that mechanism?
 Vector clocks .
 Vector Clocks are used in a distributed systems to determine whether
pairs of events are causally related or not.
 Using Vector Clocks, timestamps are generated for each event in the
system, and their causal relationship is determined by comparing those
timestamps.
 Vector clock of a system of N processes is an array of N logical clocks,
i.e one clock per process.

 So for N given processes, there will be a vector/ array of size N.
[ 1….N]
 As with Lamport logical time, each process maintains its own
view of the local time and updates it using the timestamps
placed by the sender onto messages.
 But with vector logical time, the time contains more information
i.e it contains a vector representing the state of each process
running in the distributed system.
 In other words, this vector not only contains the event count for
the process itself, it also contains the last-known event counts on
each and every other process .
 Initially, all the clocks are set to zero.
 Every time, an Internal event occurs in a process, the value of the
processes' logical clock in the vector is incremented by 1
Two rules
 Rule 1: ( Local update rule) Every time a process sends a message, the
value of the processes' logical clock in the vector is incremented by 1 and
and then send a copy of its own vector.
 Rule 2: (message rule) Every time, a process receives a message, the
value of the processes' logical clock in the vector is incremented by 1.
Moreover, each element is updated by taking the maximum of the value
in its own vector clock and the value in the vector in the received message
.
 As a result, when a process receives a message, it merges its own time
vector and the timestamp sent with the message -- it selects the higher
of the values for each element.
 This ensures that the sender has information that is at least as up-to-
date as the receiver.
Vector clock algorithm
 Assume, N = 3. i.e 3 processes are running p1, p2 and p3.
Apply rule 1 ( Local update rule)
 The event a occurs in p1. So it increments its own logical clock in the
vector by 1. ( 1,0,0)
 The event d occurs in p2. So it increments its own logical clock in
the vector by 1. ( 0,1,0)
 The event g occurs in p3. So it increments its own logical clock in
the vector by 1. ( 0,0,1)
 Now , event b occurs in process p1. So again apply rule 1 (local update
rule). Process p1 increments its clock in the vector by 1. ( 2,0,0).
 The event b of process p1 sends a message to the event e in process
p2. Also sends a copy of its own vector to p2( By piggybacking. i.e
sends vector elements on the shoulder of message).
 Now what will be the status of the vector clocks ?.
 Apply rule 2
( Every time, a process receives a message, the value of the processes'
logical clock in the vector is incremented by 1. Moreover, each element is
updated by taking the maximum of the value in its own vector clock and
the value in the vector in the received message (for every element) ) .
First, Increment VC of p2 by 1 as per the rule. So ( 0,1,0) becomes
( 0,2,0) .
Vector clock values in the received message are ( 2, 0, 0). ( Already
sent by p1)
Take maximum of these two vector clock values
Time stamps
-----------
0, 2, 0 0 and 2 . maximum is 2
2, 0, 0 2 and 0 . maximum is 2
-----------
2, 2, 0
----------
Vector clock algorithm
 Now, many events occur in all the processes
 Event h occurs in process p3. So VCs become ( 0, 0, 2)
 Event c occurs in process p1. Now, VCs become ( 3, 0, 0)
 Event f occurs in process p2. Now, VCs become ( 2, 3, 0)
 Event i occurs in process p3.
Vector clock algorithm
Vector clock algorithm
 Now what will be the status of the vector clocks now ?.
 Apply rule 2
 first, Increment VC of p3 by 1 as per the rule
 So ( 0, 0, 2) becomes ( 0, 0, 3 )
 Vector clock values in the received message are ( Already sent by p2)
 ( 2, 3, 0).
 Take maximum of these two vector clock values
 Time stamps
 ------------
 0, 0, 3 take maximum values
 2, 3, 0
 -----------
 2, 3, 3
 ----------

Vector clock algorithm
 Vector clocks easily captures the causality between inter-process
communications. Partial order (→) between a and i.
 If two events are not comparable, we say these events are concurrent. But
Lamport logical clock mechanism can not find whether the events are
concurrent or not. This problem is solved by the vector clock mechanism
 Using vector clock, timestamps are created for each event in the
distributed system and their relationship is determined by comparing
those timestamps. Whether they are concurrent or in a casual relationship.
 Vector clock timestamps precisely capture happens-before relation
 Vector Clocks guarantee strong clock consistency as they are an
extension of Lamport Timestamps.
 .
Thank you

More Related Content

PPTX
Distributed system lamport's and vector algorithm
PPTX
Optimistic concurrency control in Distributed Systems
PPT
message passing
PDF
Distributed deadlock
PPTX
Memory virtualization
PPTX
Replication in Distributed Systems
PPT
distributed shared memory
PPTX
And or graph
Distributed system lamport's and vector algorithm
Optimistic concurrency control in Distributed Systems
message passing
Distributed deadlock
Memory virtualization
Replication in Distributed Systems
distributed shared memory
And or graph

What's hot (20)

PPT
Synchronization in distributed systems
PPT
Clock synchronization in distributed system
PPTX
Mining Data Streams
PPT
Distributed Transaction
PPSX
Congestion avoidance in TCP
PPT
Chapter 4 a interprocess communication
PPTX
knowledge representation using rules
PPTX
distributed Computing system model
DOC
Distributed Mutual exclusion algorithms
PPT
Lamport’s algorithm for mutual exclusion
PPTX
Structure of shared memory space
PDF
CS9222 Advanced Operating System
PPT
Logical Clocks (Distributed computing)
PPT
Np cooks theorem
PPTX
Directory implementation and allocation methods
PPT
Type Checking(Compiler Design) #ShareThisIfYouLike
PPT
Distributed System-Multicast & Indirect communication
PDF
Resource management
PPTX
Algorithm and pseudocode conventions
PPTX
Publish subscribe model overview
Synchronization in distributed systems
Clock synchronization in distributed system
Mining Data Streams
Distributed Transaction
Congestion avoidance in TCP
Chapter 4 a interprocess communication
knowledge representation using rules
distributed Computing system model
Distributed Mutual exclusion algorithms
Lamport’s algorithm for mutual exclusion
Structure of shared memory space
CS9222 Advanced Operating System
Logical Clocks (Distributed computing)
Np cooks theorem
Directory implementation and allocation methods
Type Checking(Compiler Design) #ShareThisIfYouLike
Distributed System-Multicast & Indirect communication
Resource management
Algorithm and pseudocode conventions
Publish subscribe model overview
Ad

Similar to Vector clock algorithm (20)

PDF
Ds practical file
PPT
Clocks
PDF
PDF
Chapter 14 slides Distributed System Presentation
PPTX
PDF
Synchonization in Distributed Systems.pdf
PPT
Chapter 6-Synchronozation2.ppt
PDF
Time in distributed systmes
PPTX
Synchronization in distributed computing
PPT
Distributed System
PPT
CS6601-Unit 4 Distributed Systems
PDF
Distributed computing time
PPTX
Cross cutting concerns should be logically centralized DRY ,but it may appear...
PDF
Chapter14.pdfffasfdaddsdsvdsffdhhhahdfdfghhh
PDF
6.Distributed Operating Systems
PPTX
Physical and Logical Clocks
PPTX
W03-L06 Physial and Logical Clocks (3).pptx
PPTX
aks-time-matrixdone with the universal clock.pptx
PPTX
Synchronization
PDF
Distributed Computing
Ds practical file
Clocks
Chapter 14 slides Distributed System Presentation
Synchonization in Distributed Systems.pdf
Chapter 6-Synchronozation2.ppt
Time in distributed systmes
Synchronization in distributed computing
Distributed System
CS6601-Unit 4 Distributed Systems
Distributed computing time
Cross cutting concerns should be logically centralized DRY ,but it may appear...
Chapter14.pdfffasfdaddsdsvdsffdhhhahdfdfghhh
6.Distributed Operating Systems
Physical and Logical Clocks
W03-L06 Physial and Logical Clocks (3).pptx
aks-time-matrixdone with the universal clock.pptx
Synchronization
Distributed Computing
Ad

Recently uploaded (20)

PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
Basic Mud Logging Guide for educational purpose
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
Lesson notes of climatology university.
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Pharma ospi slides which help in ospi learning
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PPTX
master seminar digital applications in india
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
Classroom Observation Tools for Teachers
PPTX
Cell Structure & Organelles in detailed.
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPH.pptx obstetrics and gynecology in nursing
O7-L3 Supply Chain Operations - ICLT Program
Abdominal Access Techniques with Prof. Dr. R K Mishra
102 student loan defaulters named and shamed – Is someone you know on the list?
Basic Mud Logging Guide for educational purpose
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
2.FourierTransform-ShortQuestionswithAnswers.pdf
Lesson notes of climatology university.
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
Supply Chain Operations Speaking Notes -ICLT Program
Pharma ospi slides which help in ospi learning
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
master seminar digital applications in india
Renaissance Architecture: A Journey from Faith to Humanism
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
Classroom Observation Tools for Teachers
Cell Structure & Organelles in detailed.
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx

Vector clock algorithm

  • 1. Subject: Distributed systems Department of computer science and Engineering Prof. S. Anbu Sep’10, 2021
  • 2.  This algorithm is used to determine the partial ordering of events in a distributed system and also to detect causality violations.
  • 3.  Assume the processes are running P0,P1 and P2.
  • 4.  At 1’o clock, The first process P0 send a message to P1. This message reaches P1 only at 6 pm in the evening.  At 2’0 clock, the first process P0 send an another message to the process p3. It reaches P3 at 3 pm.  The processPp3 also sends one message to process P2 at 4 ‘o clock. This message reaches P1 at 5 pm.
  • 5.  The important thing about this situation is that , the message from P2 arrives at P1, before the first message from P0 reaches p1 i.e the first message arrives only at 6 pm. ( late arrival)  This timing problem should be solved .
  • 7.  The process P0 gives one apple to P1.  Immediately P0 sends a message to P2 that P1 has one apple  So P2 sends a message to P1 to eat that apple.  But the real situation is, P1 not yet received that apple. So how does he eat it?
  • 8.  This example illustrates a causality violation.  A causality violation occurs when a message ordering problem results in one host taking an action based on information that another host should have received, but not yet received.  In this case , P2 is trying to invoke a method ( eat( ) ) on P1, because P2 wrongly assumes that P1 has an apple.
  • 9.  Each process in a system should have knowledge of other processes running in the system to find the causality violations. i.e An array of knowledge is needed by each process.  Lamport logical lock is not sufficient to solve this problem, because it tracks only the total number of events in the system  So a new communication mechanism is needed to solve this causality violation problem. What is that mechanism?  Vector clocks .
  • 10.  Vector Clocks are used in a distributed systems to determine whether pairs of events are causally related or not.  Using Vector Clocks, timestamps are generated for each event in the system, and their causal relationship is determined by comparing those timestamps.  Vector clock of a system of N processes is an array of N logical clocks, i.e one clock per process.   So for N given processes, there will be a vector/ array of size N. [ 1….N]
  • 11.  As with Lamport logical time, each process maintains its own view of the local time and updates it using the timestamps placed by the sender onto messages.  But with vector logical time, the time contains more information i.e it contains a vector representing the state of each process running in the distributed system.  In other words, this vector not only contains the event count for the process itself, it also contains the last-known event counts on each and every other process .
  • 12.  Initially, all the clocks are set to zero.  Every time, an Internal event occurs in a process, the value of the processes' logical clock in the vector is incremented by 1 Two rules  Rule 1: ( Local update rule) Every time a process sends a message, the value of the processes' logical clock in the vector is incremented by 1 and and then send a copy of its own vector.  Rule 2: (message rule) Every time, a process receives a message, the value of the processes' logical clock in the vector is incremented by 1. Moreover, each element is updated by taking the maximum of the value in its own vector clock and the value in the vector in the received message .
  • 13.  As a result, when a process receives a message, it merges its own time vector and the timestamp sent with the message -- it selects the higher of the values for each element.  This ensures that the sender has information that is at least as up-to- date as the receiver.
  • 15.  Assume, N = 3. i.e 3 processes are running p1, p2 and p3. Apply rule 1 ( Local update rule)  The event a occurs in p1. So it increments its own logical clock in the vector by 1. ( 1,0,0)  The event d occurs in p2. So it increments its own logical clock in the vector by 1. ( 0,1,0)  The event g occurs in p3. So it increments its own logical clock in the vector by 1. ( 0,0,1)
  • 16.  Now , event b occurs in process p1. So again apply rule 1 (local update rule). Process p1 increments its clock in the vector by 1. ( 2,0,0).
  • 17.  The event b of process p1 sends a message to the event e in process p2. Also sends a copy of its own vector to p2( By piggybacking. i.e sends vector elements on the shoulder of message).  Now what will be the status of the vector clocks ?.
  • 18.  Apply rule 2 ( Every time, a process receives a message, the value of the processes' logical clock in the vector is incremented by 1. Moreover, each element is updated by taking the maximum of the value in its own vector clock and the value in the vector in the received message (for every element) ) . First, Increment VC of p2 by 1 as per the rule. So ( 0,1,0) becomes ( 0,2,0) . Vector clock values in the received message are ( 2, 0, 0). ( Already sent by p1) Take maximum of these two vector clock values Time stamps ----------- 0, 2, 0 0 and 2 . maximum is 2 2, 0, 0 2 and 0 . maximum is 2 ----------- 2, 2, 0 ----------
  • 20.  Now, many events occur in all the processes  Event h occurs in process p3. So VCs become ( 0, 0, 2)  Event c occurs in process p1. Now, VCs become ( 3, 0, 0)  Event f occurs in process p2. Now, VCs become ( 2, 3, 0)  Event i occurs in process p3.
  • 23.  Now what will be the status of the vector clocks now ?.  Apply rule 2  first, Increment VC of p3 by 1 as per the rule  So ( 0, 0, 2) becomes ( 0, 0, 3 )  Vector clock values in the received message are ( Already sent by p2)  ( 2, 3, 0).  Take maximum of these two vector clock values  Time stamps  ------------  0, 0, 3 take maximum values  2, 3, 0  -----------  2, 3, 3  ---------- 
  • 25.  Vector clocks easily captures the causality between inter-process communications. Partial order (→) between a and i.
  • 26.  If two events are not comparable, we say these events are concurrent. But Lamport logical clock mechanism can not find whether the events are concurrent or not. This problem is solved by the vector clock mechanism  Using vector clock, timestamps are created for each event in the distributed system and their relationship is determined by comparing those timestamps. Whether they are concurrent or in a casual relationship.  Vector clock timestamps precisely capture happens-before relation  Vector Clocks guarantee strong clock consistency as they are an extension of Lamport Timestamps.  .