Package org.opensearch.tasks
Class TaskResourceTrackingService
java.lang.Object
org.opensearch.tasks.TaskResourceTrackingService
- All Implemented Interfaces:
RunnableTaskExecutionListener
Service that helps track resource usage of tasks running on a node.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interface
Listener that gets invoked when a task execution completes. -
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionTaskResourceTrackingService
(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool) -
Method Summary
Modifier and TypeMethodDescriptionvoid
boolean
boolean
void
refreshResourceStats
(Task... tasks) Refreshes the resource stats for the tasks provided by looking into which threads are actively working on these and how much resources these have consumed till now.void
setTaskResourceTrackingEnabled
(boolean taskResourceTrackingEnabled) startTracking
(Task task) Executes logic only if task supports resource tracking and resource tracking setting is enabled.void
stopTracking
(Task task) Stops tracking task registered earlier for tracking.void
taskExecutionFinishedOnThread
(long taskId, long threadId) Called when a thread finishes working on a task's runnable.void
taskExecutionStartedOnThread
(long taskId, long threadId) Called when a thread starts working on a task's runnable.
-
Field Details
-
TASK_RESOURCE_TRACKING_ENABLED
-
TASK_ID
- See Also:
-
-
Constructor Details
-
TaskResourceTrackingService
@Inject public TaskResourceTrackingService(Settings settings, ClusterSettings clusterSettings, ThreadPool threadPool)
-
-
Method Details
-
setTaskResourceTrackingEnabled
public void setTaskResourceTrackingEnabled(boolean taskResourceTrackingEnabled) -
isTaskResourceTrackingEnabled
public boolean isTaskResourceTrackingEnabled() -
isTaskResourceTrackingSupported
public boolean isTaskResourceTrackingSupported() -
startTracking
Executes logic only if task supports resource tracking and resource tracking setting is enabled.1. Starts tracking the task in map of resourceAwareTasks. 2. Adds Task Id in thread context to make sure it's available while task is processed across multiple threads.
- Parameters:
task
- for which resources needs to be tracked- Returns:
- Autocloseable stored context to restore ThreadContext to the state before this method changed it.
-
stopTracking
Stops tracking task registered earlier for tracking.It doesn't have feature enabled check to avoid any issues if setting was disable while the task was in progress.
It's also responsible to stop tracking the current thread's resources against this task if not already done. This happens when the thread executing the request logic itself calls the unregister method. So in this case unregister happens before runnable finishes.
- Parameters:
task
- task which has finished and doesn't need resource tracking.
-
refreshResourceStats
Refreshes the resource stats for the tasks provided by looking into which threads are actively working on these and how much resources these have consumed till now.- Parameters:
tasks
- for which resource stats needs to be refreshed.
-
taskExecutionStartedOnThread
public void taskExecutionStartedOnThread(long taskId, long threadId) Called when a thread starts working on a task's runnable.- Specified by:
taskExecutionStartedOnThread
in interfaceRunnableTaskExecutionListener
- Parameters:
taskId
- of the task for which runnable is startingthreadId
- of the thread which will be executing the runnable and we need to check resource usage for this thread
-
taskExecutionFinishedOnThread
public void taskExecutionFinishedOnThread(long taskId, long threadId) Called when a thread finishes working on a task's runnable.- Specified by:
taskExecutionFinishedOnThread
in interfaceRunnableTaskExecutionListener
- Parameters:
taskId
- of the task for which runnable is completethreadId
- of the thread which executed the runnable and we need to check resource usage for this thread
-
getResourceAwareTasks
-
addTaskCompletionListener
-