zoukankan      html  css  js  c++  java
  • SpringBoot入门-SpringBoot性能优化

    SpringBoot启动优化

    显示声明扫包范围:

    即不使用@SpringBootApplication默认扫包,使用@ComponentScan(basePackages = { "com.xxx.controller" ,"com.xxx.service" })显示声明扫包范围。

    原因是@SpringBootApplication默认扫包,扫的是启动类下的所有子包,实际开发场景中有很多包是不需要扫的,所以用默认的扫包会去扫很多本来就不用扫的包。

    验证是否有优化效果的时候,如果是自己写的demo,验证不出来,因为包和类太少了,可以用公司的实际项目验证一下,启动会快很多。

    SpringBoot运行优化

    使用Undertow服务器:

    默认情况下,SpringBoot使用Tomcat来作为内嵌的servlet容器。可以将web服务器切换到Undertow来提高应用性能。

    Undertow是一个采用Java开发的灵活的高性能web服务器,提供包括阻塞和基于NIO的非阻塞机制。Undertow是红帽公司的开源产品,是Wildfly默认的web服务器。

    过多的就不在介绍了,自行百度了解更多。

    首先移除Tomcat

    <dependency>
       <groupId>org.springframework.boot</groupId>
       <artifactId>spring-boot-starter-web</artifactId>
           <exclusions>
                <exclusion>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-starter-tomcat</artifactId>
                </exclusion>
           </exclusions>
    </dependency>

    添加Undertow

    <dependency>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-undertow</artifactId>
    </dependency>

    Tomcat 与 Undertow 吞吐量对比(在本人电脑上实际测试):

    SpringBoot JVM参数调优:

    根据服务器的内存大小,来设置堆参数。

    -Xms :设置Java堆栈的初始化大小

    -Xmx :设置最大的java堆大小

    实例参数-XX:+PrintGCDetails -Xmx32M -Xms1M

    本地项目调优

     

    外部运行调优

    java -server -Xms32m -Xmx32m  -jar springboot_v2.jar

     

  • 相关阅读:
    不删除数据库,只删除GridView的某一行!
    纯CSS无图打造圆角Table 无图制作圆角
    2009年总结与2010总体计划
    工作中的碰到的问题,以及处理过程:
    SQL Server 2005 不允许远程连接解决方法
    Visual Studio 2008项目模板丢失的解决办法
    C#格式化数值结果表
    准备把csdn的博客搬到这里
    生产系统中 RAC 数据库服务器 不要批量 gzip压缩
    不再更新的业务统计表
  • 原文地址:https://www.cnblogs.com/ibigboy/p/10978550.html
Copyright © 2011-2022 走看看