Download presentation
Presentation is loading. Please wait.
Published byRiikka Mikkonen Modified over 5 years ago
1
by Manas Hardas for Advanced Operating Systems Nov 27th 2007
Implementing Lamport's Scalar clocks and Singhal-Kshemkalyani’s vector clocks by Manas Hardas for Advanced Operating Systems Nov 27th 2007
2
Lamport's Scalar clocks
to implement “” in a distributed system, Lamport (1978) introduced the concept of logical clocks, which captures “” numerically each process Pi has a logical clock Ci process Pi can assign a value of Ci to an event a: step, or statement execution the assigned value is the timestamp of this event, denoted C(a) the timestamps have no relation to physical time, hence the term logical clock P1 e11 (1) e12 (2) e13 (3) e14 (4) e15 (5) e16 (6) e17 (7) P2 e21 e22 e23 e24 e25
3
Problem with scalar clocks
Total ordering , strong consistency i.e. if Ca < Cb then a b Concurrent events cannot be ordered Total order is needed to form a computation i.e. before generating a computation we should know exact event going to take place Example scalar clocks cannot determine total order of events Scalar clocks are not strongly consistent e11 e12 e13 P1 (2) (3) (1) e21 e22 P2 (1) (4) c21 < c12 (1<2) ; e21 ==> e12 c12 < c22 and e12 e22 is true e11 e12 e13 P1 (3) (1) (2) e21 e22 P2 (1) (4) c21 < c12 (1<2) ; e21 ==> e12; e12 ==> e21 c21 < c12 but e21 e12 is not true
4
SK implementation of vector clocks
LU LS 1 2 P T LU LS 1 2 P T LU LS 1 2 P T LU LS 1 2 e11 e12 e13 P1 (1,2) e21 e22 P2 comment on strong consistency of vector clocks P T LU LS 1 2 P T LU LS 1 2 P T LU LS 1 2
5
Code implementation Class diagram for Lamports and SK algorithm
Process id:int processName:string currClock:int prevClock:int clockAtEvent: vector<int> Process(); void localEvent(Message) void sendEvent(Message) void receiveEvent(Message) 1 1…n executes Message sender:int receiver:int sendingEvent:int receivingEvent:int senderProcessClockTimestamp:int messageString:string 1…m 1 processes SimulatorEngine computation: vector< vector<int>> processArray[N]: Process mq: MessageQueue void initProcesses(); void readComputation(string); void initSimEngine(); void runSimulation(); 1 MessageQueue messageQueue: queue<Message> void enqueue(Message) Message dequeue(); bool isEmpty(); int queueSize(); 1
6
Messages exchanged in SK algorithm
Standard vector clock implementation not scalable because of n*n message size Singhal-Kshemkalyani’s algorithm tries to reduce this by just sending what values have changed in updates However this parameter is decreased only if communication is localized In case of all processes actively participating in communication SK algorithm is as effective as any vector clock implementation Efficiency of the technique as given by SK is ( 1 – (log2N + b). n / b . N ) . 100% Therefore SK technique is only efficient if, n < N . b / (log2N + b) Where, n = localized processes N = total processes b = number of bits in a sequence number N = number of bits needed to encode N
7
HYPOTHESIS There is only a linear increase in the updates in the messages sent as the number of processes in the system increases given a constant number of messages (maximum N updates for a message) to be sent are randomly generated for localized vs. non-localized communication. Reasoning for hypothesis: - consider 100 processes in a system. for localized say if only 5 processes are exchanging messages i.e. there are changes in only 5 process clocks, then the maximum number of updates are not going to exceed 5. if all 100 processes are exchanging messages then the maximum number of updates a message could contain is 100. therefore there is a linear increase in the messages being exchanged as the communication goes from localized to non-localized
8
Computations e11 e12 P1 (2) (1) e21 e23 e22 P2 (3)
Computations can be randomly generated or extracted from a comma separated file. The representation for a computation is as follows: For Lamport’s implementation computation format: eventType|sender|receiver|sendingEvent|receivingEvent where event type 00=local; 01=send; 10=receive Example: 00,1,1,0,0, --> local event at 1 00,2,2,0,0, --> local event at 2 01,1,2,2,3, --> send e(1,2) to e(2,3) 10,1,2,2,3, --> receive e(1,2) to e(2,3) P1 e11 (1) e12 (2) P2 e21 e23 (3) e22
9
computations cont’d P1 P2 P3
For SK implementation Computation format: sender|receiver|sendingEvent|receivingEvent Example: 1,1,0,0, --> local event at 1 (if sender=receiver local event) 2,2,0,0, --> local event at 2 3,3,0,0, --> local event at 3 1,2,0,0, --> 1 sends to 2 and 2 receives (no delay) 3,2,0,0, --> 3 sends to 2 and 2 receives 2,3,0,0, --> 2 sends to 3 and 3 receives 3,1,0,0, --> 3 sends to 1 and 1 receives P1 P2 P3
10
Testing the hypothesis: Results
The computations were randomly generated using a uniform distribution By random it means that the sender and receiver of the messages were randomly generated For localized communication, the number of processes exchanging messages were kept to N/10 (minimum N=20; therefore only p0 and p1 exchanging messages, which processes exchange messages is not important) For non-localized all processes were allowed to exchange messages. The number of messages to be randomly generated were then changed to see if that made any difference Also the rule N/10 was later changed to see that made any difference
11
No. of updates vs. No. of processes for localization rule n = N/10
M=10 M=100 M=500 N L NL 20 2.4 32.5 10.4 169.6 15.6 40 0.2 25.6 4.1 167.3 27.7 60 1 19.4 142.3 12.3 80 12.7 104.5 5.8 100 12 85.4 11 200 8.2 50.6 7.4 Observations: 1.For L as well as NL communication, number of updates always decreases as N increases 2. For L and NL, number of updates increase as M increases.
12
Localization rule SK say that their technique will only be effective when. n < N . b / (log2N + b) So say if, N=20, b=4 and log2N=5 then, n < 20.4/(5+4) ≈ 8 Thus if n < 8 then SK technique is effective, as in the number of updates will not be closer to N. Therefore we change the localization rule from n = N/10 to n = N/2 to test if this hypothesis is true. So now if N=20, n=10(>8) not n=2(<8)
13
No. of updates vs. No. of processes for localization rule n = N/2
M=10 M=100 M=500 N L NL 20 0.4 13.4 10.4 85 15.6 40 9.9 4.1 49.3 27.7 60 1.6 37 12.3 80 5.3 33.9 5.8 100 17.8 11 200 12.9 7.4 Observations: 1. As the localization rule changed for less localization, interestingly the number of updates decreased instead of increasing.
14
No. of updates vs. No. of processes for localization rule n = N/10 and n =N/2 for increasing M
20 2.4 0.4 32.5 13.4 169.6 85 40 0.2 25.6 9.9 167.3 49.3 60 1 19.4 1.6 142.3 37 80 12.7 5.3 104.5 33.9 100 12 85.4 17.8 200 8.2 50.6 12.9
15
Future research We need to figure out why exactly this unexpected phenomenon occurred. Maybe it is not so wise to experiment with randomly generated computations because you don’t know exactly what is going on In our definition of localized communication no other process sends any messages. This can be revised to included some messages sent by other processes.
16
Thank you! Questions?
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.