2016-12-27 59 views
2

我注意到在使用彈簧集成的同時將Spring-Boot從1.4.2升級到1.4.3時性能顯着下降。spring-boot-starter-integration 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); 
    } 
} 

集成Test.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-引導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-引導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 

我不知道可能是什麼原因造成的。 其他人是否有同樣的問題?

回答

3

這可能與SPR-14929有關。

在這種情況下,從消息參數中刪除@Payload可解決問題(在這種情況下不需要 - 如果有多個參數,則只需要有效載荷註釋)。

+0

是的,當使用'@ Header'註解時,我們注意到了同樣的問題。 –

+0

感謝您提及相關的JIRA問題。 它肯定看起來它的問題仍然沒有解決。 –

+0

對 - 我已經打開了一個[新的JIRA問題](https://jira.spring.io/browse/SPR-15060)。 –