Distributed Systems CS 15-440 Synchronization – Part II Lecture 8, Sep 28, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud.

Slides:



Advertisements
Similar presentations
Distributed Systems CS Synchronization Lecture 6, Sep 26, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud.
Advertisements

Synchronization Chapter clock synchronization * 5.2 logical clocks * 5.3 global state * 5.4 election algorithm * 5.5 mutual exclusion * 5.6 distributed.
Computer Science 425 Distributed Systems CS 425 / CSE 424 / ECE 428 Fall 2011 August 30, 2011 Lecture 3 Time and Synchronization Reading: Sections
Time and Global States Ali Fanian Isfahan University of Technology
Distributed Systems Spring 2009
Distributed Systems Fall 2010 Time and synchronization.
Distributed Systems Fall 2009 Logical time, global states, and debugging.
Distributed Systems CS Google Chubby and Message Ordering Recitation 4, Sep 29, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud.
Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion.
© Chinese University, CSE Dept. Distributed Systems / Distributed Systems Topic 9: Time, Coordination and Replication Dr. Michael R. Lyu Computer.
Lecture 13 Synchronization (cont). EECE 411: Design of Distributed Software Applications Logistics Last quiz Max: 69 / Median: 52 / Min: 24 In a box outside.
1 Slides for Chapter 10: Time (and Global State) From Coulouris, Dollimore and Kindberg Distributed Systems: Concepts and Design Edition 3, © Addison-Wesley.
CSE 486/586, Spring 2012 CSE 486/586 Distributed Systems Logical Time Steve Ko Computer Sciences and Engineering University at Buffalo.
EEC-681/781 Distributed Computing Systems Lecture 10 Wenbing Zhao Cleveland State University.
EEC-681/781 Distributed Computing Systems Lecture 10 Wenbing Zhao Cleveland State University.
Lecture 12 Synchronization. EECE 411: Design of Distributed Software Applications Summary so far … A distributed system is: a collection of independent.
Lecture 9: Time & Clocks CDK4: Sections 11.1 – 11.4 CDK5: Sections 14.1 – 14.4 TVS: Sections 6.1 – 6.2 Topics: Synchronization Logical time (Lamport) Vector.
Time, Clocks, and the Ordering of Events in a Distributed System Leslie Lamport (1978) Presented by: Yoav Kantor.
Lecture 2-1 CS 425/ECE 428 Distributed Systems Lecture 2 Time & Synchronization Reading: Klara Nahrstedt.
Logical Clocks (2). Topics r Logical clocks r Totally-Ordered Multicasting r Vector timestamps.
1 Physical Clocks need for time in distributed systems physical clocks and their problems synchronizing physical clocks u coordinated universal time (UTC)
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
1DT066 D ISTRIBUTED I NFORMATION S YSTEM Time, Coordination and Agreement 1.
A Security Analysis of the Network Time Protocol (NTP) Presentation by Tianen Liu.
© Oxford University Press 2011 DISTRIBUTED COMPUTING Sunita Mahajan Sunita Mahajan, Principal, Institute of Computer Science, MET League of Colleges, Mumbai.
Logical Clocks n event ordering, happened-before relation (review) n logical clocks conditions n scalar clocks condition implementation limitation n vector.
Computer Science Lecture 10, page 1 CS677: Distributed OS Last Class: Naming Name distribution: use hierarchies DNS X.500 and LDAP.
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Synchronization. Why we need synchronization? It is important that multiple processes do not access shared resources simultaneously. Synchronization in.
Logical Clocks. Topics Logical clocks Totally-Ordered Multicasting Vector timestamps.
Synchronization Chapter 5.
Communication & Synchronization Why do processes communicate in DS? –To exchange messages –To synchronize processes Why do processes synchronize in DS?
Distributed Systems Fall 2010 Logical time, global states, and debugging.
Distributed Systems Principles and Paradigms Chapter 05 Synchronization.
1 Clock Synchronization & Mutual Exclusion in Distributed Operating Systems Brett O’Neill CSE 8343 – Group A6.
Time This powerpoint presentation has been adapted from: 1) sApr20.ppt.
CIS825 Lecture 2. Model Processors Communication medium.
Time and global states Chapter 11. Outline Introduction Clocks, events and process states Synchronizing physical clocks Logical time and logical clocks.
Distributed Systems CS Synchronization – Part I Lecture 8, Sep 23, 2013 Mohammad Hammoud.
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Distributed Systems Topic 5: Time, Coordination and Agreement
Tanenbaum & Van Steen, Distributed Systems: Principles and Paradigms, 2e, (c) 2007 Prentice-Hall, Inc. All rights reserved DISTRIBUTED SYSTEMS.
Logical Clocks. Topics r Logical clocks r Totally-Ordered Multicasting.
Event Ordering. CS 5204 – Operating Systems2 Time and Ordering The two critical differences between centralized and distributed systems are: absence of.
6 SYNCHRONIZATION. introduction processes synchronize –exclusive access. –agree on the ordering of events much more difficult compared to synchronization.
COMP 655: Distributed/Operating Systems Summer 2011 Dr. Chunbo Chu Week 6: Synchronyzation 3/5/20161 Distributed Systems - COMP 655.
Logical Clocks event ordering, happened-before relation (review) logical clocks conditions scalar clocks  condition  implementation  limitation vector.
CSE 486/586 CSE 486/586 Distributed Systems Time and Synchronization Steve Ko Computer Sciences and Engineering University at Buffalo.
Topic 7: Time and Global State Dr. Ayman Srour Faculty of Applied Engineering and Urban Planning University of Palestine.
Distributed Systems CS
Distributed Computing
Distributed Systems CS
Time and Global States Ali Fanian Isfahan University of Technology
Logical time (Lamport)
Distributed Systems CS
Distributed Systems CS
Distributed Systems CS
DISTRIBUTED SYSTEMS Principles and Paradigms Second Edition ANDREW S
Distributed Systems CS
Distributed Systems CS
Distributed Systems CS
Distributed Systems CS
CDK: Sections 11.1 – 11.4 TVS: Sections 6.1 – 6.2
Logical time (Lamport)
Distributed Systems CS
Logical time (Lamport)
Logical time (Lamport)
Last Class: Naming Name distribution: use hierarchies DNS
Presentation transcript:

