1 / 40

Chapter 5 Synchronization

Chapter 5 Synchronization. Presenter: Maria Riaz. Sequence of Presentation. Synchronization Clock Synchronization Logical Clocks Global State Election Algorithms Mutual Exclusion Distributed Transactions. Synchronization – Why we need it !. Stand-alone System

Download Presentation

Chapter 5 Synchronization

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 5Synchronization Presenter:Maria Riaz

  2. Sequence of Presentation • Synchronization • Clock Synchronization • Logical Clocks • Global State • Election Algorithms • Mutual Exclusion • Distributed Transactions

  3. Synchronization – Why we need it ! • Stand-alone System • Exclusive access to shared resources • Distributes System • Exclusive access to shared resources • Ordering of Events • Each node in a distributed system has separate local clock • Notion of physical time might differ among various nodes of the system

  4. - Clock Synchronization - • Problem due to different time values at different nodes • When each machine has its own clock, an event that occurred after another event may nevertheless be assigned an earlier time

  5. Physical Clocks (1) • Can all clocks in a distributed system be synchronized ? • If we start all clocks in the system with same initial value, will they remain synchronized for the rest of their operations ? • Some terminology • Skew: instantaneous difference between readings • Drift: different rates of counting time • physical variations of underlying oscillators • variance with temperature • even extremely small differences accumulate over a large number of oscillations • Drift Rate: difference in reading bet. a clock and a nominal “perfect clock” per unit of time measured by the reference clock • 10-6 seconds/sec for quartz crystals • 10-7 - 10-8 seconds/sec for high precision quartz crystals • Problem • How do we synchronize them with real-world clocks • How do we synchronize the clocks with each other

  6. Physical Clocks (2) • Some methods to measure time • Mean solar second: measuring a large numbers of day -- taking average -- dividing by 86400 • TAI (International Atomic Time): the mean number of ticks of the cesium 133 clocks (since 1/1/1958) divided by 9,192,631,770 • Very small drift rate ~ 10-13 seconds/second • UTC: broadcast by NIST from Fort Collins, Colorado over shortwave radio station WWV.

  7. Clock Synchronization Algorithms (1) • The relation between clock time and UTC when clocks tick at different rates • maximum drift rate () • every t seconds, the worst case drift between two clocks will be at most 2t • to guarantee two clocks never differ by more than , the clocks must re-synchronize every /2 seconds

  8. Clock Synchronization Algorithms (2) • Centralized Algorithms • Cristian’s Algorithm (1989) • Berkeley Algorithm (1989) • Decentralized Algorithms • Averaging Algorithms (e.g. NTP) • Multiple External Time Sources

  9. Cristian’s Algorithm • Assume one machine (the time server) has a WWV receiver and all other machines are to stay synchronized with it. • Every /2seconds, each machine sends a message to the time server asking for the current time. • Time server responds with message containing current time, CUTC. • Problem • time must never run backward

  10. Berkeley Algorithm • The time daemon asks all the other machines for their clock values. • The machines answer and the time daemon computes the average. • The time daemon tells everyone how to adjust their clock.

  11. Averaging Algorithms • At the beginning of each interval, every machine broadcasts the current time according to its clock • Then it starts a local timer to collect all other broadcasts that arrive during some interval S • The simplest algorithm is just to average the values from all other machines • A slightly more sophisticated algorithm :: Discard the m highest and m lowest to reduce the effect of a set of faulty clocks • Another improved algorithm :: Correct each message by adding to the received time an estimate of the propagation time from the ith source • extra probe messages are needed to use this scheme • One of the most widely used algorithms in the Internet is the Network Time Protocol (NTP)

  12. - Logical Clocks - • Mostly ‘absolute’ time is not important rather ‘relative’ time is of significance • Internal consistency and ordering of events • If two process don’t interact  no need for synchronization between them • A logical clock is a • Monotonically increasing SW counters (COULOURIS) • Clocks on different computers that are somehow consistent (LAMPORT) • Potential Requirements for logical clocks: • Timestamps : C(a), C(b) • If a happens before b in the same process, C(a) < C(b). • a  b => C(a) < C(b) • If a and b represent the sending and receiving of a message, respectively, C(a) < C(b). • For all distinctive events a and b, C(a) ≠ C(b). • Two methods for assigning logical timestamps • Lamport’s Timestamps • Vector Timestamps

  13. Lamport’s Timestamps (1) • Lamport defined a relation ”happens before”. a  b ‘a happens before b’ (1978) • Each Process has local clock LCi • with each local event e: LCi := LCi + 1; e • with each sending of a message by process Pi: LCi := LCi +1; send (LCi,m) • with each reception of a message “(M,LCm)” by Pj: LCj := MAX(LCm, LCj ); LCj := LCj +1

  14. Lmaport’s Timestamps (2) • Can be used to implement ‘totally ordered multicast’ • A multicast operation by which all messages are delivered in the same order to each receiver

  15. Vector Timestamps • Each process Pi has its own vector clock Ci • Ci : n-dimensional vector (n: number of processes) • Notation: Ci[j] : the timestamp of the last event in Pj by which Pi has potentially been effected • Initially: • all c[i] = 0 • Increment C[i]: • -Events • Send msg • Receive msg

  16. - Global State - • Like a ‘distributed snapshot’ reflecting a state in which the system might have been • represents the last event recorded for each process • Graphically represented by a cut • Consistent : for every received message, the sender can be identified • Cause  Effect

  17. Global State (2) Organization of a process and channels for a distributed snapshot • Process Q receives a marker (start) for the first time and records its local state • Q records all incoming message • Q receives a marker (end) for its incoming channel and finishes recording the state of the incoming channel • final recorded state

  18. - Election Algorithms - • Election algorithms • algorithms for electing a coordinator (using this as a generic name for the special process) • attempt to locate the process with the highest process number and designate it as coordinator • Bully Algorithm • Ring Algorithm • Goal • ensure that when an election starts, it concludes with all processes agreeing on who the new coordinator is to be

  19. Bully Algorithm • A process P detects failure of coordinator and holds an election to be the coordinator • All process with ID > P response • If P receives such a response, it will step back • Processes having ID > P can hold electionsand repeat same procedure • If no response from any process with higher ID, election holder becomes the new coordinator • Example • Process 4 holds election • Process 5 and 6 respond, telling 4 to stop • Now 5 and 6 each hold an election • Process 6 tells 5 to stop • Process 6 wins and tells everyone

  20. Ring Algorithm • Process detects failure of coordinator • Send message to neighbor with its ID • Neighbor adds its ID and pass along • When all process have added their ID, the one with highest ID becomes the coordinator • The message is rotated once again so everyone knows

  21. - Mutual Exclusion - • To control access to a critical section • Centralized Algorithm • Distributed Algorithm • Token Ring Algorithm

  22. Centralized Algorithm • Process 1 asks the coordinator for permission to enter a critical region. Permission is granted • Process 2 then asks permission to enter the same critical region. The coordinator does not reply • When process 1 exits the critical region, it tells the coordinator, when then replies to 2

  23. Distributed Algorithm • Two processes want to enter the same critical region at the same moment • Process 0 has the lowest timestamp, so it wins • When process 0 is done, it sends an OK also, so 2 can now enter the critical region

  24. Token Ring Algorithm • unordered group of processes on a network • logical ring constructed in software A token is passed along the ring to allow access to the critical section

  25. Comparison A comparison of three mutual exclusion algorithms

  26. - Distributed Transactions - • Basic (Flat) Transactions & Limitations • Alternatives • Distributed Transactions • Nested Transactions • Problems • Concurrency Control • Synchronization

  27. The Transaction Model (1) Updating a master tape is fault tolerant

  28. The Transaction Model (2) Examples of primitives for transactions

  29. ACID - Four Characteristics • Atomic: to the outside world, the transaction happens indivisibly • Consistent: the transaction does not violate system invariants • Isolated: concurrent transactions do not interfere with each other • Durable: once a transaction commits, the changes are permanent

  30. Limitations of Flat Transactions Main limitation: do not allow partial results to be committed or aborted • updating all of the hyperlinks to a webpage W, which moved to a new location

  31. Classification of Transactions • A nested transaction • A distributed transaction

  32. Private Workspace Make a copy of the original workspace and perform all operation in the copied ‘private’ space before committing read only  no need for private copy a) The file index and disk blocks for a three-block file b) The situation after a transaction has modified block 0 and appended block 3 b) After committing

  33. Write-Ahead Log a) A transaction b) – d) The log before each statement is executed

  34. Concurrency Control (1) General organization of managers for handling transactions

  35. Concurrency Control (2) General organization of managers for handling distributed transactions

  36. Synchronization • Two operations are serializable if the order of operations does not change the outcome i.e., the operations do not conflict • properly schedule conflicting operations (two read operations never conflict) • Mechanism for synchronization • Mutual Exclusion mechanisms on shared data (i.e locking) • Two-Phase Locking • Strict Two-Phase Locking • Explicitly ordering operations using timestamps • Pessimistic Timestamp Ordering

  37. Two-phase locking • A transaction T is granted a lock if there is no conflict • The scheduler will never release a lock for data item x, until the data manager acknowledges it has performed the operation for which the lock was set • Once the scheduler has released a lock on behalf of a transaction T, it will never grant another lock on behalf of T

  38. Strict two-phase locking • In centralized 2PL: a single site is responsible for granting and releasing locks • In primary 2PL: each data item is assigned a primary copy • In distributed 2PL: the schedulers on each machine not only take care that locks are granted and released, but also that the operation is forwarded to the (local) data manager

  39. Pessimistic Timestamp Ordering Concurrency control using Timestamps

  40. Thank you ! Questions ?

More Related