SpringBoot Performance Tuning

1,

By default, we will use @SpringBootApplication annotation to automatically obtain configuration information for the application, but it will also bring some side effects to the application. After using this annotation, triggers automatic configuration ( Auto-the Configuration ) and component scans ( the Component Scanning ), which with the use of @Configuration , @EnableAutoConfiguration and @ComponentScan role of three notes is the same. Doing so bring convenience to developers, there will be a threefold effect:

1 , the project will lead to longer startup time. When starting a large application , or when to do a lot of integration tests start the application, the impact will be particularly pronounced.

2 , will not need to load some instances excess ( Beans ).

3 , will increase CPU consumption.

For the above three cases, we can remove @SpringBootApplication and @ComponentScan two annotations to disable the automatic scanning components, then we need the bean to be explicitly configured on:

2, replace the http server, tomcat will be built to replace the Undertow 

 

By default, the Spring the Boot using Tomcat as the embedded Servlet container

 

You can Web server switches to the Undertow to improve application performance. Undertow is a use of Java flexible development of high-performance Web server to provide, including blocking based and NIO are non-blocking mechanism. Undertow is Red Hat's open source products, is Wildfly the default Web server.

First, remove the dependency information in Tomcat configuration:

 

      <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
            <exclusions>
                <exclusion>
                    <groupId>org.springframework.boot</groupId>
                    <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
            </exclusions>
        </dependency>
        <!-- undertow 服务器 -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-undertow</artifactId>
    </dependency>

 

. 3, SpringBoot the JVM parameter tuning

The memory size of the server to set the parameters of the heap.

-Xms: Set Java initialize the stack size

-Xmx: set the maximum java heap size

Examples of parameters -XX: + PrintGCDetails -Xmx32M -Xms1M

Tuning the local project, arranged on the inside on the IDE OK

 

If, after the project was labeled package, execute the command

java -server -Xms32m -Xmx32m -jar .jar project

 

Project packaging, please glow:

 

Guess you like

Origin www.cnblogs.com/pickKnow/p/11200416.html