feat(metrics): wrap executor.heartbeat() in a timer to localize loop slowdowns#66808
Merged
Merged
Conversation
…slowdowns Emit scheduler.executor_heartbeat_duration as a per-executor timer so operators can see whether executor.heartbeat() is the bottleneck of a slow scheduler loop, instead of inferring from the aggregate scheduler.scheduler_loop_duration. Tagged by type(executor).__name__ so multi-executor deployments attribute the cost to each configured executor separately. Closes apache#66803 Signed-off-by: 1fanwang <1fannnw@gmail.com>
potiuk
approved these changes
May 12, 2026
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
dag_processing.loop_durationis aggregate. When the scheduler loop slows down, there's no signal pointing at the executor as the cause —executor.heartbeat()runs every iteration and can spike from Kubernetes API throttling, Celery broker lag, etc., but its wall time is folded into the loop total.Fix
Wrap
executor.heartbeat()instats.timer("scheduler.executor_heartbeat_duration"), tagged withexecutor: <ClassName>so each configured executor reports independently in multi-executor deployments.Tests
test_executor_heartbeat_emits_timerpatchesstats.timer, runs one scheduler loop iteration with the two-executormock_executorsfixture, and asserts the timer was opened once per executor with the right metric name andtags={"executor": <class>}.Note
I scoped this to
executor.heartbeat()only, not_process_executor_events. The two calls are structurally separate — they live in different loops with a freshcreate_session()block between them — and their cost characteristics differ (heartbeat is executor I/O;_process_executor_eventsis DB writes plus event-buffer drain). They look like two independent signals rather than a tight pair, so a separate timer for_process_executor_eventsmakes sense as a follow-up if the same need surfaces there. Happy to roll it into this PR if reviewers would prefer.Closes #66803