Transcript Slide 1

Implementation of
Lamport's Scalar clocks and
Singhal-Kshemkalyani’s VC
Algorithms
Kent State University
Computer Science Department
Saleh Alnaeli
Advanced Operating System. Spring 2010
Goals
Implementing both of the algorithms
 study their behavior under some different
arguments

 Processes
Number
 Messages Number
 Involved processes Number in the computation
Note: This presentation assumes that you have a back
ground about Logical Clocks and some of its related
algorithms (Scalar, Vector, S-K).
Lamport's Scalar clocks



was proposed by Lamport 1978
to totally order events in distributed system
each process Pi has a logical clock Ci (represented as integer
value)

consistency condition

consistency: if ab, then C(a)  C(b)


strong consistency: consistency and


if event a happens before event b, then the clock value (timestamp) of
a should be less than the clock value of b
if C(a)C(b) then ab
scalar clocks are not strongly consistent:


if ab, then C(a)  C(b) but
C(a)  C(b), then not necessarily ab
Implementation of Scalar Clocks



Rule1: before executing event update Ci so, Ci := Ci + d
(d>0)
Rule2:
attach timestamp of the send event to the
transmitted message when received, timestamp of receive
event is computed as follows: Ci := max(Ci , Cmsg) and then
execute R1
It is implemented in C++ and was verified in different ways:
 Checking its consistency using a function compares the
new value of previous one locally and with the sender in
receive event
 Results were compared with vector clock application
Generating the computations
Computations were entered from input text file
 Generated manually and using a computation generator
developed in C++ randomly (random sender and receiver)
 Each event is constructed according the following scheme:
EventType,SenderID,ReceiverID such that:

EventType is 1 for internal event, 2 for send event and 3 for receive
event.
 Example:3,7,8 means an event to receive a SMS was sent by
Pcocess 7 to 8 // Also
 order of the events can be changed in the InputFile just make sure
the receive event is preceeded by send event
 SMS not found or lost for receive without send event.
 Sending to process it self is an internal event. Example 2,5,5
Singhal-Kshemkalyani’s
Algorithm for vector clock S-K



Considered as an efficient implementation of
vector clocks.
instead of sending the whole vector only need to
send elements that changed. And same update
rules are used for the recipient process.
maintain two vectors :




LS[1..n] – “last sent”
LU[1..n]
needs to send with the message only the elements that meet
the condition: {(x,vti[x])| LSi[j] < LUi[x]}
The sent vector contains the processes’ Id’s and
Clock values of changed processes.
S-K Implementation

It is implemented in C++ and was verified in different ways:
 Results were compared with others generated by a
combined Scalar and vector clock application.
 Known examples and random computations were used.

Computations were entered from input text file
Computations were generated using a computation
generator developed in C++.

Events construction scheme

similar to scalar events format with extra field:

EventType,SenderID,ReceiverID,EventId such that:
EventType is 1 for internal event, 2 for send event and 3 for receive
event.
EventId is number of the event when the message has been sent
 Example:3,7,8,4 means an event to receive a SMS was sent by
Process 7 to 8 and the event was the fourth send event
 order of the events can be changed in the InputFile just make sure
the receive event is preceeded by send event
 SMS not found or lost for receive without send event.
 Sending to process it self is an internal event. Example 2,5,5,4
Performance Evaluation

Lamport’s Scalar Clock algorithm:
 There

were not enough area to study (trivial)
S-K algorithms
 Performance

Stamps Memory size used in units (1 unit=32 bytes)
 Conditions

 It’s
metrics evaluated include
of varying
Processes Number, messages Number, and number of the
involved processes in the computation.
expected that SK in the worst case will perform as VC
S-K: Simulation Parameters
Parameter
Default Values
Processes numbers
50-100 // constant 50
Simulation Cycles
15
Messages Number
500-2500
Involved processes in computation
100%-50% // 100%-20% (10-50 of 50)
Events sequence 1
All Send to all and all receive (50 lost)
Event sequence 2
Randomly send and direct receive
Expectations: In the worst case of S-K will be Vector clock’s work.
# processes vs. #messages

events by sequence1 with 2500 messages and 50 lost
figure1 shows that S-K out performance regular VC even with
changing the No of processes and involved processes as well
Processes No vs memory spent with 2500 SMS's and 50 lost
300000
Memory in units

250000
200000
150000
Not
Sufficient
and
not
satisfied
100000
50000
0
0
50
60
70
processes No
80
90
100
VC
S-K
#Messages vs. #involved processes
Events were generated randomly with
sequence 2 (randomly picking sender and
receiver)
 After sending, message is directly
received to got more updates in locals V.
 Constant # of processes 50
 Changing # of involved processes (10-50)

Figure2 shows surprising results
table1
500
Messages Number
1000
1500
10
5318
10804
15264
21152
27020
20
12412
25966
39054
54974
66504
30
17026
40906
64556
85070
110548
40
22698
56564
88224
119018
152488
50
24202
65326
105732
153888
189428
Table2
500
1000
1500
2000
2500
10
25000
50000
75000
100000
125000
20
25000
50000
75000
100000
125000
30
25000
50000
75000
100000
125000
40
25000
50000
75000
100000
125000
50
25000
50000
75000
100000
125000
2000
2500
Used memory in units
# involved processes
Table1 and table2 S-K and VC respectively
Verifying S-K efficiency equation

S-K original paper states that their technique can
be beneficial if n<N.b/(log2N+b)
Such that: n=avr of entries in Ti, b=bits in a sequence
number, log2N=bits needed to code N process ids.

It doesn’t work with my simulation !!!
I
have calculated n value in (2500,40 and 110548,30 )
and I compared it with their equation but did not work!!!

Mine is :
 When
of involved processes gets close to 70% and #of
messages gets close to 20N, then S-K becomes
inefficient.
Conclusion





.
The sequence of the events plays big role in
determining the efficiency of S-K
Number of the involved processes in the
computation can affect S-K performance
For low # of messages, S-K seems fine.
When # of involved processes is about 70% and
#of messages close to 20N then S-K becomes a
weak.
Efficiency equation is not applicable in my
experiment
Difficulties
The most difficult issue was generating a
computation that can be used for
adequate results.
 It’s Difficult to predict the order of receiving
the messages which make it difficult to
generate a computation close to reality.

References
Original S-K paper
 Logical clock, Adv OS course slides.

 Prof.
Mikhail Nesterenko (Acknowledge)
 http://deneb.cs.kent.edu/~mikhail/classes/aos.s10/

S-k implementation-Manas Hardas. KSU.
(Acknowledge)