注意
:
文末有最新
Java实战
项目
和
面试题
来源:http://suo.im/5WmqLV
作为一名工程师,项目调优这事,是必须得熟练掌握的事情。
在SpringBoot项目中,调优主要通过配置文件和配置JVM的参数的方式进行。
修改配置文件
关于修改配置文件application.properties。
SpringBoot项目详细的配置文件修改文档
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html#common-application-properties
其中比较重要的有:
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调优
关于Jvm调优Oracle官网有一份指导说明:
https://docs.oracle.com/middleware/11119/wls/PERFM/jvm_tuning.htm#i1146060
有兴趣大家可以去看看。
Jvm调优实战
1、未设置JVM参数的情况
我现在有一个项目,默认情况下,没有设置任何Jvm参数。
下面我来启动看一下。
看一下堆栈分配:
很明显默认的最大堆内存分配了8个G。很明显的不合理嘛。
2、下面我们来设置下Jvm参数
例如要配置JVM这么一大段参数:
-XX:MetaspaceSize=128m
-XX:MaxMetaspaceSize=128m
-Xms1024m -Xmx1024m -Xmn256m
-Xss256k -XX:SurvivorRatio=8
-XX:+UseConcMarkSweepGC
方式一:
如果你用的是IDEA等开发工具,来启动运行项目,那么要调试JDK就方便太多了。
只需要将参数值设置到VM options中即可。
设置成功,我的GC日志和堆栈分配都已经OK了。