-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 (#15651)
* cancellation related Signed-off-by: Kiran Prakash <awskiran@amazon.com> * Update CHANGELOG.md Signed-off-by: Kiran Prakash <awskiran@amazon.com> * add better cancellation reason Signed-off-by: Kiran Prakash <awskiran@amazon.com> * Update DefaultTaskCancellationTests.java Signed-off-by: Kiran Prakash <awskiran@amazon.com> * refactor Signed-off-by: Kiran Prakash <awskiran@amazon.com> * refactor Signed-off-by: Kiran Prakash <awskiran@amazon.com> * Update DefaultTaskCancellation.java Signed-off-by: Kiran Prakash <awskiran@amazon.com> * Update DefaultTaskCancellation.java Signed-off-by: Kiran Prakash <awskiran@amazon.com> * Update DefaultTaskCancellation.java Signed-off-by: Kiran Prakash <awskiran@amazon.com> * Update DefaultTaskSelectionStrategy.java Signed-off-by: Kiran Prakash <awskiran@amazon.com> * refactor Signed-off-by: Kiran Prakash <awskiran@amazon.com> * refactor node level threshold Signed-off-by: Kiran Prakash <awskiran@amazon.com> * use query group task Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * code clean up and refactorings Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * add unit tests and fix existing ones Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * uncomment the test case Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * update CHANGELOG Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * fix imports Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * refactor and add UTs for new constructs Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * fix javadocs Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * remove code clutter Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * change annotation version and task selection strategy Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * rename a util class Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * remove wrappers from resource type Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * apply spotless Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * address comments Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * add rename changes Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * address comments Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * refactor changes and logical bug fix Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> * address comments Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> --------- Signed-off-by: Kiran Prakash <awskiran@amazon.com> Signed-off-by: Kaushal Kumar <ravi.kaushal97@gmail.com> Signed-off-by: Ankit Jain <akjain@amazon.com> Co-authored-by: Kiran Prakash <awskiran@amazon.com> Co-authored-by: Ankit Jain <akjain@amazon.com>
- 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.