Operating Systems: Threaded Servers, Logical Clocks, and Distributed Synchronizations - Pr, Study notes of Operating Systems

A set of slides from a university course on operating systems, specifically focusing on threaded servers, logical clocks, and distributed synchronizations. The slides cover topics such as threaded clients and servers, thread pools, stateless servers, physical and logical clocks, and various algorithms for clock synchronization and causally ordering messages in distributed systems.

Typology: Study notes

Pre 2010

Uploaded on 07/30/2009

koofers-user-98t-1
koofers-user-98t-1 🇺🇸

5

(1)

9 documents

1 / 20

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
1
CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 52
Spring 2009
Distributed Systems (cont.)
aThreaded server structures
aStateful vs. stateless servers
aPhysical clock/time in distributed systems
¾No global time is available
aLogical clock/time and ‘Happen Before’ Relation
¾Application: total ordering multicast Æconsistency
aVector clocks: causally ordering
aDistributed synchronizations
CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 53
Spring 2009
Threaded Clients/Servers
aThreaded clients for hiding network latency
aThreaded server for high performance
aThread pool concept
Server
N threads
Input-output
Client
Thread 2 makes
T1
Thread 1
requests to server
generates
results
Requests
Receipt &
queuing
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14

Partial preview of the text

Download Operating Systems: Threaded Servers, Logical Clocks, and Distributed Synchronizations - Pr and more Study notes Operating Systems in PDF only on Docsity!

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 52

Distributed Systems (cont.)

aThreaded server structures aStateful vs. stateless servers aPhysical clock/time in distributed systems ¾ No global time is available aLogical clock/time and ‘Happen Before’ Relation ¾ Application: total ordering multicast Æ consistency aVector clocks: causally ordering aDistributed synchronizations

Threaded Clients/Servers

aThreaded clients for hiding network latency aThreaded server for high performance aThread pool concept

Server

N threads

Input-output

Client

Thread 2 makes

T

Thread 1

requests to server

generatesresults

Requests

Receipt &queuing

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 54

Multithreaded Clients

aMain issue is hiding network latency a Multithreaded Web client ¾ Web browser scans an incoming HTML page, and finds that more files need to be fetched; ¾ Each file is fetched by a separate thread by (blocking) HTTP request; ¾ As files come in, the browser displays them a Multiple request-response calls ¾ Client makes several calls at the same time, each by a different thread; ¾ It then waits until all results have been returned; ¾ Note: if calls are to different servers, we may have a linear speed-up compared to doing calls one after the other

Threaded Servers

aImproved performance and better structure a Improve performance ¾ To handle incoming requests, using threads is cheaper than new process; ¾ Having a single-threaded server prohibits simply scaling the server to a multiprocessor system ¾ As with clients: hide network latency by reacting to next request while previous one is being replied. a Better structure ¾ High I/O demands Æ simple, well-understood blocking calls simplifies the overall structure. ¾ Simplified flow of control Æ easy understand

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 58

Servers and States: Stateful Servers

a Keeps track of the status of its clients ¾ Record that a file has been opened, so that pre-fetching can be done ¾ Knows which data a client has cached, and allows clients to keep local copies of shared data

a Observation: The performance of stateful servers can be extremely high , provided clients are allowed to keep local copies.

Servers and States: Stateless Servers

a Never keep information about the status of a client after having handled a request ¾ Don’t record whether a file has been opened (simply close it after access) ¾ Don’t keep track of your clients ¾ Don’t promise to invalidate a client’s cache a Consequences: ¾ Clients and servers are completely independent ¾ Less state inconsistencies due to client/server crashes ¾ Possible loss of performance, e.g., a server cannot anticipate client behavior (think of pre-fetching file blocks)

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 60

Measuring Time

aWhat is a “second”? aTime it takes the cesium 133 atom to make exactly 9,192,631,770 transitions.

aInternational Atomic Time is based on very accurate physical clocks (drift rate 10-13^ )

aIt is based on atomic time, but occasionally adjusted to astronomical time

Universal Coordinated Time (UTC)

a An international standard for time keeping a At present, the real time is taken as the average of some 50 cesium-clocks around the world a Introduces a leap second from time to time to compensate that days are getting longer a National Institute of Standard Time (NIST) operates a shortwave radio station with call letters WWV and broadcast UTC from radio stations on land and satellite a GEOS (Geostationary Environment Operational Satellite) can provide UTC accurately to 0.5 msec a Computers with receivers can synchronize their clocks with these timing signals

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 64

Clock Synchronization Principles

a Principle I: Time server scans all machines periodically, calculate an average, and inform each machine how to adjust its time

a Principle II: Every machine asks a time server for the accurate time at least once every d /(2 r ) seconds ( Network Time Protocol )

a Fundamental: setting the time back is never allowed ⇒ smooth adjustments.

Network Time Protocol (NTP)

aNTP (Mills, 1995) defines an architecture for a time service and a protocol to distribute time information over the Internet. aObjectives ¾ Provide a service enabling clients across the Internet to be synchronized accurately to UTC ¾ Provide a reliable service through the use of redundant servers/paths ¾ Provide protection against interference with the time service, whether malicious or accidental aNeed an accurate measure of round trip delay, interrupt handling and processing messages

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 66

Network Time Protocol (NTP) (cont.)

a Provided by a network of servers located across the Internet a Primary servers are connected to UTC sources a Secondary servers are synchronized to primary servers a Synchronization subnet - lowest level servers in users’ computers

1

2

3

2

3 3

Time in Distributed Systems

a Problem: how to measure time accurately to know the exact time an event occurred in a computer system

a There is no global clock in a distributed system

a Logical time is an alternative ¾ Order of events - also useful for consistency of replicated data

