11. Cost of Contention
Increment a long counter 500M times
One Thread 300ms
One Thread (Volatile) 4700ms x 15
One Thread (Atomic) 5700ms x 19
12. Cost of Contention
Increment a long counter 500M times
One Thread 300ms
One Thread (Volatile) 4700ms x 15
One Thread (Atomic) 5700ms x 19
One Thread (Lock) 10000ms x 33
13. Cost of Contention
Increment a long counter 500M times
One Thread 300ms
One Thread (Volatile) 4700ms x 15
One Thread (Atomic) 5700ms x 19
One Thread (Lock) 10000ms x 33
Two Threads (Atomic) 30000ms x 100
14. Cost of Contention
Increment a long counter 500M times
One Thread 300ms
One Thread (Volatile) 4700ms x 15
One Thread (Atomic) 5700ms x 19
One Thread (Lock) 10000ms x 33
Two Threads (Atomic) 30000ms x 100
Two Threads (Lock) 224000ms x 746
That’s almost
4 minutes!!!
18. • Events are mutable instances of T
• Sequence denotes last available event
• Publisher will publish to the next slot
• EventProcessor will read up to including sequence
46. Memory Barrier
• Load Barrier - invalidates CPU cache and forces all load
instructions after the barrier to happen after the barrier
• Store Barrier - forces all store instructions prior to the barrier to
happen before the barrier and have the store buffers flushed to
cache for the CPU on which it is issued.
a type of instruction that causes a central processing unit (CPU) to enforce an
ordering constraint on memory operations issued before and after the barrier
instruction
47. in Java
volatile - a volatile field has a store barrier inserted
after a write to it and a load barrier inserted before a
read of it.
48.
49. By Sticking to the Single Writer
Principle we can use only volatile
counters to synchronize between
the producer and eventProcessor
56. How Fast Is It - Latency
ArrayBlockingQueue Disruptor
Min 145 29
Mean 32,757 52
99 Percentile 2,097,152 128
99.99 Percentile 4,194,304 8,192
Max 5,069,086 175,567
57. How Fast Is It - Throughput
0.0
7500000.0
15000000.0
22500000.0
30000000.0
Unicast Diamond
ABQ Disruptor
58. When not to use it?
• Events are not deltas but snapshots so that only the
latest needs to be dealt with
• No way of separating your domain logic to multiple
instances (You’re locked to either having shared
state between instances (DB) or one instance with
multiple threads)