Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

shelltea/warmup-spring-boot-starter

Open more actions menu

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot HTTP组件预热Starter

Maven Central Apache 2.0

简介

Spring Boot的应用程序在启动时,JVM需要加载各种类进行初始化,导致初期的HTTP请求往往响应时间较长,这也就是我们经常遇到的冷启动问题。通过warmup-spring-boot-starter可以在应用程序对外提供服务之前预热HTTP相关的组件,从而降低HTTP请求响应时间。

通过在业务服务中使用对比测试,可有效降低响应时间达30%~90%

此项目受到warm-me-up项目启发,将预热功能包装成Spring Boot Starter以方便使用。

如果希望在启动时对其他组件(数据库连接、缓存加载等)进行预热,可以参考:

@Component
public class WarmUpListener implements ApplicationListener<ApplicationReadyEvent> {
    @Override
    public void onApplicationEvent(ApplicationReadyEvent event) {
        // 对其他组件进行预热
    }
}

使用方法

  1. 增加依赖;
<dependency>
    <groupId>io.github.shelltea</groupId>
    <artifactId>warmup-spring-boot-starter</artifactId>
    <version>${version}</version>
</dependency>
  1. 正常启动服务,如果日志中输出以下内容表示预热完成。
Completed warm up application

配置参数

参数名 类型 默认值 说明
management.endpoint.warm-up.enable boolean true 开启预热
management.endpoint.warm-up.times int 5 预热接口请求次数

兼容性

Spring Boot 版本 兼容
2.7.x
2.6.x
2.5.x
2.4.x
2.3.x.RELEASE
2.2.x.RELEASE
2.1.x.RELEASE
2.0.x.RELEASE

参考

  1. https://stackoverflow.com/questions/54759652/spring-boot-cold-start/70711103#70711103
  2. https://github.com/steinsag/warm-me-up

About

Spring Boot Starter for warm up http component

Topics

Resources

License

Stars

Watchers

Forks

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.