Cache continued tasks during queue maintenance#565
Open
bennettzhu1 wants to merge 1 commit into
Open
Conversation
Queue maintenance calls QueueTaskDispatcher.canTake for each buildable item and idle executor. ContinuedTask.Scheduler previously scanned every buildable item on each call to find continued tasks, making queue maintenance quadratic in the number of buildables. Maintain a queue-id keyed cache of buildable continued tasks via QueueListener events. The first scheduler call initializes the cache from the current buildable queue, and later queue transitions add or remove entries. Cache entries keep only a weak task reference plus display name and assigned label so stale entries can be dropped during the next scheduler pass. Add coverage for a cached task that stops being continued. Fixes jenkinsci#560
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.
Fixes #560
We have seen jenkins queue maintenance spend a lot of time in
ContinuedTask.Scheduer.canTake. Queue.maintain already iterates through each buildable and idle executor, and then for each buildable, scans the full buildable queue again to see if any are ContinuedTasks.To avoid the full buildable loop again, this PR creates a cache of buildable
ContinuedTaskitems. On first pass, populates the map ofContinuedTasks, else it watches theQueueListenerto update the cache.This brings the execution time from
(buildable)^2 * idle executorstobuildables * idle executors * unique continued tasks. I briefly thought of caching by node to continued task, but it makes updating the cache very messy.Testing done
We tested it in our staging environment, and we are currently running this patch at my company.
Submitter checklist