【问题标题】:Gateway poor performance网关性能不佳
【发布时间】: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


    【解决方案1】:
    • 需要 11 毫秒,因为您在没有任何消息传递背景的情况下直接使用您的代码 - 对于不可变的 Message 对象 (10000) 和方法调用的反射没有 GC(来自网关代理)

    • 对我来说,你的测试需要这段时间:

    Total: 433
    Total: 247
    Total: 150
    Total: 145
    Total: 152
    Total: 146
    Total: 142
    Total: 142
    Total: 142
    Total: 143
    

    在测试方法上有@Repeat(10)&lt;int:service-activator input-channel="requestChannel" expression="'hello'"/&gt;

    • 由于您的 replyChannel 没有做任何特别的事情,您可以摆脱它并且您将获得一些性能提升,因为无需将来自 replyChannel 的回复关联到 TemporaryReplyChannel来自MessageHeaders

    • 无论如何,请显示您的myProcessor的代码

    • 您使用哪个版本的 Spring Integration?您不介意升级到最新版本 - 3.0.2 (http://projects.spring.io/spring-integration) 吗?

    【讨论】:

    • 我使用的是 3.0.0.RELEASE。我已更改为 3.0.2 并使用临时回复频道。测试花费的时间几乎相同,尽管如果我使用@repeat(10),在第一次重复两次之后我会得到更好的时间。无论如何,正如你所说,我想我将不得不处理消息创建和反射的使用。
    • 用 SI 4.0 测试它对你来说会这么难吗?
    • 我正在使用带有 SI 3 的 Spring 3.2.8。不幸的是,我不允许迁移到 Spring 4。
    猜你喜欢
    • 2021-11-30
    • 1970-01-01
    • 2011-01-03
    • 2016-11-06
    • 2019-06-15
    • 2013-06-11
    • 2010-12-31
    • 2012-01-25
    • 2021-12-15
    相关资源
    最近更新 更多