Make CPU utilization checks in the thread pool configurable#112789
Merged
kouvel merged 1 commit intodotnet:mainfrom Feb 25, 2025
kouvel:ConfigCpuUtil
Merged
Make CPU utilization checks in the thread pool configurable#112789kouvel merged 1 commit intodotnet:mainfrom kouvel:ConfigCpuUtil
kouvel merged 1 commit intodotnet:mainfrom
kouvel:ConfigCpuUtil
Conversation
Contributor
kouvel
commented
Feb 21, 2025
- On Windows, checking CPU utilization seems to involve a small amount of overhead, which can become noticeable or even significant in some scenarios. This change makes the intervals of time over which CPU utilization is computed configurable. Increasing the interval increases the period at which CPU utilization is updated. The same config var can also be used to disable CPU utilization checks and have features that use it behave as though CPU utilization is low.
- CPU utilization is used by the starvation heuristic and hill climbing. When CPU utilization is very high, the starvation heuristic reduces the rate of thread injection in starved cases. When CPU utilization is high, hill climbing avoids settling on higher thread count control values.
- CPU utilization is currently updated when the gate thread performs periodic activities, which happens typically every 500 ms when a worker thread is active. There is one gate thread per .NET process.
- In scenarios where there are many .NET processes running, and where many of them frequently but lightly use the thread pool, overall CPU usage may be relatively low, but the overhead from CPU utilization checks can bubble up to a noticeable portion of overall CPU usage. In a scenario involving 100s of .NET processes, it was seen that CPU utilization checks amount to 0.5-1% of overall CPU usage on the machine, which was considered significant.
- On Windows, checking CPU utilization seems to involve a small amount of overhead, which can become noticeable or even significant in some scenarios. This change makes the intervals of time over which CPU utilization is computed configurable. Increasing the interval increases the period at which CPU utilization is updated. The same config var can also be used to disable CPU utilization checks and have features that use it behave as though CPU utilization is low. - CPU utilization is used by the starvation heuristic and hill climbing. When CPU utilization is very high, the starvation heuristic reduces the rate of thread injection in starved cases. When CPU utilization is high, hill climbing avoids settling on higher thread count control values. - CPU utilization is currently updated when the gate thread performs periodic activities, which happens typically every 500 ms when a worker thread is active. There is one gate thread per .NET process. - In scenarios where there are many .NET processes running, and where many of them frequently but lightly use the thread pool, overall CPU usage may be relatively low, but the overhead from CPU utilization checks can bubble up to a noticeable portion of overall CPU usage. In a scenario involving 100s of .NET processes, it was seen that CPU utilization checks amount to 0.5-1% of overall CPU usage on the machine, which was considered significant.
Contributor
There was a problem hiding this comment.
Copilot reviewed 1 out of 1 changed files in this pull request and generated no comments.
Comments suppressed due to low confidence (2)
src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.GateThread.cs:34
- It looks like a new configuration variable has been introduced to control CPU utilization refresh behavior. Please ensure that there are tests verifying that CPU utilization updates are correctly enabled and disabled based on different values of cpuUtilizationIntervalMs, including edge cases (such as 0 for disabled and positive values for active updating).
int cpuUtilizationIntervalMs = AppContextConfigHelper.GetInt32Config(...
src/libraries/System.Private.CoreLib/src/System/Threading/PortableThreadPool.GateThread.cs:124
- Please verify via tests that the interval check and subsequent CPU utilization update behave as expected; this includes ensuring that the timing logic (using Environment.TickCount differences) is robust in scenarios where the interval value is changed.
if (cpuUtilizationIntervalMs > 0 && ... && (uint)(currentTimeMs - lastCpuUtilizationRefreshTimeMs) >= (uint)cpuUtilizationIntervalMs)
Contributor
|
Tagging subscribers to this area: @mangod9 |
This was referenced Feb 21, 2025
This was referenced Feb 21, 2025
mangod9
approved these changes
Feb 25, 2025
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.