feat(DM01-6251): decouple blocking K8s API calls from scheduler main loop - #641
Merged
Conversation
…loop Move GET /api/v1/nodes and GET ibpipelineinvocations out of the main scheduling loop into a daemon thread that refreshes every 10s. The main loop now reads from a lock-protected cache instead of making synchronous HTTP requests on every tick. Root cause: under K8s API load these calls blocked for up to 10s each, causing the 1s scheduler loop to actually run every 10-20s. With a backlog of queued jobs this produced queue-wait times of hours (confirmed: generator/di-embedded-tests waited 2.8h before being scheduled). Also increase main loop sleep from 1s to 3s to further reduce DB and K8s API pressure. abort/timeout response latency increases by at most 3s, which is acceptable.
- Add r.raise_for_status() before r.json() in both refresh methods so HTTP error responses (401, 503) raise an exception and leave the previously valid cache intact, instead of silently overwriting it with an empty list - Run initial synchronous K8s fetch in __init__ so caches are populated before the first scheduler tick; prevents update_cluster_state from skipping the DB write during the first 10s after startup - Split nodes and pipelines into independent background threads so a slow/hung K8s nodes API call does not delay the pipelines refresh
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.
Summary
GET /api/v1/nodesandGET ibpipelineinvocationsfrom the main scheduler loop into a daemon background thread that refreshes every 10ssleep(1)→sleep(3)to reduce DB and K8s API pressureRoot Cause
Under K8s API load, the two blocking HTTP calls (10s timeout each) caused the nominal 1s scheduler loop to actually run every 10–20s. With a backlog of queued jobs this multiplied into queue-wait times of hours.
Evidence:
generator/di-embedded-testsqueue_wait = 10,211s (~2.8h). Normal expected wait: < 5s.How the fix works
Before:
After:
Risk
schedule(),handle_aborts(),handle_timeouts()logic untouchedTest plan