Question

I am using a gateway as an entry point to the messaging system. Before going further I wanted to test the performance and I see that the gateway is taking too much time to process each request. I have the following code:

Configuration

<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"/>

The processor just takes the message and returns a default String "hello". No processing. The test is as follows:

@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);
}

This test takes almost 3 seconds to execute while if I change the service.getTest("Hi") for a direct call to the processor it takes 11ms. Can anyone tell me if there's something done wrong or is it just like this?

EDIT: I'm adding the processor. It is a dummy processor to test the flow performance:

public String process(Message<String> data) {
    return "hello";
}
Was it helpful?

Solution

  • 11ms it takes because you use your code directly without any messaging background - no GC for immutable Message objects (10000) and reflection for method invocation (from Gateway Proxy)

  • For me your test takes this time:

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

It is with @Repeat(10) on test method and <int:service-activator input-channel="requestChannel" expression="'hello'"/>.

  • Since your replyChannel doesn't do anything special you can get rid of it and you'll get some performance increase, because there is no need to correlate the reply from replyChannel to the TemporaryReplyChannel from MessageHeaders.

  • Anyway show, please, the code of your myProcessor

  • which version of Spring Integration do you use? Wouldn't you mind to upgrade to the latest one - 3.0.2 (http://projects.spring.io/spring-integration) ?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top