forked from opensearch-project/OpenSearch
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add cancellation framework changes in wlm (opensearch-project#15651)
* cancellation related Signed-off-by: Kiran Prakash <[email protected]> * Update CHANGELOG.md Signed-off-by: Kiran Prakash <[email protected]> * add better cancellation reason Signed-off-by: Kiran Prakash <[email protected]> * Update DefaultTaskCancellationTests.java Signed-off-by: Kiran Prakash <[email protected]> * refactor Signed-off-by: Kiran Prakash <[email protected]> * refactor Signed-off-by: Kiran Prakash <[email protected]> * Update DefaultTaskCancellation.java Signed-off-by: Kiran Prakash <[email protected]> * Update DefaultTaskCancellation.java Signed-off-by: Kiran Prakash <[email protected]> * Update DefaultTaskCancellation.java Signed-off-by: Kiran Prakash <[email protected]> * Update DefaultTaskSelectionStrategy.java Signed-off-by: Kiran Prakash <[email protected]> * refactor Signed-off-by: Kiran Prakash <[email protected]> * refactor node level threshold Signed-off-by: Kiran Prakash <[email protected]> * use query group task Signed-off-by: Kaushal Kumar <[email protected]> * code clean up and refactorings Signed-off-by: Kaushal Kumar <[email protected]> * add unit tests and fix existing ones Signed-off-by: Kaushal Kumar <[email protected]> * uncomment the test case Signed-off-by: Kaushal Kumar <[email protected]> * update CHANGELOG Signed-off-by: Kaushal Kumar <[email protected]> * fix imports Signed-off-by: Kaushal Kumar <[email protected]> * refactor and add UTs for new constructs Signed-off-by: Kaushal Kumar <[email protected]> * fix javadocs Signed-off-by: Kaushal Kumar <[email protected]> * remove code clutter Signed-off-by: Kaushal Kumar <[email protected]> * change annotation version and task selection strategy Signed-off-by: Kaushal Kumar <[email protected]> * rename a util class Signed-off-by: Kaushal Kumar <[email protected]> * remove wrappers from resource type Signed-off-by: Kaushal Kumar <[email protected]> * apply spotless Signed-off-by: Kaushal Kumar <[email protected]> * address comments Signed-off-by: Kaushal Kumar <[email protected]> * add rename changes Signed-off-by: Kaushal Kumar <[email protected]> * address comments Signed-off-by: Kaushal Kumar <[email protected]> * refactor changes and logical bug fix Signed-off-by: Kaushal Kumar <[email protected]> * address comments Signed-off-by: Kaushal Kumar <[email protected]> --------- Signed-off-by: Kiran Prakash <[email protected]> Signed-off-by: Kaushal Kumar <[email protected]> Signed-off-by: Ankit Jain <[email protected]> Co-authored-by: Kiran Prakash <[email protected]> Co-authored-by: Ankit Jain <[email protected]>
- Loading branch information
1 parent
9354dd9
commit 58794ad
Showing
20 changed files
with
1,297 additions
and
98 deletions.
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
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
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
71 changes: 71 additions & 0 deletions
71
...r/src/main/java/org/opensearch/wlm/cancellation/MaximumResourceTaskSelectionStrategy.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,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.