lamport’s logical clocks l lamport’s logical clocks i ...sbarker/teaching/courses/... ·...

4
Sean Barker Lamport Clocks 1 a b c d e f m 1 m 2 2 1 3 4 5 1 p 1 p 2 p 3 Physical time Sean Barker Vector Clocks 2 p 1 p 2 p 3 a b c d e f m 1 m 2 Physical time

Upload: others

Post on 23-Jul-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lamport’s Logical Clocks L Lamport’s Logical Clocks i ...sbarker/teaching/courses/... · Lamport’s Logical Clocks" • A logical clock is a monotonically increasing software

Sean Barker

Lamport Clocks

1

3/14/14

7

37"

NTP Statistics"

•  In 1999 there were 175,000 hosts running NTP in the Internet"

•  Among these there were:"•  Over 300 valid Stratum 1 servers (they are never

contacted directly, unless you are a Stratum 2 server)"•  Over 20,000 servers at Stratum 2"

•  Over 80,000 servers at Stratum 3"

•  Accuracy of 10s of milliseconds over Internet paths (even more accurate on LANs)"

38"

Logical Clocks"

39"

Logical Time and Logical Clocks"•  Instead of synchronizing clocks, event ordering can be used"•  Rules:"

1. If two events occurred at the same process pi (i = 1, 2, … N) then they occurred in the order observed by pi, that is → "

2. When a message m is sent between two processes, send(m) happened before receive(m)"

3. The happened before relation is transitive"

p1

p2

p3

a b

c d

e f

m1

m2

Physical

time

40"

Happened Before Relation"•  What do we know about events a, b, c, d, e?"

•  Rule 1: a → b (at p1), c → d (at p2)"•  Rule 2: b → c (by m1), d → f (by of m2)"•  Rule 3: a → b → c → d → f = a → f "

•  What do we know about a and e?"•  No relation - they are concurrent: a || e"

p1

p2

p3

a b

c d

e f

m1

m2

Physical

time

41"

Lamport’s Logical Clocks"•  A logical clock is a monotonically increasing software counter. It need not

relate to a physical clock."•  Each process pi has a logical clock, Li which can be used to apply logical

timestamps to events using the following rules:"•  LC1: Li is incremented by 1 before each event at process pi, Li = Li + 1"•  LC2: "•  (a) when process pi sends message m, it piggybacks on m the value t = Li "

•  (b) when pj receives (m,t) it sets Lj := max(Lj, t) and applies LC1 before timestamping the event receive (m)"

p1

p2

p3

a b

c d

e f

m1

m2

Physical

time

42"

Lamport’s Logical Clocks"•  Each of p1, p2, p3 has its logical clock initialized to zero "•  The clock values on events are those immediately after the event"

•  e.g. 1 for a, 2 for b. "•  For m1, t = 2 is piggybacked and c gets L2 = max(0,2)+1 = 3 "•  Note that e → e’ implies L(e) < L(e’)"•  Does L(e) < L(e') imply e → e’ ?"

•  No! The converse is not true: L(e) < L(e') does not imply e → e’"

•  Example: L(e) < L(b) but b || e"

a b

c d

e f

m1

m2

21

3 4

51

p1

p2

p3

Physical time

Sean Barker

Vector Clocks

2

3/14/14

7

37"

NTP Statistics"

•  In 1999 there were 175,000 hosts running NTP in the Internet"

•  Among these there were:"•  Over 300 valid Stratum 1 servers (they are never

contacted directly, unless you are a Stratum 2 server)"•  Over 20,000 servers at Stratum 2"

•  Over 80,000 servers at Stratum 3"

•  Accuracy of 10s of milliseconds over Internet paths (even more accurate on LANs)"

38"

Logical Clocks"

39"

Logical Time and Logical Clocks"•  Instead of synchronizing clocks, event ordering can be used"•  Rules:"

1. If two events occurred at the same process pi (i = 1, 2, … N) then they occurred in the order observed by pi, that is → "

2. When a message m is sent between two processes, send(m) happened before receive(m)"

3. The happened before relation is transitive"

p1

p2

p3

a b

c d

e f

m1

m2

Physical

time

40"

Happened Before Relation"•  What do we know about events a, b, c, d, e?"

•  Rule 1: a → b (at p1), c → d (at p2)"•  Rule 2: b → c (by m1), d → f (by of m2)"•  Rule 3: a → b → c → d → f = a → f "

•  What do we know about a and e?"•  No relation - they are concurrent: a || e"

p1

p2

p3

a b

c d

e f

m1

m2

Physical

time

41"

Lamport’s Logical Clocks"•  A logical clock is a monotonically increasing software counter. It need not

relate to a physical clock."•  Each process pi has a logical clock, Li which can be used to apply logical

