java中Disruptor效能測試筆記

來源:互聯網
上載者:User

硬體描述:

model name      : Intel(R) Xeon(R) CPU E5-2640 0 @ 2.50GHz

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

測試代碼(dtest.zip common-disruptor):

 代碼如下 複製代碼

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 bufferSize = 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, "任務執行器", 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();
    }
}

 

測試1描述:多生產者模式下單個消費者事件消費能力(無耗時商務邏輯,僅測試事件分發吞吐能力),每種類型操作分別測試3次。

測試1結果:
測試2描述:多生產者模式下單個消費者事件消費能力(有耗時商務邏輯,每個事件平均耗時1.8ms,測試事件分發處理吞吐能力),每種類型操作分別測試3次。
測試2結果:
 
總結:測試1情境中當事件數目量超過1000w,其事件分發吞吐能力穩定在300w左右,測試2情境中在兩種不同事件數目量類型的分發處事過程中,其事件分發處理吞吐能力穩定在540左右。
按照這個測試結果,如果在遊戲中引入Disruptor替代傳統的BlockQueue處理訊息事件,承載數量應該可以提高3倍左右。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.