【发布时间】:2014-05-11 19:57:36
【问题描述】:
我使用网关作为消息传递系统的入口点。在继续之前,我想测试性能,我发现网关需要太多时间来处理每个请求。我有以下代码:
配置
<int:gateway id="inGateway"
service-interface="com.example.MyInterface" default-request-channel="requestChannel"
default-reply-channel="replyChannel"/>
<int:channel id="requestChannel"/>
<int:service-activator method="process" input-channel="requestChannel" ref="myProcessor" output-channel="replyChannel"/>
<int:channel id="replyChannel"/>
处理器只接收消息并返回默认字符串“hello”。没有处理。测试如下:
@Autowired
private MyInterface service;
@Test
public void testBucle() {
String test = service.getTest("Hi");
long start = System.currentTimeMillis();
for (int i=0;i<10000;i++) {
test = service.getTest("Hi");
}
long end = System.currentTimeMillis();
long total = (end - start);
System.out.println("Total: "+total);
}
这个测试需要将近 3 秒来执行,而如果我更改 service.getTest("Hi") 以直接调用处理器则需要 11 毫秒。任何人都可以告诉我是否有什么做错了,还是只是这样?
编辑:我正在添加处理器。它是一个用于测试流性能的虚拟处理器:
public String process(Message<String> data) {
return "hello";
}
【问题讨论】:
标签: spring integration spring-integration