timestamps to events using the following rules:"•  LC1: Li is incremented by 1 before each event at process pi, Li = Li + 1"•  LC2: "•  (a) when process pi sends message m, it piggybacks on m the value t = Li "

•  (b) when pj receives (m,t) it sets Lj := max(Lj, t) and applies LC1 before timestamping the event receive (m)"

p1

p2

p3

a b

c d

e f

m1

m2

Physical

time

42"

Lamport’s Logical Clocks"•  Each of p1, p2, p3 has its logical clock initialized to zero "•  The clock values on events are those immediately after the event"

•  e.g. 1 for a, 2 for b. "•  For m1, t = 2 is piggybacked and c gets L2 = max(0,2)+1 = 3 "•  Note that e → e’ implies L(e) < L(e’)"•  Does L(e) < L(e') imply e → e’ ?"

•  No! The converse is not true: L(e) < L(e') does not imply e → e’"

•  Example: L(e) < L(b) but b || e"

a b

c d

e f

m1

m2

21

3 4

51

p1

p2

p3

Physical time

Page 2: Lamport’s Logical Clocks L Lamport’s Logical Clocks i ...sbarker/teaching/courses/... · Lamport’s Logical Clocks" • A logical clock is a monotonically increasing software

Sean Barker

Simple Mail Transfer Protocol (SMTP)

3

3/7/14

6

31"

Java RMI vs. XML-RPC"

•  Java RMI is arguably simpler "•  Programs look a bit more “normal”"•  Can serialize (by implementing Serializable) and

return different objects "•  (See example)"

•  XML-RPC is more flexible"•  Can interact (easily) with other XML-RPC clients

written in different languages"•  But procedure calls are somewhat limiting"•  Difficult to send non-standard objects"

32"

Take-Away Message"

•  RPCs handle the marshaling and unmarshaling of data automatically"

•  Also handle threading, message formatting, socket creation, etc."

•  Designed to simplify network programming through familiar programmatic abstractions"

•  You should appreciate all of this after building your web servers!"

33"

BREAK"

34"

Intro to Email: !Terminology"

•  Mail User Agent: end-user email program"•  Mail Transfer Agent: program responsible for

communicating with remote hosts and transmitting/receiving email"•  Think of this as the mail server software"

•  Mail Exchanger: host with specific IP address (registered with DNS) that takes care of email for a domain"

35"

SMTP"

•  Used to exchange mail messages between mail servers (Message Transfer Agents)"

MTA" MTA"

MUA"

SMTP"

File"System"

MTA"SMTP"

MUA"

36"

SMTP Protocol"

•  SMTP sender is the client"•  SMTP receiver is the server"•  Alternating dialogue:"•  Client sends command and server responds with

command status message"•  Order of the commands is important"•  Status messages include ASCII encoded numeric status

code (like HTTP) and text string"

Sean Barker

POP: Post Office Protocol

4

3/11/14

3

13"

POP – Post Office Protocol"

•  Used to transfer mail from a mail server to a MUA"

Mail"Server" MUA"

File"System"

POP"

14"

POP (version 3)"

•  Similar to SMTP command/reply lockstep protocol"

•  Used to retrieve mail for a single user"•  Requires authentication"

•  Commands and replies are ASCII lines"•  Replies start with “+OK” or “-ERR”. •  Replies may contain multiple lines"

15"

POP-3 Commands"•  USER - specify username"•  PASS - specify password "•  STAT - get mailbox status"

•  Return number of messages in the mailbox"

•  LIST - get a list of messages and sizes"•  One per line, termination line contains ‘.’ only"

•  RETR - retrieve a message"•  DELE - mark a message for deletion from the mailbox"•  NOOP - send back positive reply"•  RSET - reset; all deletion marks are unmarked"•  QUIT - remove marked messages and close the (TCP)

connection"

16"

A POP3 Exchange"albrecht:~ telnet fuji.cs.williams.edu 110 !Trying 137.165.8.2... !Connected to fuji.cs.williams.edu. !Escape character is '^]'. !+OK POP3 at fuji.cs.williams.edu server ready "USER jcool !+OK Name is a valid mailbox!PASS nomoresnow !+OK jeannie has 1 visible message in 1761 octets. !STAT !+OK 1 1761!LIST !+OK 1 visible messages (1761 octets) !1 1761!."

17"

POP3 Example Continued"

•  RETR 1!+OK 1761 octets!Received: from fuji.cs.williams.edu""From: “Jeannie Albrecht” <[email protected]>""To: <[email protected]>""Subject: test""Date: Tue, 11 Mar 2014 10:31:21 -0400"

Content-Type: text/plain;charset=“US-ASCII”"""test"".""

18"

IMAP"

•  IMAP stands for Internet message access protocol!

•  Very widely used today"•  Used to transfer messages from server to

client"

Page 3: Lamport’s Logical Clocks L Lamport’s Logical Clocks i ...sbarker/teaching/courses/... · Lamport’s Logical Clocks" • A logical clock is a monotonically increasing software

Sean Barker

IMAP vs POP

5

3/11/14

4

19"

IMAP vs. POP"

http://wiki.bath.ac.uk/display/bucstech/Imap+overview" 20"

IMAP Advantages Over POP"

•  POP clients connect, download, and disconnect. IMAP clients often stay connected and download on demand"

•  POP only allows one connected client at a time; Simultaneous access by multiple IMAP clients is allowed"

•  POP does not allow message state (i.e., read/unread) to be stored on server; IMAP does"

•  POP does not allow for server-side searchers, IMAP does"

21"

IMAP Disadvantages"

•  More complex protocol"•  Clients need to maintain TCP/IP connection

to server (this is a big deal!)"•  If server goes down, user cannot access (even

previously read) messages"•  Flaky network connections render clients

unusable"

22"

Moving on…"

Yasushi Saito 1999

Functionally Homogeneous Clustering: "A New Architecture for Scalable "Data-intensive Internet Services!

24"

Goals"

•  Use cheap, unreliable hardware components to build scalable data-intensive Internet services."•  Specifically focus on services where data is written

frequently and high performance is required"

•  Three facets of scalability "•  Performance: "linear increase with system size"•  Manageability: "react to changes automatically"•  Availability: "survive failures gracefully"

" " " ""

Sean Barker

Porcupine

6

Page 4: Lamport’s Logical Clocks L Lamport’s Logical Clocks i ...sbarker/teaching/courses/... · Lamport’s Logical Clocks" • A logical clock is a monotonically increasing software

Sean Barker

Porcupine Architecture

7

3/11/14

6

31"

Overview: Porcupine"

SMTP server

POP server

IMAP server

Mail map User

profile

Replication Manager

Membership Manager

RPC

Load Balancer

User map

Email msgs

Internet

LAN

Porcupinecluster

DNS

Router/firewall

32"

Receiving Email in Porcupine"

Internet

A B ...

A

1. “send mail to

bob”

2. Who manages bob? ⇒ A

3. “Verify bob”

5. Pick the best nodes to store new msg ⇒ {C,D}

DNS-RR selection

4. “OK, bob has msgs on C, D, & E

6. “Store msg”

B

C

Protocol handling

User lookup

Load Balancing

Data store (replication)

... C

D

7. “Store msg”

D

33"

Basic Data Structures"

User map

Mail map / user profile

Mailbox storage

bob

B C A C A B A C

bob: {A,C} ann: {B}

B C A C A B A C

suzy: {A,C} joe: {B}

B C A C A B A C

hash(“bob”) = 2

A B C

Bob’s MSGs

Suzy’s MSGs

Bob’s MSGs

Joe’s MSGs

Ann’s MSGs

Suzy’s MSGs

0 1 2 3 5 4 7 6 0 1 2 3 5 4 7 6 0 1 2 3 5 4 7 6

34"

Porcupine Performance"

0

100

200

300

400

500

600

700

800

0 5 10 15 20 25 30Cluster size

Messages/second

Porcupine

sendmail+popd

68m/day

25m/day

POP performance, no email replication

Sean Barker

Sending Mail in Porcupine

8

3/11/14

6

31"

Overview: Porcupine"

SMTP server

POP server

IMAP server

Mail map User

profile

Replication Manager

Membership Manager

RPC

Load Balancer

User map

Email msgs

Internet

LAN

Porcupinecluster

DNS

Router/firewall

32"

Receiving Email in Porcupine"

Internet

A B ...

A

1. “send mail to

bob”

2. Who manages bob? ⇒ A

3. “Verify bob”

5. Pick the best nodes to store new msg ⇒ {C,D}

DNS-RR selection

4. “OK, bob has msgs on C, D, & E

6. “Store msg”

B

C

Protocol handling

User lookup

Load Balancing

Data store (replication)

... C

D

7. “Store msg”

D

33"

Basic Data Structures"

User map

Mail map / user profile

Mailbox storage

bob

B C A C A B A C

bob: {A,C} ann: {B}

B C A C A B A C

suzy: {A,C} joe: {B}

B C A C A B A C

hash(“bob”) = 2

A B C

Bob’s MSGs

Suzy’s MSGs

Bob’s MSGs

Joe’s MSGs

Ann’s MSGs

Suzy’s MSGs

0 1 2 3 5 4 7 6 0 1 2 3 5 4 7 6 0 1 2 3 5 4 7 6

34"

Porcupine Performance"

0

100

200

300

400

500

600

700

800

0 5 10 15 20 25 30Cluster size

Messages/second

Porcupine

sendmail+popd

68m/day

25m/day

POP performance, no email replication