SpringBoot this tuning, make your project fly!

Foreword

As an engineer, project Tuning the matter is the need to get familiar with the matter.

In SpringBoot project, mainly through tuning profile parameters and the JVM manner.

Modify the configuration file

About modifying the configuration file application.properties.

SpringBoot detailed project profiles modify the document

https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html#common-application-properties

The more important are:

server.tomcat.max-connections=0 # Maximum number of connections that the server accepts and processes at any given time.
server.tomcat.max-http-header-size=0 # Maximum size, in bytes, of the HTTP message header.
server.tomcat.max-http-post-size=0 # Maximum size, in bytes, of the HTTP post content.
server.tomcat.max-threads=0 # Maximum number of worker threads.
server.tomcat.min-spare-threads=0 # Minimum number of worker threads.

Jvm Tuning

About Jvm Tuning Oracle's official website has a guidance note:

https://docs.oracle.com/middleware/11119/wls/PERFM/jvm_tuning.htm#i1146060

We are interested can go and see.

Jvm tuning combat

JVM parameter is not provided

I now have a project, by default, it does not set any Jvm parameters.

Now I start to look at.

Look at the stack allocation:

Obviously default maximum heap memory allocated 8 G. Well obviously unreasonable.

'' Let us set the parameters under Jvm

For example, to configure the JVM such a large segment parameters:

-XX:MetaspaceSize=128m
-XX:MaxMetaspaceSize=128m
-Xms1024m -Xmx1024m -Xmn256m
-Xss256k -XX:SurvivorRatio=8
-XX:+UseConcMarkSweepGC

method one:

If you are using a development tool such as IDEA, to start running the project, so it is easy to debug JDK too much.

Only need to set the parameter value to the VM options can be.

Set up, my GC logs and stack allocations have been OK.

GC logs:

Stack allocation:

Second way:

After the project is suitable for deployment at startup, when using a script or command line to run setup.

Under the first project path to the project package:

To clean up old items

mvn clean

Packaging new project:

mvn package -Dmaven.test.skip=true

Path runnable Jar package after the package is completed:

Execution startup settings Jvm parameters of operation.

$ java -jar -XX:MetaspaceSize=128m
-XX:MaxMetaspaceSize=128m
-Xms1024m -Xmx1024m -Xmn256m -Xss256k
-XX:SurvivorRatio=8
-XX:+UseConcMarkSweepGC newframe-1.0.0.jar

This time, you look at the monitor, you will find that is already in the Ok.

Stack is in accordance with the start time, Jvm parameter set to start.

JVM arguments about what is the meaning of these settings, please refer to the tuning oracle official document given in the second step.

Simply click here:

  • -XX: MetaspaceSize = 128m (metaSpace default size)

  • -XX: MaxMetaspaceSize = 128m (metaSpace maximum size)

  • -Xms1024m (maximum heap size)

  • -Xmx1024m (default heap size)

  • -Xmn256m (Cenozoic size)

  • -Xss256k (maximum depth of stack size)

  • -XX: SurvivorRatio = 8 (New Generation partition ratio 8: 2)

  • -XX: + UseConcMarkSweepGC (specify garbage collector, used here CMS collector)

  • -XX: + PrintGCDetails (print detailed log GC)

Knowledge points:

  • After JDK8 the -XX: PermSize and -XX: MaxPermGen removed, replaced by -XX: MetaspaceSize = 128m (the default size of the element space) -XX: MaxMetaspaceSize = 128m (the maximum size of space yuan)

  • 8 starts metadata to JDK classes into localized heap (native heap), which is called a region Metaspace, Chinese yuan name space.

  • Localized memory what good is it? The most direct expression is java.lang.OutOfMemoryError: PermGen space problem will cease to exist, because the metadata assigned default class is limited only by the size of the local memory, which means that the remaining number of local memory, how can theoretically Metaspace (seemingly also the capacity of the operating system's virtual memory about? here is not clear), this solves the problem of insufficient space.

  • But let Metaspace become infinite is clearly unrealistic, so we have to limit the size of Metaspace: Use -XX: MaxMetaspaceSize parameter to specify the size of the Metaspace area. MaxMetaspaceSize JVM default setting according to the size dynamically at runtime.

More exciting articles may concern: public micro-channel number, java programmers gather.


Guess you like

Origin juejin.im/post/5de4bb9d6fb9a0715e46d3b1