Sunteți pe pagina 1din 3

Lamport Algorithm

1. Necessity of synchronization Clock synchronization deals with understanding the temporal ordering of events produced by concurrent processes. It is useful for synchronizing senders and receivers of messages, controlling joint activity, and the serializing concurrent access to shared objects. The goal is that multiple unrelated processes running on different machines should be in agreement with and be able to make consistent decisions about the ordering of events in a system. Communication between processes in a distributed system can have unpredictable delays, processes can fail, and messages may be lost Synchronization in distributed systems is harder than in centralized systems so there is the need for distributed algorithms. Properties of distributed algorithms: i. The relevant information is scattered among multiple machines ii. Processes make decisions based only on locally available information iii. A single point of failure in the system should be avoided iv. No common clock or other precise global time source exists 2. Logical Clock A logical clock is a mechanism for capturing chronological and causal relationships in a distributed system. We introduce the concept of a logical clock, one where the clock need not have any bearing on the time of day but rather be able to create event sequence numbers that can be used for comparing sets of events, such as messages, within a distributed system. Here, the time of day at which the event occurred does not matter but that all processes can agree on the order in which related events occur. Our interest is in getting event sequence numbers that make sense system-wide. These clocks are called logical clocks. In a distributed system, it is not possible in practice to synchronize time across entities (typically thought of as processes) within the system; hence, the entities can use the concept of a logical clock based on the events through which they communicate. Lets say we have a logical clock, LCi for each processor. In this case, whenever an event happens, we shall increment LCi. If a processor, X, sends a message to processor, Y, then processor X will also send LCX, which is that processors logical clock. When processor Y receives this message, then we do: If LCY < (LCX + 1): LCY = LCX + 1 In order to update processor Ys logical clock. 3. Physical clock

Physical clocks keep time of day and difficult to maintain consistency across distributed systems. These are of 3 types: Quartz clocks (piezoelectric effect in quartz crystals), Atomic clocks (based on radiation within atoms like cesium-133 etc) and the UTC (Coordinated universal time obtained from astronomical observations) Physical clocks in computers: Real-time Clock: CMOS clock (counter) circuit driven by a quartz oscillator OS generally programs a timer circuit to generate an interrupt periodically The main problem is getting two systems to agree on time as it is difficult to synchronize 2 clocks because quartz oscillators oscillate at slightly different frequencies. 4. Event Ordering If two entities do not exchange any messages, then they probably do not need to share a common clock; events occurring on those entities are termed as concurrent events. Among the processes on the same local machine we can order the events based on the local clock of the system. When two entities communicate by message passing, then the send event is said to 'happen before' the receive event, and the logical order can be established among the events. A distributed system is said to have partial order if we can have a partial order relationship among the events in the system. If 'totality', i.e., causal relationship among all events in the system can be established, then the system is said to have total order.

5. Explanation of Lamport Algorithm with example The algorithm of Lamport timestamps is a simple algorithm used to determine the order of events in a distributed computer system. As different nodes or processes will typically not be perfectly synchronized, this algorithm is used to provide a partial ordering of events with minimal overhead i. ii. iii. Each process has a clock, which can be a simple counter that is incremented for each event. The sending of a message is an event and each message carries with it a timestamp obtained from the current value of the clock at that process (sequence number). The arrival of a message at a process is also an event will also receive a timestamp by the receiving process, of course. The process clock is incremented prior to timestamping the event, as it would be for any other event. If the clock value is less than the timestamp in the received message, the systems clock is adjusted to the (messages timestamp + 1). Otherwise nothing is done. The event is now time-stamped.

iv.

Each process Pi maintains a local counter Ci and adjusts this counter according to the following rules: 1. For any two successive events that take place within Pi, Ci is incremented by 1. 2. Each time a message m is sent by process Pi, the message receives a timestamp Tm = Ci 3. Whenever a message m is received by a process Pj, Pj, adjusts its local counter Cj: Cj <= max {Cj + 1, Tm + 1} Lets now say that we have a processor A and B. There are a few things we can say: If A precedes (happens before) B, then we can write A > B If A and B are concurrent events, then we cant say anything about their ordering. If A > B is true, then it must also be true that LCA < LCB. However, this is not the case. Just because LCA < LCB does not mean that A > B. Therefore, we can say that we cannot infer a casual ordering of processors just by looking at their timestamps.

S-ar putea să vă placă și