spring-startup-analyzer generates an interactive spring application startup report that lets you understand what contributes to the application startup time and
spring-startup-analyzer generates an interactive spring application startup report that lets you understand what contributes to the application startup time and
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. UI referenced spring-boot-startup-report.
Spring Bean Initialization Details support for initialization time/beanName search, Spring Bean Initialization Timeline, Method Invocation Count and Time Statistics(support for custom methods), Unused Jars(to help optimize fat jars), and Application Startup Thread Wall Clock Profile, helping developers quickly analyze and locate application startup bottlenecks. Support for linux/mac/windows.
Spring Bean Initialization Details
Spring Bean Initialization Timeline
Method Invocation Count and Time Statistics
Unused Jars
Application Startup Thread Wall Clock Profile
Provide a Spring Bean asynchronous initialization jar package, which asynchronously executes the init and @PostConstruct methods for beans with longer initialization time to improve application startup speed.
Provides two installation methods: manual installation and one-click script installation.
1. Manual Installation
Click realease to download the latest version tar.gz package
Create a new folder and extract the files
For Linux/Mac systems, you may consider utilizing the following commands:
mkdir -p ${HOME}/spring-startup-analyzer
cd download_path
tar -zxvf spring-startup-analyzer.tar.gz -C your_install_path/spring-startup-analyzer
2. Shell script installation(Only for Linux/Mac)
curl -sS https://raw.githubusercontent.com/linyimin0812/spring-startup-analyzer/main/bin/install.sh | sh
Default install directory: $HOME/spring-startup-analyzer
This project provides several configuration options, which are not mandatory and can be used with default settings.
Two ways to configure:
your_install_path/spring-startup-analyzer/config/spring-startup-analyzer.properties-Dspring-startup-analyzer.app.health.check.timeout=30The criteria for determining a successful application startup are as follows:
SpringApplication.run method, considering the application startup complete upon method exit (only applicable to Spring Boot applications).For non-Spring Boot applications, it is necessary to configure the health check URL using spring-startup-analyzer.app.health.check.endpoints.
| configuration option | description | default value |
|---|---|---|
| spring-startup-analyzer.app.health.check.timeout | application startup check timeout time in minutes | 20 |
| spring-startup-analyzer.app.health.check.endpoints | application startup success check URL(s), multiple URLs can be configured, separated by commas | http://127.0.0.1:7002/actuator/health |
| spring-startup-analyzer.admin.http.server.port | management port | 8065 |
| spring-startup-analyzer.async.profiler.sample.thread.names | thread names collected by Async Profiler, supports multiple configurations separated by commas | main |
| spring-startup-analyzer.async.profiler.interval.millis | async profiler sample interval (ms) | 5 |
| spring-startup-analyzer.linux.and.mac.profiler | specify linux/mac flame graph profiler:async_profiler/jvm_profiler | jvm_profiler |
| spring-startup-analyzer.log.path | Path of logs - startup.log: log of startup - transform.log: log of re-transform class |
$HOME/spring-startup-analyzer/logs |
This project is started as an agent, so you can add the parameter -javaagent:your_install_path/spring-startup-analyzer/lib/spring-profiler-agent.jar to the startup command.
java -javaagent:/Users/runner/spring-startup-analyzer/lib/spring-profiler-agent.jar \
-Dproject.name=mac-demo \
-Dspring-startup-analyzer.admin.http.server.port=8066 \
-jar /Users/runner/spring-startup-analyzer/spring-boot-demo.jar
After the application has finished starting, the message ======= spring-startup-analyzer finished, click http://localhost:xxxx to visit details. ====== will be printed in the console and startup.log file. You can use this output to determine if the profiling has completed successfully
Translation: If you want to customize the profiling capabilities, you need to include the spring-profiler-starter pom as the parent pom for your extension project. Then, you can use the interfaces exposed by the project for extension purposes. For more details, you can refer to the implementation ofspring-profiler-extension
<parent>
<groupId>io.github.linyimin0812</groupId>
<artifactId>spring-profiler-starter</artifactId>
<version>latest_version</version>
</parent>
…
The start() and stop() methods represent the lifecycle of the system, called respectively at the beginning and completion of application startup. The filter() method specifies the classes/methods that need to be enhanced. The listen() method specifies the events to listen for, including method enter and method return events. The onEvent() method is called when the listened events occur.
For example, the following is an extension that counts the number of invocations of the java.net.URLClassLoader.findResource(String) method during the application startup process:
FindResourceCounter demo…
It is important to note that the implementation of the EventListener interface should be annotated with @MetaInfServices. This is because the extension interface is loaded through the Service Provider Interface (SPI). When you use the @MetaInfServices annotation, the implementation class will be automatically written to the META-INF/services/io.github.linyimin0812.profiler.api.EventListener file during the code compilation process. If you don't use the @MetaInfServices annotation, you need to manually write the fully qualified name of the implementation class into the META-INF/services/io.github.linyimin0812.profiler.api.EventListener file`. Otherwise, the extension implementation will not be loaded.
The spring-profiler-starter pom already defines a packaging plugin that will by default copy the generated JAR file to the $HOME/spring-startup-analyzer/extension directory.
mvn clean package
Once you have installed this project by following the steps in the Installation section, you can execute the packaging command mentioned above. After the packaging is complete, you can start the application as described in the Application Startup section to load the extension JAR file.
From the Application startup data collectionsection, you can obtain the Beans that have long initialization time. Since the Spring startup process is single-threaded, to optimize the application startup time, you can consider making the initialization methods of these time-consuming Beans asynchronous.
NOTE:
Root Bean in Loading time of Beans sessionSupports initialization of beans through @Bean, @PostConstruct, and @ImportResource. demo: spring-boot-async-bean-demo
@Bean(initMethod = "init")@Bean(initMethod = "init")
public TestBean testBean() {
return new TestBean();
}
@PostConstruct@Component
public class TestComponent {
@PostConstruct
public void init() throws InterruptedException {
Thread.sleep(20 * 1000);
}
}
<dependency>
<groupId>io.github.linyimin0812</groupId>
<artifactId>spring-async-bean-starter</artifactId>
<version>${latest_version}</version>
</dependency>
…
View the log in the `$HOME/spring-startup-analyze
No open issues yet, or sync has not completed.