Clock Synchronization in Centralized Systems
Clock Synchronization in Centralized Systems
a process makes a kernel call to get the time process which tries to get the time later will always get a higher (or equal) time value no ambiguity in the order of events and their time
The rules for enforcing correct interaction are implemented in the form of synchronization mechanisms The following are the synchronization related issues:
Clock Synchronization Event ordering Mutual exclusion Election Algorithms Deadlock
Clock Synchronization
Physical Clocks
synchronize the physical clocks in the machines so that the time difference is limited to a very small value Physical clocks keep time of day Consistent across systems
Logical Clocks
in distributed computation, associating an event to an absolute real time is not essential, we only need to know an unambiguous order of events Logical clock keeps track of event ordering among related (causal) events
Computer clock
A computer clock usually consists of 3 parts :
Quartz crystal that oscillates at a well defined frequency Counter Register keep track of oscillations of quartz crystal which is decremented by 1 for each oscillation When the value reaches zero an interrupt is generated called CLOCK TICK Again the register is reinitialized to the vale of a constant register Constant register Stores a constant value of 60 or 100
Computer clock is synchronized with real time clock which stores two extra values in the system
A fixed starting date and time And number of ticks At every clock tick the ISR increments the value of number of ticks to keep the clock running
a)
b)
c)
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. Process 2 waits. When process 1 exits the critical region, it tells the coordinator, which then replies to Process 2
Distributed algorithm
Entering the critical section
send a request to all partners (must be known) await acknowledge from all these
Response to a request
ok, if not interested self or if request smaller than own request queue, otherwise
Ordering
total event order (e.g. based on Lamportsclocks)
A Distributed Algorithm
a) Two processes want to enter the same critical region at the same moment. b) Process 0 has the lowest timestamp, so it wins. c) When process 0 is done, it sends an OK also, so 2 can now enter the critical region.
a) b) c) d)
An unordered group of processes on a network. A logical ring constructed in software. When the ring is initialized, Process 0 is given a token Process entering into CS holds the token, on exit release the token and forward to its neighbor e) It is not permitted to enter a second critical section using the same token.
Failures
Process failure
causes break in the ring hence reconfiguration of ring has to be maintained when failure detected pass the token to the next alive process in the ring when failed process recovers back inform its neighbor previous to it in the ring
Token Loss
Mechanism for loss detection and regeneration Monitor sends frequently a message Who has the Token? Process holding the token appends its ID and sends if monitor receives the message without any ID, concludes that token is lost and hence regenerates and circulates in the ring
Major failure
Monitor may crash who has the token ? message may be lost
So have multiple monitors conduct election to decide who generates the token to avoid multiple tokens being generated
Comparison
Algorithm
Centralized Distributed Token ring
Problems
Coordinator crash Crash of any process Lost token, process crash
Election Algorithms
Many distributed algorithms need one process to act as coordinator
Doesnt matter which process does the job, just need to pick one
Election algorithms: technique to pick a unique coordinator (aka leader election) Examples: take over the role of a failed process, pick a master in Berkeley clock synchronization algorithm Types of election algorithms: Bully and Ring algorithms
Bully Algorithm
Each process has a unique numerical ID Processes know the Ids and address of every other process Communication is assumed reliable Key Idea: select process with highest ID Process initiates election if it just recovered from failure or if coordinator failed 3 message types: election, OK, I am Coordinator Several processes can initiate an election simultaneously O(n2) messages required with n processes
The bully election algorithm Process 4 holds an 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
A Ring Algorithm
receiving process adds its number to the message and passes it along
A Ring Algorithm
Reusable/consumable resources
reusable resource
number of units is constant unit is either free or allocated; no sharing process requests, acquires, releases units Examples: memory, devices, files, tables
consumable resources
number of units varies at runtime process may create new units process may consume units Examples: messages, signals
Resources
Preemptable resources
can be taken away from a process with no ill effects
Example: process swapping form main memory
Nonpreemptable resources
will cause the process to fail if taken away
Example: print request by more than one proceses
The sequence of events required to use a resource by a process is: Request initiated by client
Allocate initiated by system Release - initiated by client If these 3 events happen simultaneously by multiple processes deadlock can happen
Deadlocks
No preemption condition
previously granted resources cannot forcibly taken away
Deadlock Handling Strategies In deadlock avoidance approach to distributed systems, a resource is granted to a process if the resulting global system state is However, due to several problems, deadlock avoidance is impractical in distributed systems. Deadlock detection requires examination of the status of process-resource interactions for presence of cyclic wait. Deadlock detection in distributed systems seems to be the best approach to handle deadlocks in distributed systems.
Deadlock avoidance
Deadlock avoidance - dynamically grants a resource to a process if the resulting state is safe. A state is safe if there is at least one execution sequence that allows processes to run to completion.
In this approach, the OS may delay granting a resource request, even when the resources are available, because doing so will put the system in an unsafe state where deadlock may occur later.
(a)
(b)
(c)
(d)
(e)
(a)
(b)
(c)
(d)