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

What's hot (20)

PPT
Naming in Distributed Systems
Nandakumar P
 
PPTX
HDLC and Point to point protocol
Kinza Razzaq
 
PPTX
IP Security
Keshab Nath
 
PPTX
Application layer
anonymous
 
PPTX
Point to-point protocol (ppp)
Kongu Engineering College, Perundurai, Erode
 
PPT
Domain name system
Siddique Ibrahim
 
PPTX
Presentation Routing algorithm
Basit Hussain
 
PPTX
Troubleshooting complex layer 2 issues ppt 16 bsit098
Quratulain baloch
 
PPTX
Generating code from dags
indhu mathi
 
PPT
Unit 5 Application Layer
KalpanaC14
 
PPT
Chapter 4 a interprocess communication
AbDul ThaYyal
 
PPTX
INTER PROCESS COMMUNICATION (IPC).pptx
LECO9
 
PPTX
Congestion control
Aman Jaiswal
 
PPTX
Tcp header/IP Header/Authentication header
Faizan Shaikh
 
PPTX
Network layer - design Issues
قصي نسور
 
PPT
Unit 3 Network Layer PPT
KalpanaC14
 
PDF
Deadlock in Distributed Systems
Pritom Saha Akash
 
PPTX
Shift reduce parser
TEJVEER SINGH
 
PPTX
Check sum
Pooja Jaiswal
 
PPT
Snmp
hetaljadav
 
Naming in Distributed Systems
Nandakumar P
 
HDLC and Point to point protocol
Kinza Razzaq
 
IP Security
Keshab Nath
 
Application layer
anonymous
 
Point to-point protocol (ppp)
Kongu Engineering College, Perundurai, Erode
 
Domain name system
Siddique Ibrahim
 
Presentation Routing algorithm
Basit Hussain
 
Troubleshooting complex layer 2 issues ppt 16 bsit098
Quratulain baloch
 
Generating code from dags
indhu mathi
 
Unit 5 Application Layer
KalpanaC14
 
Chapter 4 a interprocess communication
AbDul ThaYyal
 
INTER PROCESS COMMUNICATION (IPC).pptx
LECO9
 
Congestion control
Aman Jaiswal
 
Tcp header/IP Header/Authentication header
Faizan Shaikh
 
Network layer - design Issues
قصي نسور
 
Unit 3 Network Layer PPT
KalpanaC14
 
Deadlock in Distributed Systems
Pritom Saha Akash
 
Shift reduce parser
TEJVEER SINGH
 
Check sum
Pooja Jaiswal
 

Similar to Vector clock algorithm (20)

PDF
Ds practical file
Khushboo Pal
 
PPT
Clocks
guesta013ed8
 
PDF
logical clocks
Juan Manuel Hurtado Valdivia
 
PDF
Chapter 14 slides Distributed System Presentation
Nehal668249
 
PPTX
Chapter 6 synchronization
Alagappa Government Arts College, Karaikudi
 
PDF
Synchonization in Distributed Systems.pdf
cAnhTrn53
 
PPT
Chapter 6-Synchronozation2.ppt
MeymunaMohammed1
 
PDF
Time in distributed systmes
mohammad amid abbasi
 
PPTX
Synchronization in distributed computing
SVijaylakshmi
 
PPT
Distributed System
Praveen Penumathsa
 
PPT
CS6601-Unit 4 Distributed Systems
Nandakumar P
 
PDF
Distributed computing time
Deepak John
 
PPTX
Cross cutting concerns should be logically centralized DRY ,but it may appear...
Manonmani40
 
PDF
Chapter14.pdfffasfdaddsdsvdsffdhhhahdfdfghhh
PRASAD BANOTH
 
PDF
6.Distributed Operating Systems
Dr Sandeep Kumar Poonia
 
PPTX
W03-L06 Physial and Logical Clocks (3).pptx
AliAbbas835233
 
PPTX
aks-time-matrixdone with the universal clock.pptx
PankajSheoran9
 
PPTX
Synchronization
Ameena Tijjani
 
