-
Notifications
You must be signed in to change notification settings - Fork 580
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
Implement metrics for thread pool suppliers #3630
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…created and when they create thread pools
…r metrics for them
…the ObserverManager
…r suppliers and pools
…l to avoid loading problems if JDK does not include ThreadPerTaskExecutor
tjquinno
changed the title
WIP - Implement metrics for thread pool suppliers
Implement metrics for thread pool suppliers
Nov 11, 2021
tjquinno
requested review from
tomas-langer,
danielkec,
batsatt,
ljamen,
ljnelson and
spericas
November 11, 2021 01:06
danielkec
reviewed
Nov 11, 2021
common/configurable/src/main/java/io/helidon/common/configurable/ObserverManager.java
Outdated
Show resolved
Hide resolved
danielkec
reviewed
Nov 11, 2021
common/configurable/src/main/java/io/helidon/common/configurable/ThreadPool.java
Show resolved
Hide resolved
...urable/src/main/java/io/helidon/common/configurable/spi/ExecutorServiceSupplierObserver.java
Outdated
Show resolved
Hide resolved
common/configurable/src/main/java/io/helidon/common/configurable/VirtualExecutorUtil.java
Outdated
Show resolved
Hide resolved
danielkec
approved these changes
Nov 11, 2021
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Resolves #947 for 2.x
Overview
Helidon implements three categories of thread pool supplier, depending mostly on the type of executor service they create, implemented in
helidon-common-configurable
:ScheduleThreadPoolSupplier
)ServerThreadPoolSupplier
)ThreadPoolSupplier
with no overriding category from the other suppliers)Beginning with this PR, for each
ExecutorService
created from these thread pool suppliers Helidon will registerGauge
metrics in the vendor registry. Gauges wrap values which other objects expose. Only when the gauge values are retrieved (either by code retrieving the metric from the registry and querying its value or by an HTTP client accessing the/metrics
endpoint) are the underlying values read, so the performance drain is minimal.Metrics exposed
The classic
ExecutorService
implementations created by Helidon's thread pool suppliers areThreadPoolExecutor
subclasses.ThreadPoolExecutor
exposes several methods which reveal dynamic information about the executor, and Helidon will create these metrics for each one :getActiveCount
active-count
getCompletedTaskCount
completed-task-count
getPoolSize
pool-size
getLargestPoolSize
largest-pool-size
getTaskCount
task-count
getQueue.remainingCapacity
queue.remaining-capacity
getQueue.size
queue.size
The Loom-based
ThreadPerTaskExecutor
exposes much less:threadCount
thread-count
and so does the new metrics support for these executors.
Metric identity
Helidon identifies the new executor service metrics by:
executor-service.xxx
wherexxx
is the metric name from above) and,supplierCategory
- eitherscheduled
,server
, some other user-supplied name if user-created, orhelidon-thread-pool-i
wherei
is an increasing integer (if the supplier name is otherwise unspecified)supplierIndex
- index of the supplier within a given categorypoolIndex
- index of the thread pool within the supplierAffected Helidon components
helidon-common-configurable
The several thread pool suppliers in
helidon-common-configurable
now locate observers, using the service loading mechanism, which implement a new SPI interface. When the suppliers are constructed, and when they create new thread pools (asExecutorService
s), they notify the observers.helidon-metrics
The full-featured metrics component adds an implementation of the new observer interface which registers metrics for each new thread pool created from the thread pool suppliers.
Because the
ThreadPerTaskExecutor
(Loom) is not present in all JDK versions we support, the mechanism for getting the metrics values is different. The existing code inhelidon-common-configurable
uses reflection to obtain the thread-per-task executors, and the metrics support also uses reflection also to create a gauge to expose the thread count for those executors.helidon-microprofile-lra
In the course of working on this I found a bean that declared an observer on all app-scoped beans being destroyed--including itself which meant CDI created the bean again just to notify it of the shutdown. I changed the method to
@PreDestroy
.docs
The metrics guides (SE and MP) already contained a very brief mention of "built-in metrics" in Helidon. They now discuss them a bit more (the predefined base metrics for the JVM, the KPI metrics, and now the thread pool ones).
Example metrics output