Avoid busy waiting for processable tasks. We need to be a bit careful here to not have the task executors to sleep when work is available. We have to make sure to signal on the condition variable any time a task becomes "processable". Here are some situations where a task becomes processable:
- Task is unassigned from another TaskExecutor.
- Task state is changed (should only happen inside when a task is locked inside the polling phase).
- When tasks are unlocked.
- When tasks are added.
- New records available.
- A task is resumed.
So in summary, we
- We should probably lock tasks when they are paused and unlock them when they are resumed. We should also wake the task executors after every polling phase. This belongs to the StreamThread integration work (separate PR). We add DefaultTaskManager.signalProcessableTasks for this.
- We need to awake the task executors in DefaultTaskManager.unassignTask, DefaultTaskManager.unlockTasks and DefaultTaskManager.add.
Reviewers: Walker Carlson <wcarlson@confluent.io>, Bruno Cadonna <cadonna@apache.org>
@ -530,4 +530,10 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read
@@ -530,4 +530,10 @@ For a detailed description of spotbugs bug categories, see https://spotbugs.read
<Bugpattern="DMI_RANDOM_USED_ONLY_ONCE"/>
</Match>
<Match>
<!-- Suppress a warning about await not being in a loop - we expect the loop to be outside the method. -->
@ -94,7 +94,13 @@ public class DefaultTaskExecutor implements TaskExecutor {
@@ -94,7 +94,13 @@ public class DefaultTaskExecutor implements TaskExecutor {
@ -108,7 +110,7 @@ public class DefaultTaskManager implements TaskManager {
@@ -108,7 +110,7 @@ public class DefaultTaskManager implements TaskManager {
assignedTasks.put(task.id(),executor);
log.info("Assigned {} to executor {}",task.id(),executor.name());
log.debug("Assigned task {} to executor {}",task.id(),executor.name());
return(StreamTask)task;
}
@ -118,6 +120,41 @@ public class DefaultTaskManager implements TaskManager {
@@ -118,6 +120,41 @@ public class DefaultTaskManager implements TaskManager {
@ -132,7 +169,8 @@ public class DefaultTaskManager implements TaskManager {
@@ -132,7 +169,8 @@ public class DefaultTaskManager implements TaskManager {
assignedTasks.remove(task.id());
log.info("Unassigned {} from executor {}",task.id(),executor.name());
log.debug("Unassigned {} from executor {}",task.id(),executor.name());
tasksCondition.signalAll();
});
}
@ -188,7 +226,11 @@ public class DefaultTaskManager implements TaskManager {
@@ -188,7 +226,11 @@ public class DefaultTaskManager implements TaskManager {
@ -202,6 +244,8 @@ public class DefaultTaskManager implements TaskManager {
@@ -202,6 +244,8 @@ public class DefaultTaskManager implements TaskManager {
for(finalStreamTasktask:tasksToAdd){
tasks.addTask(task);
}
log.debug("Waking up task executors");
tasksCondition.signalAll();
});
log.info("Added tasks {} to the task manager to process",tasksToAdd);
@ -261,12 +305,11 @@ public class DefaultTaskManager implements TaskManager {
@@ -261,12 +305,11 @@ public class DefaultTaskManager implements TaskManager {