Lamport Timestamps & Election Algorithms for Clock Sync & Mutual Exclusion, Study notes of Computer Science

An overview of clock synchronization and mutual exclusion techniques in distributed systems, focusing on lamport timestamps and election algorithms. The slides cover topics such as reference broadcast synchronization (rbs), lamport timestamps, mutual exclusion, and election algorithms in the context of west virginia university's cs 757 distributed systems course.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-k62
koofers-user-k62 🇺🇸

10 documents

1 / 62

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Copyright © K.Goseva 2008 CS 757 Distributed Systems Slide 1
West Virginia
University
Synchronization
Chapter 6
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e

Partial preview of the text

Download Lamport Timestamps & Election Algorithms for Clock Sync & Mutual Exclusion and more Study notes Computer Science in PDF only on Docsity!

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Synchronization

Chapter 6

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Outline

  • Clock synchronization • Logical clocks • Mutual exclusion • Election algorithms

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Physical Clocks

Computation of the mean solar day

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Physical Clocks

  • Atomic clock (1948) counts transitions of the cesium 133 atom• International Atomic Time (TAI)• TAI seconds are of constant length, unlike solar seconds• Leap seconds are introduced when necessary to keep in phase with the

sun - Universal Coordinated Time (UTC)–UTC replaced the old standard – Greenwich Mean Time which is an astronomical

time

  • OS must have special software to account for leap seconds

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Clock Synchronization Algorithms

Relation between clock time and UTC when clocks tick at different rates•^

ρ

is the maximum drift rate

  • If two clocks are drifting from

UTC in opposite directions at atime

Δ

t after they were synchronized,

they may be 2

ρΔ

t apart

  • To assure that clocks will not

differ more than

δ

, they must be

resynchronized at least every

δ

/(

ρ

) seconds

ρ

ρ

1

1

dC dt

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Global Positioning System

Related problem: Determining one’s position anywhere inthe world

GPS is a satellite-based distributed system launched in 1978^ – 29 satellites, each circulating in an orbit at ~20,

km

  • Each satellite has up to four atomic clocks – A satellite continuously broadcasts its position and timestamps

each message with its local time

  • Three satellites are needed to determine the longitude, latitude, and

altitude of a receiver on Earth

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Global Positioning System

  • When a message is received from satellite

i

with

timestamp

T

,i

the delay

i^

measured by the receiver is

  • As signals travel with the speed of light

c,

the measured

distance from the satellite is

  • The real distance is computes as• If we have four satellites, we have to solve four equations

for the coordinates of the receiver

and

Δ

r

r

i

now

i^

T

T

r

i

r

i

now

i^

c d c T T c c

Δ ⋅ + = Δ ⋅ + − ⋅ = Δ

⋅^

)

(

2

2

2

) ( ) ( ) ( r i r i r i

i^

z z y y x x d − + − + − = )

,

,

(

r

r

r^

z

y

x

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Global Positioning System

Many things are not perfect^ – GPS does not take leap seconds into account. The deviation from

UTC can easily be taken care in software.

  • Atomic clocks in satellites are not always in sync – The position of the satellite is not known precisely – The receiver’s clock has a finite accuracy – The signal propagation speed is not constant – The Earth is not a perfect sphere

Relatively cheap GPS receivers: precision within 1-5 metersfor the location

Professional receivers, hooked up in a computer network:less than 10-35 nanoseconds error for the time

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Network Time Protocol

If

A

’s clock is fast

θ

< 0, which means

A

should set its clock

backward

However, time is not allowed to run backward

Changes are introduced gradually^ – Assume the timer is set to generate 100 interrupts per second, i.e.,

interrupts are 10

msec

apart

  • Slow down: each interrupt adds 9

msec

until the correction is made

  • Speed up: each interrupt adds 11

msec

until the correction is made

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Network Time Protocol

Network Time Protocol (NTP) allows set-up pairwisebetween servers

Eight pairs of (

θ

) values are buffered. The minimum

δ

is

adopted as the best estimate for the delay and the associated θ

as the best estimate of the offset

NTP divides servers into strata^ – a server with a reference clock is startum-1 server

When

A

contacts

B,

it will adjust its time only if its stratum

level is higher than the stratum level of

B.

After the

synchronization

A’

s stratum level will become by one

higher than

B

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Use of synchronized clocks

In the last few years, hardware and software forsynchronizing clocks on a wide scale (i.e., over the entireInternet) has become available^ – With this new technology, it is possible to keep millions of clocks

synchronized to within a few milliseconds of UTC

New algorithms that utilize synchronized clocks are startingto appear^ – Enforce at-most-once message delivery to a server, even in the

face of crashes

  • Achieve cache consistency – Handle commitment to atomic transaction

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

The Berkeley Algorithm

a)

The time daemon polls all the other machines for their clock values b) The machines answer c)

The time daemon tells estimates an average time and tells everyone how toadjust their clocks

Suitable when no machine has a WWV receiver. The time server (i.e., daemon) is active.

Copyright © K.Goseva 2008

CS 757 Distributed Systems

West VirginiaUniversity

Clock Synchronization in Wireless

Networks

  • When a sender broadcasts a reference message

m,

each

node

p

records the time when it receives the message

T

p,m

from its local clock

  • Two nodes

p

and

q

exchange their corresponding times, so

they can estimate their relative offsetwhere

M

is the total number of reference messages sent

p

will know the value of

q

’s clock relative to its own

M

T

T

q p

Offset

M k

k q

k p

=

=

1

,

,^

)

(

] , [

Copyright © K.Goseva 2008

CS 757 Distributed Systems

Slide 20

West VirginiaUniversity

Clock Synchronization in Wireless

Networks

  • The previous estimate works only if the clocks do not drift

apart

  • If the clocks of

p

and

q

drift apart, the later values will be

less accurate than the earlier values and simple average asin the previous slide will not work

  • Algorithm that uses linear regression to compute the offset

The constants

α

and

β

are computed from the pairs

β

α

=

t

t

q

p

Offset

)

](

,

[

)

,

(

,

,^

k q

k p^

T

T