Hardware description:
Model name: Intel (R) Xeon (R) CPU E5-2640 0 @ 2.50 GHz
Cpu core: 4
Cache size: 15360 KB
OS: Linux 64bit
JDK: 1.7.0 _ 21-b11
Disruptor 3.2.1:
RingBufferSize: 1024
ProducerType: ProducerType. MULTI
WaitStrategy: BlockingWaitStrategy
Test code (dtest.zip common-disruptor ):
The code is as follows: |
Copy code |
Package org. chinasb. test; Import java. util. concurrent. CountDownLatch; Import org. chinasb. common. disruptor. Event; Import org. chinasb. common. disruptor. dispatch. Dispatcher; Import org. chinasb. common. disruptor. dispatch. RingbufferDispatcher; Public class Test { Static long LOGIC_LOOP = 0; Static long COST = 0; Static int NUM = 5000000; Public static void main (String [] args ){ Boolean multithread = false; Int buffer size = 1024; If (args. length> 0 ){ If (args. length> 0 ){ NUM = Integer. parseInt (args [0]); } If (args. length> 1 ){ Multithread = Boolean. parseBoolean (args [1]); } If (args. length> 2 ){ BufferSize = Integer. parseInt (args [2]); } If (args. length> 3 ){ LOGIC_LOOP = Long. parseLong (args [3]); } } Final Dispatcher dispatcher = new RingbufferDispatcher (multithread, "task executor", bufferSize ); Long start = System. nanoTime (); Final CountDownLatch countDownLatch = new CountDownLatch (NUM ); Final int coreSize = Runtime. getRuntime (). availableProcessors (); For (int I = 0; I <coreSize; I ++ ){ New Thread (new Runnable (){ @ Override Public void run (){ For (int I = 0; I <NUM/coreSize; I ++ ){ Dispatcher. dispatch (Event. wrap (new Runnable (){ @ Override Public void run (){ // Logic Long start = System. nanoTime (); For (long I = 0; I <LOGIC_LOOP; I ++ ){} Double elapsed = (System. nanoTime ()-start)/1000.0; COST + = elapsed; CountDownLatch. countDown (); } })); } } }). Start (); } Try { CountDownLatch. await (); Double elapsed = (System. nanoTime ()-start)/1000000.0; Long throughput = (long) (NUM/(elapsed/1000.0 )); System. out. println ("throughput:" + throughput + "/sec in" + (long) elapsed + "ms "); System. out. println ("average logic:" + COST/NUM + "us "); } Catch (InterruptedException e ){ E. printStackTrace (); } Dispatcher. shutdown (); } } |
Test 1 description: the consumption capability of an individual consumer event in multi-producer mode (no time-consuming business logic, only test the event distribution throughput capability). Each type of operation is tested three times.
Test result 1:
Test 2 description: the consumption capability of a single consumer event in the multi-producer mode (with time-consuming business logic, the average time consumption of each event is 1.8 ms, and the throughput capability of event distribution and processing is tested ), each type of operation is tested three times.
Test result 2:
Conclusion: in the test scenario 1, when the number of events exceeds 1000, the event distribution throughput is stable at around. In the test scenario 2, the distribution of two different event quantity types is involved, its event distribution and processing throughput is stable at around 540.
Based on the test results, if a Disruptor is introduced in the game to replace the traditional BlockQueue for message event processing, the number of messages to be carried should be increased by about three times.