22
Synchronizing Physical Clocks Neeraj Mittal The University of Texas at Dallas August 9, 2012

Clock Synchronization Nonanimated

Embed Size (px)

DESCRIPTION

clock

Citation preview

  • Synchronizing Physical Clocks

    Neeraj Mittal

    The University of Texas at Dallas

    August 9, 2012

  • Motivation

    Types of Clock SynchronizationExternal SynchronizationInternal Synchronization

    Algorithms for Clock SynchronizationCristians AlgorithmThe Berkeley AlgorithmNetwork Time Protocol (NTP)

  • Table of Contents

    Motivation

    Types of Clock SynchronizationExternal SynchronizationInternal Synchronization

    Algorithms for Clock SynchronizationCristians AlgorithmThe Berkeley AlgorithmNetwork Time Protocol (NTP)

  • Motivation

    Applications such as real time object tracking need physicalclocks to work properly

    Most hardware clocks have a non-zero drift rate

    A clock with maximum drift rate of satisfies the followingproperty:

    C (t): value of clock C at real time t t1 and t2: two instants of real time with t1 t2 Then

    (1 )(t2 t1) C (t2) C (t1) (1 + )(t2 t1)

    Typically, 106 seconds/second After 4 months, clock may have an error of 10.37 seconds

    Although relative error is bounded, absolute error may growwith time

  • Table of Contents

    Motivation

    Types of Clock SynchronizationExternal SynchronizationInternal Synchronization

    Algorithms for Clock SynchronizationCristians AlgorithmThe Berkeley AlgorithmNetwork Time Protocol (NTP)

  • Table of Contents

    Motivation

    Types of Clock SynchronizationExternal SynchronizationInternal Synchronization

    Algorithms for Clock SynchronizationCristians AlgorithmThe Berkeley AlgorithmNetwork Time Protocol (NTP)

  • External Synchronization

    Clocks of processes are synchronized with an external clock

    External clock is assumed to be accurate (e.g., CoordinatedUniversal Time source)

    Formal definition: S : clock of the server Ci : clock of process Pi , for i = 1, 2, . . . ,N D: constant Clocks are said to be externally synchronized if:

    For all processes Pi , and for all real times t: |Ci (t)S(t)| D

    Interpretation: Clocks are accurate to within the bound D

  • Table of Contents

    Motivation

    Types of Clock SynchronizationExternal SynchronizationInternal Synchronization

    Algorithms for Clock SynchronizationCristians AlgorithmThe Berkeley AlgorithmNetwork Time Protocol (NTP)

  • Internal Synchronization

    Clocks of processes are synchronized with each other

    Formal definition: Ci : clock of process Pi , for i = 1, 2, . . . ,N D: constant Clocks are said to be internally synchronized if:

    For all pairs of processes Pi and Pj , and for all real times t:|Ci (t) Cj(t)| D

    Interpretation: Clocks agree within the bound D

    Internally synchronized clocks may show inaccurate time

    Externally synchronized clocks are also internally synchronized

  • Table of Contents

    Motivation

    Types of Clock SynchronizationExternal SynchronizationInternal Synchronization

    Algorithms for Clock SynchronizationCristians AlgorithmThe Berkeley AlgorithmNetwork Time Protocol (NTP)

  • Table of Contents

    Motivation

    Types of Clock SynchronizationExternal SynchronizationInternal Synchronization

    Algorithms for Clock SynchronizationCristians AlgorithmThe Berkeley AlgorithmNetwork Time Protocol (NTP)

  • Cristians Algorithm

    Client

    Server

    Client

    Server

    Client

    Server

    s

    Server

  • Cristians Algorithm (Contd.)

    Clients hardware may have a non-zero drift Drift introduces error in the estimation of the round trip time A typical hardware clock has maximum drift rate of only 106

    seconds/second Any error in the estimate will be negligible if the round trip

    time is small and can be ignored

    Estimate of the current clock value of the server assumesrequest and reply messages incurred the same delay

    Actual clock value of the server (when reply message isreceived by the client) can vary from s to s +Tround dependingon the actual delay incurred by request and reply messages

    Skew in clients clock value just after synchronization lies in

    the range Tround

    2

  • Table of Contents

    Motivation

    Types of Clock SynchronizationExternal SynchronizationInternal Synchronization

    Algorithms for Clock SynchronizationCristians AlgorithmThe Berkeley AlgorithmNetwork Time Protocol (NTP)

  • The Berkeley Algorithm

    Performs internal synchronization

    Master-slave approach: One of the machines is chosen as master Other machines become slaves

    Algorithm is polling based: Master periodically requests all slaves to send their clock values It then estimates the current clock value of each slave by

    observing the round-trip time (similar to Cristians algorithm)

  • The Berkeley Algorithm (Contd.)

    Slave S

    Master

    t1

    Slave S

    Master

    t2

    c

    t1

    Slave S

    Master

    t3t2t1

    Master

  • The Berkeley Algorithm (Contd.)

    Slaves

    compute the average

    Master

    Master computes the average of all (estimated) clock valuesincluding its own once it has received clock values from allslaves

    To each slave, it sends the amount by which the slaves clockrequires adjustment

  • Table of Contents

    Motivation

    Types of Clock SynchronizationExternal SynchronizationInternal Synchronization

    Algorithms for Clock SynchronizationCristians AlgorithmThe Berkeley AlgorithmNetwork Time Protocol (NTP)

  • Network Time Protocol

    Used for distributing time information over the Internet

    Service is provided by a network of servers arranged in ahierarchical manner

    Servers at highest-level (root) are primary servers Directly connected to a time source (e.g., radio clock receiving

    UTC)

    Servers at lowest-level (leaf) are users workstations Servers at each level are synchronized with servers at a higher

    level (to prevent cycles)

    Clock accuracy decreases as level decreases

  • Network Time Protocol (Contd.)

    A

    B

    A

    B

    A

    B

    B

  • Network Time Protocol (Contd.)

    Notation: o: actual offset of B s clock relative to that of As clock 1: transmission time for the first message 2: transmission time for the second message : total transmission time for the two messages oe : estimate of o

    1 = Tr1 (T

    s1 + o)

    2 = (Tr2 + o) T

    s2

    = 1 + 2 = Tr1 T

    s1 + T

    r2 T

    s2

    Set oe asT r1 T

    s1 + T

    s2 T

    r2

    2

  • Network Time Protocol (Contd.)

    Subtracting 1 from 2, we obtain:

    o = oe +2 1

    2

    This implies that:

    |o oe | |2 1|

    2

    |2 + 1|

    2=

    2

    Interpretation: oe is an estimate of oe with error bounded by

    2

    Client A computes many (oe , /2) pairs: Selects offset estimate with the least error for clock adjustment

    MotivationTypes of Clock SynchronizationExternal SynchronizationInternal Synchronization

    Algorithms for Clock SynchronizationCristian's AlgorithmThe Berkeley AlgorithmNetwork Time Protocol (NTP)