refactor: Migrate to folly::available_concurrency#27326
Merged
amitkdutta merged 1 commit intoprestodb:masterfrom Mar 16, 2026
Merged
refactor: Migrate to folly::available_concurrency#27326amitkdutta merged 1 commit intoprestodb:masterfrom
amitkdutta merged 1 commit intoprestodb:masterfrom
Conversation
The name `hardware_concurrency`, while parallel to `std::thread::hardware_concurrency`, may be misleading. Migrate to the name `available_concurrency`.
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideRefactors the server and tests to use folly::available_concurrency() instead of folly::hardware_concurrency() everywhere, keeping configuration and thread-pool sizing logic otherwise identical. Class diagram for usage of folly_available_concurrency in PrestoServer and ConfigsclassDiagram
class PrestoServer {
+void initializeThreadPools()
+void checkOverload()
+protocol_NodeStatus fetchNodeStatus()
}
class Configs {
+static uint32_t hardwareConcurrency()
}
class FollyRuntime {
+static size_t available_concurrency()
}
PrestoServer ..> FollyRuntime : uses_available_concurrency
Configs ..> FollyRuntime : uses_available_concurrency
PrestoServer ..> Configs : may_call_hardwareConcurrency
Flow diagram for thread pool sizing using folly_available_concurrencyflowchart TD
Start([Start initializeThreadPools]) --> GetConfig[Get SystemConfig_instance]
GetConfig --> GetHw[hwConcurrency = folly_available_concurrency]
GetHw --> DriverCpu["Compute numDriverCpuThreads = max(driverMultiplier * hwConcurrency, 1)"]
DriverCpu --> ExchangeIo["Compute numExchangeHttpClientIoThreads = max(exchangeIoMultiplier * folly_available_concurrency, 1)"]
ExchangeIo --> ExchangeCpu["Compute numExchangeHttpClientCpuThreads = max(exchangeCpuMultiplier * folly_available_concurrency, 1)"]
ExchangeCpu --> ConnectorCpu["Compute numConnectorCpuThreads = max(connectorCpuMultiplier * folly_available_concurrency, 0)"]
ConnectorCpu --> ConnectorIo["Compute numConnectorIoThreads = max(connectorIoMultiplier * folly_available_concurrency, 0)"]
ConnectorIo --> End([Create thread pool executors with computed sizes])
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
PrestoServer::checkOverload,hwConcurrencyis now derived fromfolly::available_concurrency()but still cached in astatic const—ifavailable_concurrencyis meant to reflect dynamic limits (e.g., cgroup/numa changes), consider recomputing it each time instead of storing it statically so overload thresholds stay aligned with the current environment.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `PrestoServer::checkOverload`, `hwConcurrency` is now derived from `folly::available_concurrency()` but still cached in a `static const`—if `available_concurrency` is meant to reflect dynamic limits (e.g., cgroup/numa changes), consider recomputing it each time instead of storing it statically so overload thresholds stay aligned with the current environment.
## Individual Comments
### Comment 1
<location path="presto-native-execution/presto_cpp/main/PrestoServer.cpp" line_range="1710" />
<code_context>
}
- static const auto hwConcurrency = folly::hardware_concurrency();
+ static const auto hwConcurrency = folly::available_concurrency();
const auto overloadedThresholdCpuPct =
systemConfig->workerOverloadedThresholdCpuPct();
</code_context>
<issue_to_address>
**issue:** Guard against available_concurrency() returning 0 when computing overload thresholds.
At other call sites you wrap `folly::available_concurrency()` in `std::max(..., 1)`, but here the static `hwConcurrency` feeds directly into the overload logic. If `available_concurrency()` returns 0 (as noted in `hardwareConcurrency()`), `overloadedThresholdQueuedDrivers` becomes 0 and overload detection effectively stops working. Please normalize this value here (e.g., `std::max<size_t>(folly::available_concurrency(), 1)` or by using `hardwareConcurrency()`).
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
amitkdutta
approved these changes
Mar 16, 2026
This was referenced Mar 31, 2026
15 tasks
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 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.
The name
hardware_concurrency, while parallel tostd::thread::hardware_concurrency, may be misleading. Migrate to the nameavailable_concurrency.Summary by Sourcery
Standardize concurrency detection on folly::available_concurrency across the Presto C++ server, configuration utilities, and related tests.
Enhancements:
Tests: