Spring 网关性能差
我使用网关作为消息传递系统的入口点。在继续之前,我想测试性能,我发现网关处理每个请求花费的时间太多。我有以下代码: 配置Spring 网关性能差,spring,integration,spring-integration,Spring,Integration,Spring Integration,我使用网关作为消息传递系统的入口点。在继续之前,我想测试性能,我发现网关处理每个请求花费的时间太多。我有以下代码: 配置 <int:gateway id="inGateway" service-interface="com.example.MyInterface" default-request-channel="requestChannel" default-reply-channel="replyChannel"/> <int:channel id="r
<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);
}
@Autowired
专用接口服务;
@试验
公共空间{
字符串测试=service.getTest(“Hi”);
长启动=System.currentTimeMillis();
对于(int i=0;i
- 需要11毫秒,因为您直接使用代码时没有任何消息传递背景-不可变的
消息对象(10000)没有GC,方法调用(从网关代理)没有反射
- 对我来说,你的测试需要这段时间:
它与试验方法上的@重复(10)
和
一致
- 由于您的
replyChannel
没有做任何特殊的事情,因此您可以摆脱它并获得一些性能提升,因为不需要将来自replyChannel
的回复与来自MessageHeaders
的TemporaryReplyChannel
关联起来
- 无论如何,请出示您的
myProcessor
- 您使用哪个版本的Spring集成?是否介意升级到最新版本-3.0.2()
我使用的是3.0.0.RELEASE。我已更改为3.0.2并使用了临时回复频道。虽然使用@repeat(10),但测试所需的时间相当相同,在第一次重复两次之后,我得到了更好的时间。无论如何,正如你所说的,我想我将不得不处理消息创建和反射的使用。用SI 4.0测试它对你来说会如此困难吗?我正在用SI 3使用Spring 3.2.8。不幸的是,我不被允许移动到Spring 4。
public String process(Message<String> data) {
return "hello";
}
Total: 433
Total: 247
Total: 150
Total: 145
Total: 152
Total: 146
Total: 142
Total: 142
Total: 142
Total: 143