a Algorithms for clock synchronization are useful for ¾ concurrency control based on timestamp ordering ¾ Consistency in distributed transactions ¾ checking the authenticity of requests

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 70

Logical Time

a Distributed system environment implies the absence of perfectly synchronized clocks or global time.

a The order of two events occurring at two different computers cannot be determined based on their “local” time.

a Problem: How do we maintain a global view on the a system’s behavior that is consistent with the happened- before relation

a The notion of logical time/clock is fairly general and constitutes the basis of many distributed algorithms

Logical Clocks (Lamport, 1978)

a Solution: attach a timestamp C ( e ) to each event e , satisfying the following properties

a P1: If a and b are two events in the same process , and ab , then we demand that C ( a ) < C ( b ).

a P2: For different processes, if a corresponds to sending a message m , and b to the receipt of that message, then also C ( a ) < C ( b ).

aHow to get timestamp Æ consistent logical clocks

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 72

Logical Clocks (Lamport, 1978)

aEach process Pi maintains a logical clock, which is a monotonically increasing software counter (no relation to physical clock ) aUpdate the logical clock/counter following ¾ For any two successive events that take place within Pi , Ci is incremented by 1; ¾ Each time a message m is sent by process Pi , the message receives a timestamp ts ( m ) = Ci; ¾ Whenever a message m is received by a process Pj , Pj adjusts its local counter Cj to max{ Cj , ts ( m )}; then executes step 1 before passing m to the application;

Logical Clock: Properties

a e Æ e ’ implies L ( e ) < L ( e ’)

aThe converse is not true, that is L ( e ) < L ( e' ) does not imply e Æ e ’. ( e.g. L ( b ) > L ( e ) but b || e)

aLamport’s “happened before” relation defines an irreflexive partial order among the events in the distributed system

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 76

An Example: Logical Clock Application

a Updating a replicated database (Initially $1000)

Add $100 (^) Add 1% interest

Result $1111 Result $

Totally-Ordered Multicast

aConsider a group of n distributed processes, m ≤ n processes multicasts “update” messages ¾ How to guarantee that all the updates are performed in the same order by all the processes?

a Assumptions ¾ No messages are lost ( Reliable delivery ) ¾ Messages from the same sender are received in the order they were sent ( FIFO ) ¾ A copy of each message is also sent to the sender

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 78

Totally-Ordered Multicast (cont.)

a Process Pi sends time stamped message msgi to all others. The message itself is put in a local queue queuei.

a Any incoming message at Pj is queued in queuej , according to its timestamp, and acknowledged to every other process.

a Pj passes a message msgi to its application if: ¾ (1) msgi is at the head of queuej ¾ (2) for each process Pk , there is a acknowledgement message msgk in queuej with a larger timestamp.

For The Example

aS1 sends Req(update1, 20) at time 20 aS2 sends Req(update2, 15) at time 15 aS1 receives Req(update1, 20) at time 21, and Req(update2, 15) at time 22; send ack. for update request at time 23; aS2 receives Req(update2, 15) at time 16, and Req(update1, 20) at time 21; send ack. for update request at time 22; aOn both S1, S ¾ Queue: Req(update2, 15), Req(update1, 20), ack …

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 82

Vector Clock: Update

a Rule 1: Before executing an event P i executes VC i [ i ] ← VC i [ i ] + 1.

a Rule 2: When process P i sends m to P j , it sets m ’s (vector) timestamp ts (m) = VC i after Rule 1;

a Rule 3: Upon the receipt of m, process P j adjust VC j [ k ] ← max{VC j [ k ], ts (m) [ k ]}, after which it executes Rule 1 and delivers m to the application

Causally Ordered Multicasting

aEnsure to deliver a message only if all causally preceding messages have already been delivered

a Px postpones delivery of m from Py until: ¾ R1: ts ( m )[ y ] = VCx [ y ] + 1; Æ m is the next message expected from Py ¾ R2: ts ( m )[ k ] ≤ VCj [ k ] for ky Æ Px see all messages from other process that Py saw before Py sent out m

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 84

Causally Ordered Multicasting (cont.)

a For P2, when receive m* from P1, ts(m) = (1,1,0), but VC2 = (0,0,0); m is delayed as R2 is not satisfied; a Whe P2 receive m from P0 ts(m)=(1,0,0), with VC2=(0,0,0) Æ both R1 and R2 is ok, and m is delivered Æ VC2 = (1,0,0) Æ m* is delivered

Mutual Exclusion in Distributed Systems

aTo ensure exclusive access to some resource for processes in a distributed system

aSolutions ¾ Centralized server ; ¾ Decentralized , using a peer-to-peer system; ¾ Distributed , with no topology imposed; ¾ Completely distributed along a (logical) ring;

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 88

Distributed: Ricart & Agrawala

aAs Lamport except that ack aren’t sent. Instead, replies (i.e. grants) are sent only when: ¾ Receive process has no interest in the shared resource; or ¾ Receive process is waiting for the resource, but has lower priority (known through comparison of timestamps)

Logical Token Ring

aProcesses in a logical ring, and let a token be passed between them. The one that holds the token is allowed to enter the critical region (if it wants to)

What if the token is lost?!

Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 90

Performance

Summary

a Threaded server structures a Stateful vs. stateless servers a Physical clock/time in distributed systems ¾ No global time is available a Logical clock/time and ‘Happen Before’ Relation ¾ Lamport, 1978 ¾ Application: total ordering multicast Æ consistency a Vector clocks ¾ Causally ordering a Distributed synchronizations ¾ De/Centralized server ¾ Distributed algorithms (Ricart & Agrawala) ¾ Logical token ring