Categories
Java Low Latency Technology

Cost of Locks, CAS and Memory Access

The absolute numbers below will change as technology progresses but the relative numbers should stay the same. According to LMAX the relative cost of locks and CAS is as follows (May 2011):- Operation (500 million times) Cost (ms) Relative Cost Single thread 300 1 Single thread with lock 10000 33 Two threads with lock 224000 […]

            The absolute numbers below will change as technology progresses but the relative numbers should stay the same.

According to LMAX the relative cost of locks and CAS is as follows (May 2011):-

Operation (500 million times) Cost (ms) Relative Cost
Single thread 300 1
Single thread with lock 10000 33
Two threads with lock 224000 747
Single thread with CAS 5700 19
Two threads with CAS 30000 100
Single thread with volatile write 4700 16
And according to Pinku Surana (Handwaving), here are the numbers for memory access (Jan 2009):-
Operation Cost (ns) Relative Cost
L1 cache reference 0.5 1
Branch mispredict 5 10
L2 cache reference 7 14
Mutex lock/unlock 100 200
Main memory reference 100 200
Compress 1K bytes with Zippy 10,000 20,000
Send 2K bytes over 1 Gbps network 20,000 40,000
Read 1 MB sequentially from memory 250,000 500,000
Round trip within same datacenter 500,000 1,000,000
Disk seek 10,000,000 20,000,000
Read 1 MB sequentially from network 10,000,000 20,000,000
Read 1 MB sequentially from disk 30,000,000 60,000,000
Send packet CA->Netherlands->CA 150,000,000 300,000,000