Hessian, CXF, Spring httpinvoke 对比

做了一个 Hessian, CXF, Spring httpinvoke 速度对比

时间消耗 cxf > spring httpinvoke > hessian

顺序调用1W次所耗时间

[table]
|hessian|2652-2922|
|spring httpinvoke|4080-4949|
|cxf|9732-10432|
[/table]

并发为10, 调用1W次所耗时间
[table]
|hessian|1625-1753|
|spring httpinvoke|3165-3338|
|cxf|5709-5863|
[/table]

当然, 都知道 cxf 和 hessian 实现以及应用场景不太一样, 但差这么多还是很意外的..
另外在并发测试时, spring httpinvoke cpu 消耗明显更高.

=============================================================
测试代码:

[b]服务端[/b]


public class Param implements Serializable {
private static final long serialVersionUID = 7414597783500374225L;
private Integer i;
private String s;
private Long l;
private List<Param> list = new ArrayList<Param>();
private boolean b;
......
}

public class Result implements Serializable {
private static final long serialVersionUID = 2729153186117404170L;
private Integer i;
private String s;
private Long l;
private List<Result> list;
private boolean b;
......
}



@WebService
public interface TestService {
Result method(Param p);
}



@Service
@WebService(endpointInterface = "org.alex.test.webservice.TestService")
public class TestServiceImpl implements TestService {

@Override
public Result method(Param p) {
Result r = new Result();
BeanUtils.copyProperties(p, r);
return r;
}

}




<!-- cxf -->
<import resource="classpath:META-INF/cxf/cxf.xml" />
<import resource="classpath:META-INF/cxf/cxf-extension-soap.xml" />
<import resource="classpath:META-INF/cxf/cxf-servlet.xml" />
<jaxws:endpoint id="testCxfService" implementor="org.alex.test.webservice.TestServiceImpl" address="/cxf" />


<bean id="testServiceImpl" class="org.alex.test.webservice.TestServiceImpl" />

<!-- hessian -->
<bean name="/hes" class="org.springframework.remoting.caucho.HessianServiceExporter">
<property name="service" ref="testServiceImpl" />
<property name="serviceInterface" value="org.alex.test.webservice.TestService" />
</bean>

<!-- spring http invoke -->
<bean name="/spr" class="org.springframework.remoting.httpinvoker.HttpInvokerServiceExporter">
<property name="service" ref="testServiceImpl" />
<property name="serviceInterface" value="org.alex.test.webservice.TestService" />
</bean>


客户端


public class Client {

static String CXF = "cxfService";
static String HESSIAN = "hesService";
static String SPRING = "sprService";

public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("client.xml");

TestService service = (TestService) ac.getBean(SPRING);

Param p = new Param();
p.setI(100);
p.setB(true);
p.setL(1000L);
p.setS("123456789123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()_\r\n\\\t");
p.getList().add(new Param());
p.getList().add(new Param());
p.getList().add(new Param());
service.method(p);

long now = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
service.method(p);
}
System.out.println(System.currentTimeMillis() - now);
}
}



public class MultiThreadClient {

static String CXF = "cxfService";
static String HESSIAN = "hesService";
static String SPRING = "sprService";

public static void main(String[] args) {
ApplicationContext ac = new ClassPathXmlApplicationContext("client.xml");

TestService service = (TestService) ac.getBean(HESSIAN);

Param p = new Param();
p.setI(100);
p.setB(true);
p.setL(1000L);
p.setS("123456789123456789abcdefghijklmnopqrstuvwxyz!@#$%^&*()_\r\n\\\t");
p.getList().add(new Param());
p.getList().add(new Param());
p.getList().add(new Param());
service.method(p);

ExecutorService exe = Executors.newFixedThreadPool(10);
Task task = new Task(service, p);

long now = System.currentTimeMillis();
for (int i = 0; i < 10000; i++) {
exe.submit(task);
}
exe.shutdown();
while (!exe.isTerminated()) {
}
System.out.println(System.currentTimeMillis() - now);

}

private static class Task implements Runnable {

TestService service;
Param p;

public Task(TestService service, Param p) {
this.service = service;
this.p = p;
}

@Override
public void run() {
service.method(p);
}
}
}




<jaxws:client id="cxfService" serviceClass="org.alex.test.webservice.TestService" address="http://localhost:8080/webservice/cxf/cxf?wsdl" />

<bean id="hesService" class="org.springframework.remoting.caucho.HessianProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/webservice/app/hes" />
<property name="serviceInterface" value="org.alex.test.webservice.TestService" />
</bean>

<bean id="sprService" class="org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean">
<property name="serviceUrl" value="http://localhost:8080/webservice/app/spr" />
<property name="serviceInterface" value="org.alex.test.webservice.TestService" />
</bean>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值