Original Address: https: //www.cnblogs.com/superfj/p/8667977.html
To facilitate their learning, recording, for everyone to share
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?
1. Convenient Micro service deployment.
2. 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, 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. This situation is more common in production of
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
Initial memory and maximum memory arranged to be substantially the same, depending on the scene setting a specific size, must be used -server is a parameter,
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 -jar springboot-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
1java -server -Xms512m -Xmx768m -jar springboot-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.
Pop appears, click the + button, find the Remote option.
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
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service # prohibit firewall boot
Click the debug button, IDEA console print information:
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:
Similarly, JvisualVm remote connection is the same start parameters as well.
Then enter the machine JvisualVm IP: PORT, remote connection to: as shown below:
Compared Jvisualvm look more powerful, the interface is more beautiful
Reproduced in: https: //www.jianshu.com/p/b8ce244c7254