preface

As an engineer, project tuning is something you have to master.

In the SpringBoot project, tuning is done primarily through configuration files and configuring the parameters of the JVM.

Modifying a Configuration File

About modifying the configuration file application.properties.

SpringBoot project detailed configuration file modification documents

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

Some of the most important ones 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.

The Jvm tuning

The Oracle website provides guidance on Jvm tuning:


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

You can go and have a look.

Jvm tuning practice

JVM parameters are not set

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

So let me start it up and see.

Take a look at stack allocation:

Obviously the default maximum heap allocation is 8 gigabytes. It doesn’t make any sense.

‘ ‘Let’s set the Jvm parameters

For example, to configure a large number of parameters for the JVM:

-XX:MetaspaceSize=128m

-XX:MaxMetaspaceSize=128m

-Xms1024m -Xmx1024m -Xmn256m

-Xss256k -XX:SurvivorRatio=8

-XX:+UseConcMarkSweepGC

A:

Debugging the JDK is much easier if you use a development tool such as IDEA to start and run your project.

Simply set the parameter values to VM Options.

Setup is successful, my GC log and stack allocation are OK.

GC logs:

Stack allocation:

Method 2:

This can be set after the project is deployed, at startup time, using a script or command line.

In the project path, package the project:

Clean up old projects

mvn clean

Package new projects:

mvn package -Dmaven.test.skip=true

Enter the path of the runnable Jar package after the package is packaged:

Perform the action that starts setting Jvm parameters.

$ java -jar -XX:MetaspaceSize=128m

-XX:MaxMetaspaceSize=128m

-Xms1024m -Xmx1024m -Xmn256m -Xss256k

-XX:SurvivorRatio=8

- XX: + UseConcMarkSweepGC newframe - 1.0.0. Jar

At this point, if you look at the surveillance, you will see that it is already Ok.

The stack is started with the Jvm parameters set at startup time.

Refer to the Official Tuning documentation from Oracle in step 2 for what the JVM parameters for these Settings mean.

Here’s a quick note:

  • -xx :MetaspaceSize=128m

  • -xx :MaxMetaspaceSize=128m

  • -xMS1024m (maximum heap size)

  • -XMx1024m (default heap size)

  • -xmn256m (Cenozoic size)

  • -xss256K (maximum stack depth)

  • -xx :SurvivorRatio=8 (Cenozoic zone ratio 8:2)

  • -xx :+UseConcMarkSweepGC (specify the garbage collector to use, CMS collector is used here)

  • -xx :+PrintGCDetails (print verbose GC log)

Knowledge:

  • -xx :MetaspaceSize=128m (default size) -xx :MaxMetaspaceSize=128m (maximum size)

  • JDK 8 began putting class metadata into the native heap, an area known as Metaspace.

  • What are the benefits of using localized memory? The most direct performance is Java. Lang. OutOfMemoryError: The PermGen space problem is eliminated, because the default class metadata allocation is only limited by the size of the local memory, which means that Metaspace can theoretically be as large as the remaining local memory. It’s not clear here), which solves the space problem.

  • However, it is obviously unrealistic to make Metaspace infinitely large, so we will also limit the size of Metaspace: use the -xx :MaxMetaspaceSize parameter to specify the size of the Metaspace region. By default, the JVM dynamically sets the size of MaxMetaspaceSize at run time as needed.

More exciting articles can pay attention to: wechat public number, Java programmers gathering place.