Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up application startup times with AppCDS #558

Merged
merged 1 commit into from
Oct 22, 2024

Conversation

groldan
Copy link
Member

@groldan groldan commented Oct 22, 2024

Enable AppCDS creation during Docker image build.

Improves application startup times from ~10% to ~30% on a fast machine. The improvement is expected to be more noticeable on slower hosts. That said, a big part of a GeoServer application startup time relates to catalog and configuration initialization, and in the case of GeoServer Cloud, there's also the Spring Cloud initialization (e.g. rabbitmq, config service lookup and discovery service registration). Nonetheless, AppCDS greatly alleviates the time spent loading and compiling classes, which relieves the host from having several containers starting up and competing from resources just for that.

AppCDS (Application Class Data Sharing) is a JVM feature that allows preloading and sharing class metadata across JVM instances. This can significantly improve startup time and reduce memory usage, especially for large applications with many dependencies.

This patch launches the applications during the Docker image build process for a short period of time (until the spring context is first refreshed) to build the AppCDS archive, and introduces an AutoConfiguration that:

  • Allows passing a JVM argument (-Dspring.context.exit=<event>) to terminate the application upon specific Spring ApplicationContextEvent events.
  • Facilitates starting the application during Docker image builds to create the AppCDS archive, improving startup performance.

Supported events include:

  • onPrepared: The SpringApplication is starting up, and the ApplicationContext is fully prepared but not yet refreshed. The bean definitions are loaded, and the Environment is ready for use at this stage.
  • onRefreshed: ApplicationContext gets initialized or refreshed.
  • onStarted: ApplicationContext has been refreshed, but before any ApplicationRunner or CommandLineRunner instances have been called.
  • onReady: Published as late as possible to indicate that the application is ready to service requests. All initialization steps will have been completed.

Note: Spring Boot 3.2+ natively supports spring.context.exit=onRefresh as of this commit, so this feature may not be necessary post-upgrade from Spring Boot 2.7.

Additional events are included for cases where certain applications may require different startup stages for proper initialization. The new offline embedded Spring profile should also facilitate starting without Spring Cloud Bus, ACL, etc.

AppCDS (Application Class Data Sharing) is a JVM feature that allows preloading
and sharing class metadata across JVM instances. This can significantly improve
startup time and reduce memory usage, especially for large applications with
many dependencies.

This patch launches the applications during the Docker image build process for a
short period of time (until the spring context is first refreshed) to build the
AppCDS archive, and introduces an `AutoConfiguration` that:

- Allows passing a JVM argument (`-Dspring.context.exit=<event>`) to terminate
  the application upon specific Spring `ApplicationContextEvent` events.
- Facilitates starting the application during Docker image builds to create the
  AppCDS archive, improving startup performance.

Supported events include:
- `onPrepared`
- `onRefreshed`
- `onStarted`
- `onReady`

Note: Spring Boot 3.2+ natively supports `spring.context.exit=onRefresh` as of
[this commit](spring-projects/spring-framework@eb3982b),
so this feature may not be necessary post-upgrade from Spring Boot 2.7.

Additional events are included for cases where certain applications may require
different startup stages for proper initialization. The new `offline` embedded
Spring profile should also facilitate starting without Spring Cloud Bus, ACL,
etc.
@groldan groldan added enhancement New feature or request build Issues related to the build and/or CI docker Issues related to docker images or docker composition labels Oct 22, 2024
@groldan groldan changed the title Enable AppCDS creation during Docker image build Speed up Java application startup time with AppCDS Oct 22, 2024
@groldan groldan changed the title Speed up Java application startup time with AppCDS Speed up application startup times with AppCDS Oct 22, 2024
@groldan groldan merged commit 9c7002b into geoserver:main Oct 22, 2024
6 checks passed
@groldan groldan deleted the build/appcds branch October 22, 2024 23:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
build Issues related to the build and/or CI docker Issues related to docker images or docker composition enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant