Optimize your springboot-- essential job interview

Introduction

In SpringBoot Web project, the default uses a built-in Tomcat, of course, can also be configured to support the built-in jetty, built what good is it?

Micro convenient service deployment.

Easy project start, no need to download Tomcat or Jetty

For current container optimization, at present, there is not much place, we need to consider the following points

Threads

overtime time

jvm optimization

In response to these optimization points, the first of a number of threads is the focus of the initial number of threads and the maximum number of threads, the initial number of threads guarantee startup, if there are a large number of users to access, can be very stable accept the request.

The maximum number of threads used to ensure the stability of the system, and timeout to guarantee the number of connections is not easy to be overwhelmed if large quantities of requests over the delay is relatively high, is not easy to thread played. In this case, the production is more common, once the network is unstable, the machine would rather do not want to overwhelm loss.

jvm optimize the scene in general is not much, nothing more than increase the initial heap, and stack the maximum limit, of course, is not unlimited increase, according to the case into the fast start

In the spring boot configuration file application.yml, add the following configuration

server:

tomcat:

min-spare-threads:20

max-threads:100

connection-timeout:5000

Tomcat was a piece of optimized configuration, the maximum number of threads is 100, initialize the thread is 20, the timeout is 5000ms

Jvm optimization

This is not primarily talk about how to optimize, jvm scene of optimization is a need, nothing too specific parameters, in general, specify the following parameters will be run at the server side

The initial memory and maximum memory will be set to the same basic, specific size depending on the scene settings, -server is a parameter must be used, as these collectors will be able to use the default unless there is a specific demand.

1. Use -server mode

Setting JVM using server mode. 64 JDK the default startup mode

java-server-jarspringboot-1.0.jar

2. Specify the heap parameter

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

-Xms: Set the initial size of the Java stack

-Xmx: set the maximum heap size of java

java-server-Xms512m-Xmx768m-jarspringboot-1.0.jar

Set the initialization heap memory is 512MB, up to 768MB.

3. Remote Debug

On the server startup parameters amended as follows:

java-Djavax.net.debug=

ssl -Xdebug-Xnoagent -Djava.compiler=

NONE -Xrunjdwp:transport=

dt_socket,server=y,suspend=

n,address=8888-jar springboot-1.0.jar

This time the server remotely Debug mode is turned on, the port number is 8888.

In IDEA, click Edit Configuration button.

10006770-04abc8ea23f8cbf8

Pop appears, click the + button, find the Remote option.

10006770-cb7eae831bd4389f

Fill in the Remote [1] project name, fill in the IP address and port number in [2], [3] to select an item in the remote debugging module, the configuration is complete click OK to

If this connection timeout encounter is likely to issue a firewall server, for example CentOs7, turn off the firewall

systemctlstopfirewalld.service#停止firewall

systemctldisablefirewalld.service # prohibit firewall boot

Click the debug button, IDEA console print information:

10006770-cdcb73790eab0b4d

Description remote debugging success.

JVM remote connection tools

jconsole and Jvisualvm remote connections

Usually we are lost deploying web services on the server, using jconsole in the window is very convenient, as opposed to Linux had some trouble and need some settings.

1. Check the hostname, the first to use

hostname-i

View, hostname server is 127.0.0.1, this is wrong, we need to be modified

2. Modify the hostname

Modify / etc / hosts file, "127.0.0.1 localhost.localdomain localhost" in its first line, amended as: "192.168.44.128 localhost.localdomain localhost" IP to "192.168.44.128" to the actual server.

3. Restart Linux, enter the hostname -i on the server, view the IP address of the actual setting is set to your

4. Start service parameters are:

java-jar -Djava.rmi.server.hostname=192.168.44.128-

Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=911-

Dcom.sun.management.jmxremote.ssl=false-

Dcom.sun.management.jmxremote.authenticate=falsejantent-1.0-SNAPSHOT.jar

ip is 192.168.44.128, port 911.

5. The jconsole open, remotely connected, and the input ports to IP

Click connection, after a little waiting to complete the connection, as shown below:

10006770-df3a8466703c7269

Similarly, JvisualVm remote connection is the same start parameters as well.

Then enter the machine JvisualVm IP: PORT, remote connection to: as shown below:

10006770-ae546fd483e595bd

Compared Jvisualvm look more powerful, the interface is more beautiful

Reproduced in: https: //www.jianshu.com/p/fa07d3cdde01

Guess you like

Origin blog.csdn.net/weixin_34388207/article/details/91341042