dubbo和S-HSF测试对比

今天没什么事,简单测试下RPC框架性能: HSF完胜dubbo


1.dubbo测试结果:

note:
dubbo测试时有使用ZooKeeper,所以存在不公平性,不一定准确。

同步模型

耗时:16.808 s
平均:0.16808 ms
TPS:5949.547834364588

测试数据:


public class TPS_TEST {

public static void main(String[] args) throws InterruptedException {
final ClassPathXmlApplicationContext context =
new ClassPathXmlApplicationContext(
new String[] {"file:E:/1-project_test/dubbox-master/dubbo-demo/dubbo-demo-consumer/src/main/resources/META-INF/spring/dubbo-demo-consumer.xml"});
final HelloService helloService = (HelloService)context.getBean("helloService"); // get service invocation proxy
ExecutorService executorServicePool = Executors.newFixedThreadPool(200);
final int size = 100000;
final CountDownLatch cdl = new CountDownLatch(size);
long begin = System.currentTimeMillis();
for (int i = 0; i < size; i++) {
executorServicePool.execute(new Runnable() {
@Override
public void run() {
try {

String hello = helloService.hello("aa"); // do invoke!
//System.out.println( hello ); // cool, how are you~
cdl.countDown();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
//executorServicePool.shutdown();
//executorService.awaitTermination(10, TimeUnit.MINUTES);
cdl.await();//等待所有任务处理完
long time = System.currentTimeMillis() - begin;
System.out.println("耗时:" + (double) time / 1000 + " s");
System.out.println("平均:" + ((double) time) / size +" ms");
System.out.println("TPS:" + (double) size / ((double) time / 1000));


}


}



2.hsf 测试结果:

异步模型:

耗时:6.305 s
平均:0.06305 ms
TPS:15860.428231562253

测试数据:


public class Client {
public static void main(String[] args) throws InterruptedException, ExecutionException {
final int size = 100000;
final CountDownLatch cdl = new CountDownLatch(size);

// final TestService testService = ServiceProxyFactory.getRoundFactoryInstance(connector).wrapAsyncProxy(
// TestService.class);

HsfConnector connector = new HsfConnectorImpl();
connector.connect(new InetSocketAddress("localhost", 8082));


final TestService testService = ServiceProxyFactory.getRoundFactoryInstance(connector).wrapAsyncCallbackProxy(
TestService.class, new AsyncCallback<Object>() {
public void doCallback(Object data) {
//System.out.println("received:" + data);
cdl.countDown();
};
@Override
public void doExceptionCaught(Throwable ex, HsfChannel channel, Object param) {
System.out.println(ex);
super.doExceptionCaught(ex, channel, param);
}
});
ExecutorService executorServicePool = Executors.newFixedThreadPool(200);
long begin = System.currentTimeMillis();
for (int i = 0; i < size; i++) {
executorServicePool.execute(new Runnable() {
@Override
public void run() {
try {
testService.test("aa");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
//executorServicePool.shutdown();
//executorService.awaitTermination(10, TimeUnit.MINUTES);
cdl.await();//等待所有任务处理完
long time = System.currentTimeMillis() - begin;
System.out.println("耗时:" + (double) time / 1000 + " s");
System.out.println("平均:" + ((double) time) / size +" ms");
System.out.println("TPS:" + (double) size / ((double) time / 1000));

}

}




同步模型:

耗时:9.446 s
平均:0.09446 ms
TPS:10586.491636671608


//tips:
//模拟HSF的同步模型:在10万个并发线程发送数据时有时候比异步模型还要快,这点有点想不通,估计是我测试的服务是直接return的场景吧。

/**
* @Title: Client.java
* @Description: TODO(添加描述)
* @date 2012-2-23 上午01:01:33
* @version V1.0
*/
public class Client2 {
public static void main(String[] args) throws InterruptedException, ExecutionException {
final int size = 100000;
final CountDownLatch cdl = new CountDownLatch(size);
HsfConnector connector = new HsfConnectorImpl();
connector.connect(new InetSocketAddress("10.118.63.12", 10223));


/*
final TestService testService = ServiceProxyFactory.getRoundFactoryInstance(connector).wrapAsyncCallbackProxy(
TestService.class, new AsyncCallback<Object>() {
public void doCallback(Object data) {
//System.out.println("received:" + data);
cdl.countDown();
};
@Override
public void doExceptionCaught(Throwable ex, HsfChannel channel, Object param) {
System.out.println(ex);
super.doExceptionCaught(ex, channel, param);
}
});
ExecutorService executorServicePool = Executors.newFixedThreadPool(200);
long begin = System.currentTimeMillis();
for (int i = 0; i < size; i++) {
executorServicePool.execute(new Runnable() {
@Override
public void run() {
try {
testService.test("aa");
} catch (Exception e) {
e.printStackTrace();
}
}
});
}

*/

final TestService testService = ServiceProxyFactory.getRoundFactoryInstance(connector).wrapSyncProxy(
TestService.class);

ExecutorService executorServicePool = Executors.newFixedThreadPool(200);
long begin = System.currentTimeMillis();
for (int i = 0; i < size; i++) {
executorServicePool.execute(new Runnable() {
@Override
public void run() {
try {
String hello = testService.test("aa");
cdl.countDown();
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
//executorServicePool.shutdown();
//executorService.awaitTermination(10, TimeUnit.MINUTES);
cdl.await();//等待所有任务处理完
long time = System.currentTimeMillis() - begin;
System.out.println("耗时:" + (double) time / 1000 + " s");
System.out.println("平均:" + ((double) time) / size +" ms");
System.out.println("TPS:" + (double) size / ((double) time / 1000));

}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值