Distributed Systems CS Synchronization – Part II Lecture 8, Sep 28, 2011 Majd F. Sakr, Vinay Kolar, Mohammad Hammoud

Today…  Last Session  Synchronization: Clock Synchronization and Cristian’s Algorithm  Today’s session  Quiz (20 minutes)  Synchronization  Clock Synchronization: Berkeley’s Algorithm and NTP  Logical Clocks: Lamport’s Clock, Vector Clocks  Announcements  Assignment 2 posted (Due Oct 13 th )  Assignment 1 will be graded by Monday  Project 1 due on Oct 3 rd

Time Synchronization Physical Clock Synchronization (or, simply, Clock Synchronization) Here, actual time on the computers are synchronized Logical Clock Synchronization Computers are synchronized based on the relative ordering of events Mutual Exclusion How to coordinate between processes that access the same resource? Election Algorithms Here, a group of entities elect one entity as the coordinator for solving a problem Where do We Stand in Synchronization Chapter? Previous lecture Next lecture Today’s lecture

Types of Time Synchronization Computer 1Computer 2Computer 3Computer 4 Clocks are synchronized over the network Computer 1Computer 2Computer 3Computer 4 Logical Clocks are synchronized over the network only when an event occurs Clock-based Time Synchronization Event-based Time Synchronization

Overview Time Synchronization Clock Synchronization Logical Clock Synchronization Mutual Exclusion Election Algorithms

Clock Synchronization Coordinated Universal Time Tracking Time on a Computer Clock Synchronization Algorithms Cristian’s Algorithm Berkeley Algorithm Network Time Protocol

Berkeley Algorithm Approach: 1.A time server periodically (approx. once in 4 minutes) sends its time to all the computers and polls them for the time difference 2.The computers compute the time difference and then reply 3.The server computes an average time difference for each computer 4.The server commands all the computers to update their time (by gradual time synchronization) 3:00 3:252:50 Time server 3:00 -0:10+0:25 +0:00+0:05 +0:15 -0:20 Berkeley Algorithm is a distributed approach for time synchronization 3:05

Berkeley Algorithm – Discussion 1. Assumption about packet transmission delays Berkeley’s algorithm predicts network delay (similar to Cristian’s algorithm) Hence, it is effective in intranets, and not accurate in wide-area networks 2. No UTC Receiver is necessary The clocks in the system synchronize by averaging all the computer’s times 3. Decreases the effect of faulty clocks Fault-tolerant averaging, where outlier clocks are ignored, can be easily performed in Berkeley Algorithm 4. Time server failures can be masked If a time server fails, another computer can be elected as a time server

Clock Synchronization Coordinated Universal Time Tracking Time on a Computer Clock Synchronization Algorithms Cristian’s Algorithm Berkeley Algorithm Network Time Protocol

