The DisruptorHigh Performance Inter-Thread MessagingMichael Barker @mikeb2701Lead DeveloperLMAX
Thursday, 17 November 11
Mo’vember• Apologies for the silly facial hair• Raising money for men’s health• Donate!!!
2
http://mobro.co/mikeb2701
Thursday, 17 November 11
What is the Disruptor?
http://code.google.com/p/disruptor
Thursday, 17 November 11
static long foo = 0;
private static void increment() { for (long l = 0; l < 500000000L; l++) { foo++;
}
}
Thursday, 17 November 11
public static long foo = 0;public static Lock lock = new Lock();
private static void increment() { int iterations = 500000000L / THREADS; for (long l = 0; l < iterations; l++){ lock.lock(); try { foo++; } finally { lock.unlock(); } }}
Thursday, 17 November 11
static AtomicLong foo = new AtomicLong(0);
private static void increment() { int iterations = 500000000L / THREADS; for (long l = 0; l < iterations; l++) { foo.getAndIncrement(); }}
Thursday, 17 November 11
Increment a counter 500 000 000 times.
• One Thread : 300 ms
Thursday, 17 November 11
Increment a counter 500 000 000 times.
• One Thread : 300 ms• One Thread (volatile): 4 700 ms (15x)
Thursday, 17 November 11
Increment a counter 500 000 000 times.
• One Thread : 300 ms• One Thread (volatile): 4 700 ms (15x)• One Thread (Atomic) : 5 700 ms (19x)
Thursday, 17 November 11
Increment a counter 500 000 000 times.
• One Thread : 300 ms• One Thread (volatile): 4 700 ms (15x)• One Thread (Atomic) : 5 700 ms (19x)• One Thread (Lock) : 10 000 ms (33x)
Thursday, 17 November 11
Increment a counter 500 000 000 times.
• One Thread : 300 ms• One Thread (volatile): 4 700 ms (15x)• One Thread (Atomic) : 5 700 ms (19x)• One Thread (Lock) : 10 000 ms (33x)• Two Threads (Atomic) : 17 000 ms (58x)
Thursday, 17 November 11
Increment a counter 500 000 000 times.
• One Thread : 300 ms• One Thread (volatile): 4 700 ms (15x)• One Thread (Atomic) : 5 700 ms (19x)• One Thread (Lock) : 10 000 ms (33x)• Two Threads (Atomic) : 17 000 ms (58x)• Two Threads (Lock) : 104 000 ms (345x) ^^^^^^^^ > 1.5 minutes!!!
Thursday, 17 November 11
Thursday, 17 November 11
Test Queue Disruptor Factor
OnePublisherToOneProcessorUniCastThroughputTest 2,366,171 72,087,993 30.5
OnePublisherToThreeProcessorDiamondThroughputTest 1,590,126 63,358,798 39.8
OnePublisherToThreeProcessorMultiCastThroughputTest 191,661 54,165,692 282.6
OnePublisherToThreeProcessorPipelineThroughputTest 1,289,199 71,562,125 55.5
OnePublisherToThreeWorkerPoolThroughputTest 2,175,593 10,412,567 4.8
Thursday, 17 November 11
Demo: Concert Tickets...
15
Concert Service
Concert Repository
<entity>Concert
<entity>Section
<event>Concert Created
<event>Allocation Rejected
<event>Allocation Approved
<event>Section Updated
<event>Concert Created
<event>Ticket
Purchase
Thursday, 17 November 11
Demo: Concert Tickets...
16
Request Servlet
Response Servlet
Concert Service
UDP UDP
HTTP Client
Long PollHTTP
Thursday, 17 November 11