-
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.
Browse files
Browse the repository at this point in the history
* cancellation related * Update CHANGELOG.md * add better cancellation reason * Update DefaultTaskCancellationTests.java * refactor * refactor * Update DefaultTaskCancellation.java * Update DefaultTaskCancellation.java * Update DefaultTaskCancellation.java * Update DefaultTaskSelectionStrategy.java * refactor * refactor node level threshold * use query group task * code clean up and refactorings * add unit tests and fix existing ones * uncomment the test case * update CHANGELOG * fix imports * refactor and add UTs for new constructs * fix javadocs * remove code clutter * change annotation version and task selection strategy * rename a util class * remove wrappers from resource type * apply spotless * address comments * add rename changes * address comments * refactor changes and logical bug fix * address comments --------- 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
fa6de0d
commit a05d6d1
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.