Network Time Protocol (NTP) NTP defines an architecture for a time service and a protocol to distribute time information over the Internet In NTP, servers are connected in a logical hierarchy called synchronization subnet The levels of synchronization subnet is called strata Stratum 1 servers have most accurate time information (connected to a UTC receiver) Servers in each stratum act as time servers to the servers in the lower stratum

Hierarchical organization of NTP Servers This stratum contains the primary servers that are directly connected to the UTC receivers Stratum 1 Stratum 2 are secondary servers that are synchronized directly with primary servers Stratum 2 Stratum 3 synchronizes with Stratum 2 servers Stratum 3 End user computers synchronize with the servers in the upper layer stratum Last stratum

Operation of NTP Protocol When a time server A contacts time server B for synchronization If stratum(A) <= stratum(B), then A does not synchronize with B If stratum(A) > stratum(B), then: Time server A synchronizes with B An algorithm similar to Cristian’s algorithm is used to synchronize. However, larger statistical samples are taken before updating the clock Time server A updates its stratum stratum(A) = stratum(B) + 1

Discussion of NTP Design NTP enables clients across the Internet to be synchronized accurately to the UTC Large and variable message delays are tolerated through statistical filtering of timing data from different servers Accurate synchronization to UTC time NTP servers are hierarchically organized to speed up synchronization, and to scale to a large number of clients and servers Scalability There are redundant time servers, and redundant paths between the time servers The architecture provides reliable service that can tolerate lengthy losses of connectivity A synchronization subnet can reconfigure as servers become unreachable. For example, if Stratum 1 server fails, then it can become a Stratum 2 secondary server Reliability and Fault-tolerance NTP protocol uses authentication to check of the timing message originated from the claimed trusted sources Security

Summary of Clock Synchronization Physical clocks on computers are not accurate Clock synchronization algorithms provide mechanisms to synchronize clocks on networked computers in a DS Computers on a local network use various algorithms for synchronization Some algorithms (e.g, Cristian’s algorithm) synchronize time with by contacting centralized time servers Some algorithms (e.g., Berkeley algorithm) synchronize in a distributed manner by exchanging the time information on various computers NTP provides architecture and protocol for time synchronization over wide-area networks such as Internet

Overview Time Synchronization Clock Synchronization Logical Clock Synchronization Mutual Exclusion Election Algorithms

Why Logical Clocks? Lamport (in 1978) showed that: Clock synchronization is not necessary in all scenarios If two processes do not interact, it is not necessary that their clocks are synchronized Many times, it is sufficient if processes agree on the order in which the events has occurred in a DS For example, for a distributed make utility, it is sufficient to know if an input file was modified before or after its object file

Logical Clocks Logical clocks are used to define an order of events without measuring the physical time at which the events occurred We will study two types of logical clocks 1.Lamport’s Logical Clock (or simply, Lamport’s Clock) 2.Vector Clock

Logical Clocks We will study two types of logical clocks 1.Lamport’s Clock 2.Vector Clock

Lamport’s Logical Clock Lamport advocated maintaining logical clocks at the processes to keep track of the order of events To synchronize logical clocks, Lamport defined a relation called “ happened-before ” The expression a  b (read as “ a happened before b ”) means that all entities in a DS agree that event a occurred before event b

Happened-before Relation The happened-before relation can be observed directly in two situations: 1.If a and b are events in the same process, and a occurs before b, then a  b is true 2.If a is an event of message m being sent by a process, and b is the event of the message m being received by another process, the a  b is true. The happened-before relation is transitive If a  b and b  c, then a  c

Time values in Logical Clocks For every event a, assign a logical time value C(a) on which all processes agree Time value for events have the property that If a  b, then C(a)< C(b)

Properties of Logical Clock From happened-before relation, we can infer that: If two events a and b occur within the same process and a  b, then assign C(a) and C(b) such that C(a) < C(b) If a is the event of sending the message m from one process, and b is the event of receiving the message m, then the time values C(a) and C(b) are assigned such that all processes agree that C(a) < C(b) The clock time C must always go forward (increasing), and never backward (decreasing)

Synchronizing Logical Clocks Three processes P1, P2 and P3 running at different rates If the processes communicate between each other, there might be discrepancies in agreeing on the event ordering Ordering of sending and receiving messages m1 and m2 are correct However, m3 and m4 violate the happens-before relationship P1P2P3 m1 m2 m3 m4

Lamport’s Clock Algorithm When a message is being sent: Each message carries a timestamp according to the sender’s logical clock When a message is received: If the receiver logical clock is less than message sending time in the packet, then adjust the receiver’s clock such that currentTime = timestamp P1P2P3 m3: m4:

