spring-boot-starter-integration 1.4.3性能下降

时间:2016-12-27 14:02:19

标签: java spring spring-boot spring-integration

我注意到在使用spring-integration时将Spring-Boot从1.4.2升级到1.4.3时性能显着下降。

我可以使用以下程序重现该问题:

的pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>

   <parent>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-parent</artifactId>
       <!--<version>1.4.2.RELEASE</version>-->
       <version>1.4.3.RELEASE</version>
   </parent>

   <artifactId>performance-test</artifactId>
   <version>1.0-SNAPSHOT</version>

   <dependencies>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-integration</artifactId>
       </dependency>
       <dependency>
           <groupId>org.springframework.boot</groupId>
           <artifactId>spring-boot-starter-test</artifactId>
           <scope>test</scope>
       </dependency>
   </dependencies>

</project>

Application.java:

package performance.test;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class Application {

    public static void main(final String[] args) {
        SpringApplication.run(Application.class, args);
    }
}

UsersManager.java:

package performance.test;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.integration.annotation.MessageEndpoint;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.messaging.handler.annotation.Payload;

@MessageEndpoint
public class UsersManager {

    private static final Logger LOGGER = LoggerFactory.getLogger(UsersManager.class);

    @ServiceActivator(inputChannel = "testChannel")
    public void process(@Payload String payload) {
        LOGGER.debug("payload: {}", payload);
    }
}

IntegrationTest.java:

package performance.test;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringApplicationConfiguration(classes = Application.class)
public class IntegrationTest {

    private static final Logger LOGGER = LoggerFactory.getLogger(IntegrationTest.class);

    @Autowired
    private MessageChannel testChannel;

    @Test
    public void basic_test() {
        for (int i = 1; i <= 10; i++) {
            final long start = System.currentTimeMillis();
            test(1000);
            final long end = System.currentTimeMillis();
            LOGGER.info("test run: {} took: {} msec", i, end - start);
        }
    }

    private void test(int count) {
        for (int i = 0; i < count; i++) {
            testChannel.send(MessageBuilder.withPayload("foo").setHeader("monkey", "do").build());
        }
    }
}

当我使用Spring-Boot 1.4.2时,我得到以下结果:

2016-12-27 14:55:39.331  INFO 4939 --- [           main] performance.test.IntegrationTest         : Started IntegrationTest in 0.975 seconds (JVM running for 1.52)
2016-12-27 14:55:39.468  INFO 4939 --- [           main] performance.test.IntegrationTest         : test run: 1 took: 123 msec
2016-12-27 14:55:39.552  INFO 4939 --- [           main] performance.test.IntegrationTest         : test run: 2 took: 83 msec
2016-12-27 14:55:39.632  INFO 4939 --- [           main] performance.test.IntegrationTest         : test run: 3 took: 80 msec
2016-12-27 14:55:39.696  INFO 4939 --- [           main] performance.test.IntegrationTest         : test run: 4 took: 63 msec
2016-12-27 14:55:39.763  INFO 4939 --- [           main] performance.test.IntegrationTest         : test run: 5 took: 67 msec
2016-12-27 14:55:39.842  INFO 4939 --- [           main] performance.test.IntegrationTest         : test run: 6 took: 78 msec
2016-12-27 14:55:39.895  INFO 4939 --- [           main] performance.test.IntegrationTest         : test run: 7 took: 53 msec
2016-12-27 14:55:39.950  INFO 4939 --- [           main] performance.test.IntegrationTest         : test run: 8 took: 55 msec
2016-12-27 14:55:40.004  INFO 4939 --- [           main] performance.test.IntegrationTest         : test run: 9 took: 54 msec
2016-12-27 14:55:40.057  INFO 4939 --- [           main] performance.test.IntegrationTest         : test run: 10 took: 53 msec
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.776 sec - in performance.test.IntegrationTest

但是,当我使用Spring-Boot 1.4.3时,性能会有显着下降:

2016-12-27 14:57:41.705  INFO 5122 --- [           main] performance.test.IntegrationTest         : Started IntegrationTest in 1.002 seconds (JVM running for 1.539)
2016-12-27 14:57:41.876  INFO 5122 --- [           main] performance.test.IntegrationTest         : test run: 1 took: 156 msec
2016-12-27 14:57:42.031  INFO 5122 --- [           main] performance.test.IntegrationTest         : test run: 2 took: 153 msec
2016-12-27 14:57:42.251  INFO 5122 --- [           main] performance.test.IntegrationTest         : test run: 3 took: 220 msec
2016-12-27 14:57:42.544  INFO 5122 --- [           main] performance.test.IntegrationTest         : test run: 4 took: 293 msec
2016-12-27 14:57:42.798  INFO 5122 --- [           main] performance.test.IntegrationTest         : test run: 5 took: 254 msec
2016-12-27 14:57:43.111  INFO 5122 --- [           main] performance.test.IntegrationTest         : test run: 6 took: 312 msec
2016-12-27 14:57:43.544  INFO 5122 --- [           main] performance.test.IntegrationTest         : test run: 7 took: 432 msec
2016-12-27 14:57:44.112  INFO 5122 --- [           main] performance.test.IntegrationTest         : test run: 8 took: 567 msec
2016-12-27 14:57:44.807  INFO 5122 --- [           main] performance.test.IntegrationTest         : test run: 9 took: 695 msec
2016-12-27 14:57:45.620  INFO 5122 --- [           main] performance.test.IntegrationTest         : test run: 10 took: 813 msec
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.989 sec - in performance.test.IntegrationTest

我不知道造成这种情况的原因是什么。 其他人是否有同样的问题?

1 个答案:

答案 0 :(得分:3)

这可能与SPR-14929有关。

在这种情况下,从message参数中删除@Payload可以解决问题(在这种情况下不需要它 - 如果有多个参数,则只需要有效负载注释)。