PPT
Synchronization in distributed systems
SHATHAN
 
PDF
Distributed Computing
GururajaHebburSatyan
 
Ds practical file
Khushboo Pal
 
Clocks
guesta013ed8
 
Chapter 14 slides Distributed System Presentation
Nehal668249
 
Synchonization in Distributed Systems.pdf
cAnhTrn53
 
Chapter 6-Synchronozation2.ppt
MeymunaMohammed1
 
Time in distributed systmes
mohammad amid abbasi
 
Synchronization in distributed computing
SVijaylakshmi
 
Distributed System
Praveen Penumathsa
 
CS6601-Unit 4 Distributed Systems
Nandakumar P
 
Distributed computing time
Deepak John
 
Cross cutting concerns should be logically centralized DRY ,but it may appear...
Manonmani40
 
Chapter14.pdfffasfdaddsdsvdsffdhhhahdfdfghhh
PRASAD BANOTH
 
6.Distributed Operating Systems
Dr Sandeep Kumar Poonia
 
W03-L06 Physial and Logical Clocks (3).pptx
AliAbbas835233
 
aks-time-matrixdone with the universal clock.pptx
PankajSheoran9
 
Synchronization
Ameena Tijjani
 
Synchronization in distributed systems
SHATHAN
 
Distributed Computing
GururajaHebburSatyan
 
Ad

Recently uploaded (20)

PDF
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
PPTX
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
PPT
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
PDF
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
PPTX
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
PPTX
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
PPTX
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
PPTX
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
PPTX
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
PDF
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
PDF
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
PPTX
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
PPSX
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
PDF
The Different Types of Non-Experimental Research
Thelma Villaflores
 
PDF
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
PPTX
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
PPTX
grade 5 lesson ENGLISH 5_Q1_PPT_WEEK3.pptx
SireQuinn
 
PDF
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
PPTX
How to Set Maximum Difference Odoo 18 POS
Celine George
 
PPTX
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
The Constitution Review Committee (CRC) has released an updated schedule for ...
nservice241
 
Unit 2 COMMERCIAL BANKING, Corporate banking.pptx
AnubalaSuresh1
 
Talk on Critical Theory, Part II, Philosophy of Social Sciences
Soraj Hongladarom
 
Chapter-V-DED-Entrepreneurship: Institutions Facilitating Entrepreneurship
Dayanand Huded
 
Soil and agriculture microbiology .pptx
Keerthana Ramesh
 
MENINGITIS: NURSING MANAGEMENT, BACTERIAL MENINGITIS, VIRAL MENINGITIS.pptx
PRADEEP ABOTHU
 
How to Create a PDF Report in Odoo 18 - Odoo Slides
Celine George
 
HYDROCEPHALUS: NURSING MANAGEMENT .pptx
PRADEEP ABOTHU
 
How to Convert an Opportunity into a Quotation in Odoo 18 CRM
Celine George
 
SSHS-2025-PKLP_Quarter-1-Dr.-Kerby-Alvarez.pdf
AishahSangcopan1
 
CEREBRAL PALSY: NURSING MANAGEMENT .pdf
PRADEEP ABOTHU
 
STAFF DEVELOPMENT AND WELFARE: MANAGEMENT
PRADEEP ABOTHU
 
HEALTH ASSESSMENT (Community Health Nursing) - GNM 1st Year
Priyanshu Anand
 
The Different Types of Non-Experimental Research
Thelma Villaflores
 
ARAL-Orientation_Morning-Session_Day-11.pdf
JoelVilloso1
 
Mathematics 5 - Time Measurement: Time Zone
menchreo
 
grade 5 lesson ENGLISH 5_Q1_PPT_WEEK3.pptx
SireQuinn
 
CONCURSO DE POESIA “POETUFAS – PASSOS SUAVES PELO VERSO.pdf
Colégio Santa Teresinha
 
How to Set Maximum Difference Odoo 18 POS
Celine George
 
Growth and development and milestones, factors
BHUVANESHWARI BADIGER
 
Ad

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.  .