












Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
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
1 / 20
This page cannot be seen from the preview
Don't miss anything!













Spring 2009 CS5523: Operating Systems: slides incorporate materials kindly provided by Prof. Kay A. Robbins. 52
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
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
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
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
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.
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
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
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
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.
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
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
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
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
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 a → b , 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
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;
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
a Updating a replicated database (Initially $1000)
Add $100 (^) Add 1% interest
Result $1111 Result $
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
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.
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
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
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 k ≠ y Æ 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
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
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
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)
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
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