-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Configure worker threads relative to core count #20772
Merged
findepi
merged 3 commits into
trinodb:master
from
findepi:findepi/configure-worker-threads-relative-to-core-count-144a9e
Feb 21, 2024
Merged
Changes from all commits
Commits
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
61 changes: 61 additions & 0 deletions
61
core/trino-main/src/main/java/io/trino/execution/ThreadCountParser.java
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,61 @@ | ||
/* | ||
* 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 io.trino.execution; | ||
|
||
import com.google.common.annotations.VisibleForTesting; | ||
|
||
import java.util.function.Supplier; | ||
|
||
import static com.google.common.base.Preconditions.checkArgument; | ||
import static com.google.common.base.Preconditions.checkState; | ||
import static java.lang.Long.parseLong; | ||
import static java.lang.Math.multiplyExact; | ||
import static java.lang.Math.toIntExact; | ||
import static java.util.Objects.requireNonNull; | ||
|
||
// Based on https://github.com/airlift/units/pull/31, but adapted not to be a value class per https://github.com/trinodb/trino/pull/16303#issuecomment-1730146433 | ||
public class ThreadCountParser | ||
{ | ||
private static final String PER_CORE_SUFFIX = "C"; | ||
private static final Supplier<Integer> AVAILABLE_PROCESSORS = Runtime.getRuntime()::availableProcessors; | ||
public static final ThreadCountParser DEFAULT = new ThreadCountParser(AVAILABLE_PROCESSORS); | ||
|
||
private final Supplier<Integer> coreCount; | ||
|
||
@VisibleForTesting | ||
ThreadCountParser(Supplier<Integer> coreCount) | ||
{ | ||
this.coreCount = requireNonNull(coreCount, "coreCount is null"); | ||
} | ||
|
||
public int parse(String value) | ||
{ | ||
int coreCount = this.coreCount.get(); | ||
checkState(coreCount > 0, "coreCount must be positive"); | ||
|
||
long threads; | ||
if (value.endsWith(PER_CORE_SUFFIX)) { | ||
long multiplier = parseLong(value.substring(0, value.length() - PER_CORE_SUFFIX.length()).trim()); | ||
checkArgument(multiplier > 0, "Thread multiplier cannot be negative"); | ||
threads = multiplyExact(multiplier, coreCount); | ||
} | ||
else { | ||
threads = parseLong(value); | ||
} | ||
|
||
checkArgument(threads <= Integer.MAX_VALUE, "Thread count is greater than 2^32 - 1"); | ||
checkArgument(0 <= threads, "Thread count cannot be negative"); | ||
findepi marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return toIntExact(threads); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
core/trino-main/src/main/java/io/trino/operator/index/IndexLoader.java
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
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
Oops, something went wrong.
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.
Can we add
@ConfigDescription
and documentation ?Maybe also deprecate
task.shard.max-threads
in another commitThere 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.
that's orthogonal, i believe?