-
Notifications
You must be signed in to change notification settings - Fork 4.3k
implement time limiter for binpacking #6556
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
Merged
k8s-ci-robot
merged 2 commits into
kubernetes:master
from
damikag:binpacking-time-limiter
Jun 17, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
66 changes: 66 additions & 0 deletions
66
cluster-autoscaler/processors/binpacking/combined_limiter.go
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| /* | ||
| Copyright 2023 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package binpacking | ||
|
|
||
| import ( | ||
| "k8s.io/autoscaler/cluster-autoscaler/cloudprovider" | ||
| "k8s.io/autoscaler/cluster-autoscaler/context" | ||
| "k8s.io/autoscaler/cluster-autoscaler/expander" | ||
| ) | ||
|
|
||
| // CombinedLimiter combines the outcome of multiple limiters. It will limit | ||
| // binpacking when at least one limiter meets the stop condition. | ||
| type CombinedLimiter struct { | ||
| limiters []BinpackingLimiter | ||
| } | ||
|
|
||
| // NewCombinedLimiter returns an instance of a new CombinedLimiter. | ||
| func NewCombinedLimiter(limiters []BinpackingLimiter) *CombinedLimiter { | ||
| return &CombinedLimiter{ | ||
| limiters: limiters, | ||
| } | ||
| } | ||
|
|
||
| // InitBinpacking initialises all the underline limiters. | ||
| func (l *CombinedLimiter) InitBinpacking(context *context.AutoscalingContext, nodeGroups []cloudprovider.NodeGroup) { | ||
| for _, limiter := range l.limiters { | ||
| limiter.InitBinpacking(context, nodeGroups) | ||
| } | ||
| } | ||
|
|
||
| // MarkProcessed marks the nodegroup as processed in all underline limiters. | ||
| func (l *CombinedLimiter) MarkProcessed(context *context.AutoscalingContext, nodegroupId string) { | ||
| for _, limiter := range l.limiters { | ||
| limiter.MarkProcessed(context, nodegroupId) | ||
| } | ||
| } | ||
|
|
||
| // StopBinpacking returns true if at least one of the underline limiter met the stop condition. | ||
| func (l *CombinedLimiter) StopBinpacking(context *context.AutoscalingContext, evaluatedOptions []expander.Option) bool { | ||
| stopCondition := false | ||
| for _, limiter := range l.limiters { | ||
| stopCondition = limiter.StopBinpacking(context, evaluatedOptions) || stopCondition | ||
| } | ||
| return stopCondition | ||
| } | ||
|
|
||
| // FinalizeBinpacking will call FinalizeBinpacking for all the underline limiters. | ||
| func (l *CombinedLimiter) FinalizeBinpacking(context *context.AutoscalingContext, finalOptions []expander.Option) { | ||
| for _, limiter := range l.limiters { | ||
| limiter.FinalizeBinpacking(context, finalOptions) | ||
| } | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
| /* | ||
| Copyright 2023 The Kubernetes Authors. | ||
|
|
||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| package binpacking | ||
|
|
||
| import ( | ||
| "time" | ||
|
|
||
| "k8s.io/autoscaler/cluster-autoscaler/cloudprovider" | ||
| "k8s.io/autoscaler/cluster-autoscaler/context" | ||
| "k8s.io/autoscaler/cluster-autoscaler/expander" | ||
| "k8s.io/klog/v2" | ||
| ) | ||
|
|
||
| // TimeLimiter limits binpacking based on the total time spends on binpacking. | ||
| type TimeLimiter struct { | ||
| startTime time.Time | ||
| maxBinpackingDuration time.Duration | ||
| } | ||
|
|
||
| // NewTimeLimiter returns an instance of a new TimeLimiter. | ||
| func NewTimeLimiter(maxBinpackingDuration time.Duration) *TimeLimiter { | ||
| return &TimeLimiter{ | ||
| maxBinpackingDuration: maxBinpackingDuration, | ||
| } | ||
| } | ||
|
|
||
| // InitBinpacking initialises the TimeLimiter. | ||
| func (b *TimeLimiter) InitBinpacking(context *context.AutoscalingContext, nodeGroups []cloudprovider.NodeGroup) { | ||
| b.startTime = time.Now() | ||
| } | ||
|
|
||
| // MarkProcessed marks the nodegroup as processed. | ||
| func (b *TimeLimiter) MarkProcessed(context *context.AutoscalingContext, nodegroupId string) { | ||
| } | ||
|
|
||
| // StopBinpacking returns true if the binpacking time exceeds maxBinpackingDuration. | ||
| func (b *TimeLimiter) StopBinpacking(context *context.AutoscalingContext, evaluatedOptions []expander.Option) bool { | ||
| now := time.Now() | ||
| if now.After(b.startTime.Add(b.maxBinpackingDuration)) { | ||
| klog.Infof("Binpacking is cut short after %v seconds due to exceeding maxBinpackingDuration", now.Sub(b.startTime).Seconds()) | ||
| } | ||
| return false | ||
| } | ||
|
|
||
| // FinalizeBinpacking is called to finalize the BinpackingLimiter. | ||
| func (b *TimeLimiter) FinalizeBinpacking(context *context.AutoscalingContext, finalOptions []expander.Option) { | ||
| } |
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
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.
Uh oh!
There was an error while loading. Please reload this page.