-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Add cancellation framework changes in wlm #15651
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
Merged
jainankitk
merged 34 commits into
opensearch-project:main
from
kaushalmahi12:feature/wlm-cancellation
Sep 11, 2024
Merged
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit
Hold shift + click to select a range
a720136
cancellation related
kiranprakash154 83e20c0
Update CHANGELOG.md
kiranprakash154 9983c73
add better cancellation reason
kiranprakash154 245ee5d
Update DefaultTaskCancellationTests.java
kiranprakash154 0771fd2
refactor
kiranprakash154 4b1ef81
refactor
kiranprakash154 3ea44d7
Update DefaultTaskCancellation.java
kiranprakash154 0103089
Update DefaultTaskCancellation.java
kiranprakash154 092d715
Update DefaultTaskCancellation.java
kiranprakash154 4a2c51e
Update DefaultTaskSelectionStrategy.java
kiranprakash154 cbb51bd
refactor
kiranprakash154 4e846e2
refactor node level threshold
kiranprakash154 241b036
Merge branch 'main' into kp/wlm-cancellation-1
kaushalmahi12 7511d99
use query group task
kaushalmahi12 498743a
code clean up and refactorings
kaushalmahi12 e26e525
add unit tests and fix existing ones
kaushalmahi12 0ff2b09
uncomment the test case
kaushalmahi12 ddb8dce
update CHANGELOG
kaushalmahi12 3528054
Merge branch 'main' into feature/wlm-cancellation
kaushalmahi12 e8366a5
fix imports
kaushalmahi12 448ea41
refactor and add UTs for new constructs
kaushalmahi12 3fc21be
fix javadocs
kaushalmahi12 fe02a6a
remove code clutter
kaushalmahi12 8aede33
change annotation version and task selection strategy
kaushalmahi12 623f6f8
rename a util class
kaushalmahi12 9e2e3ea
remove wrappers from resource type
kaushalmahi12 34184ef
apply spotless
kaushalmahi12 91893e7
address comments
kaushalmahi12 66e43b2
add rename changes
kaushalmahi12 a6b1afd
Merge branch 'main' into feature/wlm-cancellation
kaushalmahi12 981b15f
address comments
kaushalmahi12 caf5914
refactor changes and logical bug fix
kaushalmahi12 b78ca02
address comments
kaushalmahi12 7bb6b2c
Merge branch 'main' into feature/wlm-cancellation
jainankitk 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 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
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
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
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
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
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
71 changes: 71 additions & 0 deletions
71
...r/src/main/java/org/opensearch/wlm/cancellation/MaximumResourceTaskSelectionStrategy.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| * | ||
| * The OpenSearch Contributors require contributions made to | ||
| * this file be licensed under the Apache-2.0 license or a | ||
| * compatible open source license. | ||
| */ | ||
|
|
||
| package org.opensearch.wlm.cancellation; | ||
|
|
||
| import org.opensearch.wlm.QueryGroupTask; | ||
| import org.opensearch.wlm.ResourceType; | ||
|
|
||
| import java.util.ArrayList; | ||
| import java.util.Collections; | ||
| import java.util.Comparator; | ||
| import java.util.List; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import static org.opensearch.wlm.cancellation.QueryGroupTaskCancellationService.MIN_VALUE; | ||
|
|
||
| /** | ||
| * Represents the highest resource consuming task first selection strategy. | ||
| */ | ||
| public class MaximumResourceTaskSelectionStrategy implements TaskSelectionStrategy { | ||
|
|
||
| public MaximumResourceTaskSelectionStrategy() {} | ||
|
|
||
| /** | ||
| * Returns a comparator that defines the sorting condition for tasks. | ||
| * This is the default implementation since the most resource consuming tasks are the likely to regress the performance. | ||
| * from resiliency point of view it makes sense to cancel them first | ||
| * | ||
| * @return The comparator | ||
| */ | ||
| private Comparator<QueryGroupTask> sortingCondition(ResourceType resourceType) { | ||
| return Comparator.comparingDouble(task -> resourceType.getResourceUsageCalculator().calculateTaskResourceUsage(task)); | ||
| } | ||
|
|
||
| /** | ||
| * Selects tasks for cancellation based on the provided limit and resource type. | ||
| * The tasks are sorted based on the sorting condition and then selected until the accumulated resource usage reaches the limit. | ||
| * | ||
| * @param tasks The list of tasks from which to select | ||
| * @param limit The limit on the accumulated resource usage | ||
| * @param resourceType The type of resource to consider | ||
| * @return The list of selected tasks | ||
| * @throws IllegalArgumentException If the limit is less than zero | ||
| */ | ||
| public List<QueryGroupTask> selectTasksForCancellation(List<QueryGroupTask> tasks, double limit, ResourceType resourceType) { | ||
| if (limit < 0) { | ||
| throw new IllegalArgumentException("limit has to be greater than zero"); | ||
| } | ||
| if (limit < MIN_VALUE) { | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| List<QueryGroupTask> sortedTasks = tasks.stream().sorted(sortingCondition(resourceType).reversed()).collect(Collectors.toList()); | ||
|
|
||
| List<QueryGroupTask> selectedTasks = new ArrayList<>(); | ||
| double accumulated = 0; | ||
| for (QueryGroupTask task : sortedTasks) { | ||
| selectedTasks.add(task); | ||
| accumulated += resourceType.getResourceUsageCalculator().calculateTaskResourceUsage(task); | ||
| if ((accumulated - limit) > MIN_VALUE) { | ||
| break; | ||
| } | ||
| } | ||
| return selectedTasks; | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.