perf: eliminate expensive log construction in remote-task-runner shutdown (#12097)

This commit is contained in:
Jason Koch 2022-03-03 13:38:21 -08:00 committed by GitHub
parent f594e7ac24
commit 36193955b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 9 additions and 5 deletions

View File

@ -325,13 +325,17 @@ public class TaskQueue
final Set<String> tasksToKill = Sets.difference(runnerTaskFutures.keySet(), knownTaskIds);
if (!tasksToKill.isEmpty()) {
log.info("Asking taskRunner to clean up %,d tasks.", tasksToKill.size());
// On large installations running several thousands of tasks,
// concatenating the list of known task ids can be compupationally expensive.
final boolean logKnownTaskIds = log.isDebugEnabled();
final String reason = logKnownTaskIds
? String.format("Task is not in knownTaskIds[%s]", knownTaskIds)
: "Task is not in knownTaskIds";
for (final String taskId : tasksToKill) {
try {
taskRunner.shutdown(
taskId,
"task is not in knownTaskIds[%s]",
knownTaskIds
);
taskRunner.shutdown(taskId, reason);
}
catch (Exception e) {
log.warn(e, "TaskRunner failed to clean up task: %s", taskId);