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

improving scheduler enqueue performance #399

Merged
merged 1 commit into from Jun 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
32 changes: 18 additions & 14 deletions pkg/scheduler/scheduler.go
Expand Up @@ -240,7 +240,10 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) {

sub, err := sched.subsLister.Subscriptions(ns).Get(name)
if err != nil {
utilruntime.HandleError(err)
if !errors.IsNotFound(err) {
utilruntime.HandleError(err)
sched.SchedulingQueue.AddRateLimited(key)
}
return
}
klog.V(3).InfoS("Attempting to schedule subscription", "subscription", klog.KObj(sub))
Expand All @@ -251,6 +254,7 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) {
if err != nil {
if !errors.IsNotFound(err) {
utilruntime.HandleError(err)
sched.SchedulingQueue.AddRateLimited(key)
}
return
}
Expand All @@ -276,7 +280,7 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) {

scheduleResult, err := sched.scheduleAlgorithm.Schedule(schedulingCycleCtx, sched.framework, state, sub, finv)
if err != nil {
sched.recordSchedulingFailure(sub, err, ReasonUnschedulable)
sched.handleSchedulingFailure(sub, err, ReasonUnschedulable)
if !strings.Contains(err.Error(), "clusters are available") {
return
}
Expand All @@ -289,7 +293,7 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) {
metrics.SubscriptionScheduleError(sched.framework.ProfileName(), metrics.SinceInSeconds(start))
// trigger un-reserve to clean up state associated with the reserved subscription
sched.framework.RunReservePluginsUnreserve(schedulingCycleCtx, state, sub, targetClusters)
sched.recordSchedulingFailure(sub, sts.AsError(), SchedulerError)
sched.handleSchedulingFailure(sub, sts.AsError(), SchedulerError)
return
}

Expand All @@ -306,7 +310,7 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) {
}
// One of the plugins returned status different from success or wait.
sched.framework.RunReservePluginsUnreserve(schedulingCycleCtx, state, sub, targetClusters)
sched.recordSchedulingFailure(sub, runPermitStatus.AsError(), reason)
sched.handleSchedulingFailure(sub, runPermitStatus.AsError(), reason)
return
}

Expand All @@ -329,7 +333,7 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) {
}
// trigger un-reserve plugins to clean up state associated with the reserved subscription
sched.framework.RunReservePluginsUnreserve(bindingCycleCtx, state, sub, targetClusters)
sched.recordSchedulingFailure(sub, waitOnPermitStatus.AsError(), reason)
sched.handleSchedulingFailure(sub, waitOnPermitStatus.AsError(), reason)
return
}

Expand All @@ -339,7 +343,7 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) {
metrics.SubscriptionScheduleError(sched.framework.ProfileName(), metrics.SinceInSeconds(start))
// trigger un-reserve plugins to clean up state associated with the reserved subscription
sched.framework.RunReservePluginsUnreserve(bindingCycleCtx, state, sub, targetClusters)
sched.recordSchedulingFailure(sub, preBindStatus.AsError(), SchedulerError)
sched.handleSchedulingFailure(sub, preBindStatus.AsError(), SchedulerError)
return
}

Expand All @@ -348,7 +352,7 @@ func (sched *Scheduler) scheduleOne(ctx context.Context) {
metrics.SubscriptionScheduleError(sched.framework.ProfileName(), metrics.SinceInSeconds(start))
// trigger un-reserve plugins to clean up state associated with the reserved subscription
sched.framework.RunReservePluginsUnreserve(bindingCycleCtx, state, sub, targetClusters)
sched.recordSchedulingFailure(sub, fmt.Errorf("binding rejected: %w", err), SchedulerError)
sched.handleSchedulingFailure(sub, fmt.Errorf("binding rejected: %w", err), SchedulerError)
} else {
metrics.SubscriptionScheduled(sched.framework.ProfileName(), metrics.SinceInSeconds(start))

Expand Down Expand Up @@ -386,9 +390,9 @@ func (sched *Scheduler) bind(ctx context.Context, state *framework.CycleState, s
return fmt.Errorf("bind status: %s, %v", bindStatus.Code().String(), bindStatus.Message())
}

// recordSchedulingFailure records an event for the subscription that indicates the
// handleSchedulingFailure records an event for the subscription that indicates the
// subscription has failed to schedule. Also, update the subscription condition.
func (sched *Scheduler) recordSchedulingFailure(sub *appsapi.Subscription, err error, _ string) {
func (sched *Scheduler) handleSchedulingFailure(sub *appsapi.Subscription, err error, _ string) {
klog.V(2).InfoS("Unable to schedule subscription; waiting", "subscription", klog.KObj(sub), "err", err)

msg := truncateMessage(err.Error())
Expand Down Expand Up @@ -434,7 +438,7 @@ func (sched *Scheduler) addAllEventHandlers() {
sched.lock.Lock()
defer sched.lock.Unlock()
sched.subscribersMap[klog.KObj(sub).String()] = sub.Spec.Subscribers
sched.SchedulingQueue.AddRateLimited(klog.KObj(sub).String())
sched.SchedulingQueue.Add(klog.KObj(sub).String())
},
UpdateFunc: func(oldObj, newObj interface{}) {
oldSub := oldObj.(*appsapi.Subscription)
Expand All @@ -449,15 +453,15 @@ func (sched *Scheduler) addAllEventHandlers() {
sched.lock.Lock()
defer sched.lock.Unlock()
sched.subscribersMap[klog.KObj(newSub).String()] = newSub.Spec.Subscribers
sched.SchedulingQueue.AddRateLimited(klog.KObj(newSub).String())
sched.SchedulingQueue.Add(klog.KObj(newSub).String())
},
},
})

sched.ClusternetInformerFactory.Apps().V1alpha1().FeedInventories().Informer().AddEventHandler(cache.ResourceEventHandlerFuncs{
AddFunc: func(obj interface{}) {
finv := obj.(*appsapi.FeedInventory)
sched.SchedulingQueue.AddRateLimited(klog.KObj(finv).String())
sched.SchedulingQueue.Add(klog.KObj(finv).String())
},
UpdateFunc: func(oldObj, newObj interface{}) {
oldInventory := oldObj.(*appsapi.FeedInventory)
Expand All @@ -466,7 +470,7 @@ func (sched *Scheduler) addAllEventHandlers() {
// Periodic resync will send update events for all known Inventory.
return
}
sched.SchedulingQueue.AddRateLimited(klog.KObj(newInventory).String())
sched.SchedulingQueue.Add(klog.KObj(newInventory).String())
},
})

Expand All @@ -484,7 +488,7 @@ func (sched *Scheduler) addAllEventHandlers() {
if !selector.Matches(labels.Set(newMcls.Labels)) && oldMcls != nil && !selector.Matches(labels.Set(oldMcls.Labels)) {
continue
}
sched.SchedulingQueue.AddRateLimited(key)
sched.SchedulingQueue.Add(key)
break
}
}
Expand Down