Logical Clock Without a Physical Clock Previous examples assumed that there is a physical clock at each computer (probably running at different rates) How to attach a time value to an event when there is no global clock?

Implementation of Lamport’s Clock Each process P i maintains a local counter C i and adjusts this counter according to the following rules: 1.For any two successive events that take place within P i, C i is incremented by 1 2.Each time a message m is sent by process P i, the message receives a timestamp ts(m) = C i 3.Whenever a message m is received by a process P j, P j adjusts its local counter C j to max(C j, ts(m)) + 1 P0P0 P1P1 P2P2 C 0 =1C 0 =2 C 0 =0 C 1 =0 C 2 =0 m:2m:2 C 1 =3

Placement of Logical Clock In a computer, several processes use Logical Clocks Similar to how several processes on a computer use one physical clock Instead of each process maintaining its own Logical Clock, Logical Clocks can be implemented as a middleware for time service Network layer Application layer Adjust local clock and timestamp message Adjust local clock Application sends a message Middleware sends a message Message is received Message is delivered to the application

Limitation of Lamport’s Clock Lamport’s Clock ensures that if a  b, then C(a) < C(b) However, it does not say anything about any two events a and b by comparing their time values For any two events a and b, C(a) < C(b) does not mean that a  b Example: P1P2P m1:6 m2:20 m3:32 Compare m1 and m3 P2 can infer that m1  m3 Compare m1 and m2 P2 cannot infer that m1  m2 or m2  m1

Summary of Lamport’s Clock Lamport advocated using logical clocks Processes synchronize based on their time values of the logical clock rather than the absolute time on the physical time Which applications in DS need logical clocks? Applications with provable ordering of events Perfect physical clock synchronization is hard to achieve in practice. Hence we cannot provably order the events Applications with rare events Events are rarely generated, and physical clock synchronization overhead is not justified However, Lamport’s clock cannot guarantee perfect ordering of events by just observing the time values of two arbitrary events

Logical Clocks We will study two types of logical clocks 1.Lamport’s Clock 2.Vector Clocks

Vector Clocks Vector Clocks was proposed to overcome the limitation of Lamport’s clock: the fact that C(a)<C(b) does not mean that a  b The property of inferring that a occurred before b is called as causality property A Vector clock for a system of N processes is an array of N integers Every process P i stores its own vector clock VC i Lamport’s time value for events are stored in VC i VC i (a) is assigned to an event a If VC i (a) < VC i (b), then we can infer that a  b

Updating Vector Clocks Vector clocks are constructed by the following two properties: 1. VC i [i] is the number of events that have occurred at process P i so far VC i [i] is the local logical clock at process P i 2.If VC i [j]=k, then P i knows that k events have occurred at P j VC i [j] is P i ’s knowledge of local time at P j Increment VC i whenever a new event occurs Pass VC j along with the message

Whenever there is a new event at P i, increment VC i [i] When a process P i sends a message m to P j : Increment VC i [i] Set m ’s timestamp ts(m) to the vector VC i When message m is received process P j : VC j [k] = max(VC j [k], ts(m)[k]) ; (for all k) Increment VC j [j] Vector Clock Update Algorithm P0P0 P1P1 P2P2 VC 0 =(1,0,0)VC 0 =(2,0,0) VC 0 =(0,0,0) VC 1 =(0,0,0) VC 2 =(0,0,0) m:(2,0,0) VC 1 =(2,1,0)

Inferring Events with Vector Clocks Let a process P i send a message m to P j with timestamp ts(m), then: P j knows the number of events at the sender P i that causally precede m ( ts(m)[i] – 1) denotes the number of events at P i P j also knows the minimum number of events at other processes P k that causally precede m ( ts(m)[k] – 1) denotes the minimum number of events at P k P0P0 P1P1 P2P2 VC 0 =(1,0,0)VC 0 =(2,0,0) VC 0 =(0,0,0) VC 1 =(0,0,0) VC 2 =(0,0,0) m:(2,0,0) VC 1 =(2,2,0) VC 2 =(2,3,1) m’:(2,3,0) VC 1 =(2,3,0) VC 1 =(0,1,0)

Summary – Logical Clocks Logical Clocks are employed when processes have to agree on relative ordering of events, but not necessarily actual time of events Two types of Logical Clocks Lamport’s Logical Clocks Supports relative ordering of events across different processes by using happen-before relationship Vector Clocks Supports causal ordering of events

Next Class Mutual Exclusion How to coordinate between processes that access the same resource? Election Algorithms Here, a group of entities elect one entity as the coordinator for solving a problem

References