Speed up application startup times with AppCDS #558
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:-Dspring.context.exit=<event>
) to terminate the application upon specific SpringApplicationContextEvent
events.Supported events include:
onPrepared
: TheSpringApplication
is starting up, and theApplicationContext
is fully prepared but not yet refreshed. The bean definitions are loaded, and theEnvironment
is ready for use at this stage.onRefreshed
:ApplicationContext
gets initialized or refreshed.onStarted
:ApplicationContext
has been refreshed, but before anyApplicationRunner
orCommandLineRunner
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.