【www.bbyears.com--手机硬件】
硬件描述:
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倍左右。