-
Notifications
You must be signed in to change notification settings - Fork 530
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
Compute pool metrics #2534
Merged
Merged
Compute pool metrics #2534
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
b31a03e
Define the MBean interface
vasilmkd 2697b8d
Implement the simple metrics
vasilmkd 9ebfb4e
Implement suspended fiber count metric
vasilmkd 9e1e941
Remove batched queue fibers metric
vasilmkd b9252e9
Implement blocked worker thread metric
vasilmkd 63469a9
Adjust package visibility of metrics implementation methods
vasilmkd b8367eb
Implement the sampler class
vasilmkd 2a73aed
Make the MBean implementation classes final
vasilmkd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
35 changes: 35 additions & 0 deletions
35
core/jvm/src/main/scala/cats/effect/unsafe/metrics/ComputePoolSampler.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2020-2021 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cats.effect.unsafe | ||
package metrics | ||
|
||
/** | ||
* An implementation of the [[ComputePoolSamplerMBean]] interface which simply delegates to the | ||
* corresponding methods of the [[cats.effect.unsafe.WorkStealingThreadPool]] being monitored. | ||
* | ||
* @param queue | ||
* the monitored local queue | ||
*/ | ||
private[unsafe] final class ComputePoolSampler(compute: WorkStealingThreadPool) | ||
extends ComputePoolSamplerMBean { | ||
def getWorkerThreadCount(): Int = compute.getWorkerThreadCount() | ||
def getActiveThreadCount(): Int = compute.getActiveThreadCount() | ||
def getSearchingThreadCount(): Int = compute.getSearchingThreadCount() | ||
def getBlockedWorkerThreadCount(): Int = compute.getBlockedWorkerThreadCount() | ||
def getLocalQueueFiberCount(): Long = compute.getLocalQueueFiberCount() | ||
def getSuspendedFiberCount(): Long = compute.getSuspendedFiberCount() | ||
} |
78 changes: 78 additions & 0 deletions
78
core/jvm/src/main/scala/cats/effect/unsafe/metrics/ComputePoolSamplerMBean.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Copyright 2020-2021 Typelevel | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package cats.effect.unsafe.metrics | ||
|
||
/** | ||
* An MBean interface for monitoring a [[WorkStealingThreadPool]] backed compute thread pool. | ||
*/ | ||
private[unsafe] trait ComputePoolSamplerMBean { | ||
|
||
/** | ||
* Returns the number of [[WorkerThread]] instances backing the [[WorkStealingThreadPool]]. | ||
* | ||
* @note | ||
* This is a fixed value, as the [[WorkStealingThreadPool]] has a fixed number of worker | ||
* threads. | ||
* | ||
* @return | ||
* the number of worker threads backing the compute pool | ||
*/ | ||
def getWorkerThreadCount(): Int | ||
|
||
/** | ||
* Returns the number of active [[WorkerThread]] instances currently executing fibers on the | ||
* compute thread pool. | ||
* | ||
* @return | ||
* the number of active worker threads | ||
*/ | ||
def getActiveThreadCount(): Int | ||
|
||
/** | ||
* Returns the number of [[WorkerThread]] instances currently searching for fibers to steal | ||
* from other worker threads. | ||
* | ||
* @return | ||
* the number of worker threads searching for work | ||
*/ | ||
def getSearchingThreadCount(): Int | ||
|
||
/** | ||
* Returns the number of [[WorkerThread]] instances which are currently blocked due to running | ||
* blocking actions on the compute thread pool. | ||
* | ||
* @return | ||
* the number of blocked worker threads | ||
*/ | ||
def getBlockedWorkerThreadCount(): Int | ||
|
||
/** | ||
* Returns the total number of fibers enqueued on all local queues. | ||
* | ||
* @return | ||
* the total number of fibers enqueued on all local queues | ||
*/ | ||
def getLocalQueueFiberCount(): Long | ||
|
||
/** | ||
* Returns the number of fibers which are currently asynchronously suspended. | ||
* | ||
* @return | ||
* the number of asynchronously suspended fibers | ||
*/ | ||
def getSuspendedFiberCount(): Long | ||
} |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pedagogical: why keep this behind a forwarder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because of this BS:
compiles to the following bytecode:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
blah()
getter is synchronized on thebitmap
field, which is volatile, incurring unnecessary synchronization points.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, I thought this happened even for
private[this]
fields which is why you moved everything to the constructor?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It does in the constructor. But for
private[this]
fields, the getter is not automatically generated by the compiler. A "forwarder" method accesses the field raw.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
compiles to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Forwarder is a Cats Effect nomenclature. I think I heard Daniel say it once, or use it, and I continued doing so. It doesn't have any meaning. It's the same as getter, the point is to write it ourselves and circumvent the synchronization that the Scala compiler would do otherwise. 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks 🤓 I'm very glad there's a workaround! But I wish I understood why the Scala compiler does this.