Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement priority queueing in the resource syncer #1052

Open
wants to merge 7 commits into
base: devel
Choose a base branch
from

Conversation

tpantelis
Copy link
Contributor

@tpantelis tpantelis commented Jan 24, 2025

All pre-existing resources are queued by the informer on startup. With many resources in the hundreds or thousands it can take significant time to process them all and the work queue rate limiter can cause further significant delays. This can block newly created resources or existing resource updates for potentially minutes. Most of the time a pod restart is fairly quick so most resources didn't likely change so it makes sense to give newly created/updated resources higher priority and process them in a more timely manner.

The client-go work queue allows the backend Queue implementation to be configurable. This PR adds an implementation to the admiral workqueue module that is backed by a priority queue that is used in conjunction with the container/heap module and implements heap.Interface. A new EnqueueLowPriority method was added to the admiral workqueue.Interface that enqueues the item with priority 0. The existing Enqueue method was modified to enqueue with higher priority 1.

The resource syncer was modified to use the EnqueueLowPriority method to prioritize newly created/updated resources over pre-existing resources on startup. The cache.ResourceEventHandler's OnAdd method has an isInInitialList param that indicates if the obj was pre-existing in the initial listing retrieved from the API server. If isInInitialList is true then enqueue with low priority otherwise use normal priority (Enqueue method).

See commits for more details.

Related to submariner-io/lighthouse#1706

@submariner-bot
Copy link
Contributor

🤖 Created branch: z_pr1052/tpantelis/priority_queue

...for use with the "container/heap" module that implements heap.Interface.
The items in the queue are ordered by descending priority such that
items with higher priority values are de-queued first.

Signed-off-by: Tom Pantelis <[email protected]>
...by configuring backend Queue for the client-go rate-limiting queue.
The work queue exposes two priorities for enqueue: normal priority via
the existing Enqueue method and low priority via a new EnqueueLowPriority
method.

Signed-off-by: Tom Pantelis <[email protected]>
Utilize the workqueue's EnqueueLowPriority method to prioritize newly
created/updated resources over pre-existing resources on startup.
The cache.ResourceEventHandler's OnAdd method has an 'isInInitialList'
param that indicates if the obj is pre-existing in the initial listing
retrieved from the API server. If 'isInInitialList' is true then
enqueue with low priority otherwise use normal priority (Enqueue method).

The underlying priority queue might adjust the ordering of items with
the same priority so the ordering of items enqueued might not be the
same order that they're dequeued. As such, the namespace event handling
needed to be modified to use the 'operationQueues' to maintain the ordering
of adds and deletes.

Signed-off-by: Tom Pantelis <[email protected]>
On an informer re-sync, all resources are re-notified as update events.
Most likely the resources didn't actually change so enqueue with low
priority if the ResourceVersion didn't change.

Signed-off-by: Tom Pantelis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

2 participants