Skip to content

Commit

Permalink
Remove limiter nil checks
Browse files Browse the repository at this point in the history
  • Loading branch information
severinson committed Sep 8, 2023
1 parent 008d906 commit 81d4dce
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 27 deletions.
40 changes: 18 additions & 22 deletions internal/scheduler/constraints/constraints.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,31 +143,27 @@ func (constraints *SchedulingConstraints) CheckConstraints(
}

// Global rate limiter check.
if sctx.Limiter != nil {
tokens := sctx.Limiter.TokensAt(sctx.Started)
if tokens <= 0 {
return false, GlobalRateLimitExceededUnschedulableReason, nil
}
if sctx.Limiter.Burst() < len(gctx.JobSchedulingContexts) {
return false, GangExceedsGlobalBurstSizeUnschedulableReason, nil
}
if tokens < float64(len(gctx.JobSchedulingContexts)) {
return false, GlobalRateLimitExceededByGangUnschedulableReason, nil
}
tokens := sctx.Limiter.TokensAt(sctx.Started)
if tokens <= 0 {
return false, GlobalRateLimitExceededUnschedulableReason, nil
}
if sctx.Limiter.Burst() < len(gctx.JobSchedulingContexts) {
return false, GangExceedsGlobalBurstSizeUnschedulableReason, nil
}
if tokens < float64(len(gctx.JobSchedulingContexts)) {
return false, GlobalRateLimitExceededByGangUnschedulableReason, nil
}

// Per-queue rate limiter check.
if qctx.Limiter != nil {
tokens := qctx.Limiter.TokensAt(sctx.Started)
if tokens <= 0 {
return false, QueueRateLimitExceededUnschedulableReason, nil
}
if qctx.Limiter.Burst() < len(gctx.JobSchedulingContexts) {
return false, GangExceedsQueueBurstSizeUnschedulableReason, nil
}
if tokens < float64(len(gctx.JobSchedulingContexts)) {
return false, QueueRateLimitExceededByGangUnschedulableReason, nil
}
tokens = qctx.Limiter.TokensAt(sctx.Started)
if tokens <= 0 {
return false, QueueRateLimitExceededUnschedulableReason, nil
}
if qctx.Limiter.Burst() < len(gctx.JobSchedulingContexts) {
return false, GangExceedsQueueBurstSizeUnschedulableReason, nil
}
if tokens < float64(len(gctx.JobSchedulingContexts)) {
return false, QueueRateLimitExceededByGangUnschedulableReason, nil
}

// PriorityClassSchedulingConstraintsByPriorityClassName check.
Expand Down
7 changes: 2 additions & 5 deletions internal/scheduler/gang_scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,8 @@ func (sch *GangScheduler) Schedule(ctx context.Context, gctx *schedulercontext.G

// Update rate-limiters to account for new successfully scheduled jobs.
if ok && !gctx.AllJobsEvicted {
if sch.schedulingContext.Limiter != nil {
sch.schedulingContext.Limiter.ReserveN(sch.schedulingContext.Started, len(gctx.JobSchedulingContexts))
}
qctx := sch.schedulingContext.QueueSchedulingContexts[gctx.Queue]
if qctx != nil && qctx.Limiter != nil {
sch.schedulingContext.Limiter.ReserveN(sch.schedulingContext.Started, len(gctx.JobSchedulingContexts))
if qctx := sch.schedulingContext.QueueSchedulingContexts[gctx.Queue]; qctx != nil {
qctx.Limiter.ReserveN(sch.schedulingContext.Started, len(gctx.JobSchedulingContexts))
}
}
Expand Down

0 comments on commit 81d4dce

Please sign in to comment.