-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into add-model-ai
- Loading branch information
Showing
24 changed files
with
1,146 additions
and
361 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 |
---|---|---|
@@ -1 +1,20 @@ | ||
placeholder | ||
## Autoscaling Algorithms | ||
|
||
|
||
This package provides various scaling algorithms for Pod Autoscaling, | ||
including implementations for | ||
- APA (Adaptive Pod Autoscaler), | ||
- KPA (KNative Pod Autoscaler), | ||
- HPA (Horizontal Pod Autoscaler), and more. | ||
|
||
These algorithms are designed to dynamically compute the desired number of replicas based on current pod usage and scaling specifications, | ||
optimizing resource usage and ensuring high availability and performance for workloads. | ||
|
||
`ScalingAlgorithm Interface` is a common interface for all scaling algorithms, requiring the implementation of the `ComputeTargetReplicas` method, | ||
which calculates the number of replicas based on current metrics and scaling specifications. | ||
|
||
```go | ||
type ScalingAlgorithm interface { | ||
ComputeTargetReplicas(currentPodCount float64, context ScalingContext) int32 | ||
} | ||
``` |
This file contains 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,32 @@ | ||
/* | ||
Copyright 2024 The Aibrix Team. | ||
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 algorithm | ||
|
||
import "github.com/aibrix/aibrix/pkg/controller/podautoscaler/common" | ||
|
||
type ScalingAlgorithm interface { | ||
// ComputeTargetReplicas calculates the number of replicas needed based on current metrics | ||
// and the provided scaling specifications. | ||
// | ||
// Parameters: | ||
// currentPodCount - the current number of ready pods | ||
// context - an interface that provides access to scaling parameters like target values and tolerances | ||
// | ||
// Returns: | ||
// int32 - the calculated target number of replicas | ||
ComputeTargetReplicas(currentPodCount float64, context common.ScalingContext) int32 | ||
} |
This file contains 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,54 @@ | ||
/* | ||
Copyright 2024 The Aibrix Team. | ||
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 algorithm | ||
|
||
import ( | ||
"math" | ||
|
||
"github.com/aibrix/aibrix/pkg/controller/podautoscaler/common" | ||
) | ||
|
||
type ApaScalingAlgorithm struct{} | ||
|
||
var _ ScalingAlgorithm = (*ApaScalingAlgorithm)(nil) | ||
|
||
// ComputeTargetReplicas - Apa's algorithm references and enhances the algorithm in the following paper: | ||
// Huo, Qizheng, et al. "High Concurrency Response Strategy based on Kubernetes Horizontal Pod Autoscaler." | ||
// Journal of Physics: Conference Series. Vol. 2451. No. 1. IOP Publishing, 2023. | ||
func (a *ApaScalingAlgorithm) ComputeTargetReplicas(currentPodCount float64, context common.ScalingContext) int32 { | ||
expectedUse := context.GetTargetValue() | ||
upTolerance := context.GetUpFluctuationTolerance() | ||
downTolerance := context.GetDownFluctuationTolerance() | ||
currentUsePerPod := context.GetCurrentUsePerPod() | ||
|
||
if currentUsePerPod/expectedUse > (1 + upTolerance) { | ||
maxScaleUp := math.Ceil(context.GetMaxScaleUpRate() * currentPodCount) | ||
expectedPods := int32(math.Ceil(currentPodCount * (currentUsePerPod / expectedUse))) | ||
if float64(expectedPods) > maxScaleUp { | ||
expectedPods = int32(maxScaleUp) | ||
} | ||
return expectedPods | ||
} else if currentUsePerPod/expectedUse < (1 - downTolerance) { | ||
maxScaleDown := math.Floor(currentPodCount / context.GetMaxScaleDownRate()) | ||
expectedPods := int32(math.Ceil(currentPodCount * (currentUsePerPod / expectedUse))) | ||
if float64(expectedPods) < maxScaleDown { | ||
expectedPods = int32(maxScaleDown) | ||
} | ||
return expectedPods | ||
} | ||
return int32(currentPodCount) | ||
} |
This file contains 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,29 @@ | ||
/* | ||
Copyright 2024 The Aibrix Team. | ||
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 algorithm | ||
|
||
import "github.com/aibrix/aibrix/pkg/controller/podautoscaler/common" | ||
|
||
// HpaScalingAlgorithm can be used by any scaler without customized algorithms | ||
type HpaScalingAlgorithm struct{} | ||
|
||
var _ ScalingAlgorithm = (*HpaScalingAlgorithm)(nil) | ||
|
||
func (a *HpaScalingAlgorithm) ComputeTargetReplicas(currentPodCount float64, context common.ScalingContext) int32 { | ||
// TODO: implement me! | ||
return int32(currentPodCount) | ||
} |
This file contains 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,51 @@ | ||
/* | ||
Copyright 2024 The Aibrix Team. | ||
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 algorithm | ||
|
||
import ( | ||
"math" | ||
|
||
"github.com/aibrix/aibrix/pkg/controller/podautoscaler/common" | ||
) | ||
|
||
type KpaScalingAlgorithm struct{} | ||
|
||
var _ ScalingAlgorithm = (*KpaScalingAlgorithm)(nil) | ||
|
||
func (a *KpaScalingAlgorithm) ComputeTargetReplicas(currentPodCount float64, context common.ScalingContext) int32 { | ||
expectedUse := context.GetTargetValue() | ||
upTolerance := context.GetUpFluctuationTolerance() | ||
downTolerance := context.GetDownFluctuationTolerance() | ||
currentUsePerPod := context.GetCurrentUsePerPod() | ||
|
||
if currentUsePerPod/expectedUse > (1 + upTolerance) { | ||
maxScaleUp := math.Ceil(context.GetMaxScaleUpRate() * currentPodCount) | ||
expectedPods := int32(math.Ceil(currentPodCount * (currentUsePerPod / expectedUse))) | ||
if float64(expectedPods) > maxScaleUp { | ||
expectedPods = int32(maxScaleUp) | ||
} | ||
return expectedPods | ||
} else if currentUsePerPod/expectedUse < (1 - downTolerance) { | ||
maxScaleDown := math.Floor(currentPodCount / context.GetMaxScaleDownRate()) | ||
expectedPods := int32(math.Ceil(currentPodCount * (currentUsePerPod / expectedUse))) | ||
if float64(expectedPods) < maxScaleDown { | ||
expectedPods = int32(maxScaleDown) | ||
} | ||
return expectedPods | ||
} | ||
return int32(currentPodCount) | ||
} |
This file contains 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,71 @@ | ||
/* | ||
Copyright 2024 The Aibrix Team. | ||
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 common | ||
|
||
// ScalingContext defines the generalized common that holds all necessary data for scaling calculations. | ||
type ScalingContext interface { | ||
GetTargetValue() float64 | ||
GetUpFluctuationTolerance() float64 | ||
GetDownFluctuationTolerance() float64 | ||
GetMaxScaleUpRate() float64 | ||
GetMaxScaleDownRate() float64 | ||
GetCurrentUsePerPod() float64 | ||
} | ||
|
||
// BaseScalingContext provides a base implementation of the ScalingContext interface. | ||
type BaseScalingContext struct { | ||
currentUsePerPod float64 | ||
targetValue float64 | ||
upTolerance float64 | ||
downTolerance float64 | ||
} | ||
|
||
func (b *BaseScalingContext) SetCurrentUsePerPod(value float64) { | ||
b.currentUsePerPod = value | ||
} | ||
|
||
func (b *BaseScalingContext) GetUpFluctuationTolerance() float64 { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (b *BaseScalingContext) GetDownFluctuationTolerance() float64 { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (b *BaseScalingContext) GetMaxScaleUpRate() float64 { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (b *BaseScalingContext) GetMaxScaleDownRate() float64 { | ||
//TODO implement me | ||
panic("implement me") | ||
} | ||
|
||
func (b *BaseScalingContext) GetCurrentUsePerPod() float64 { | ||
return b.currentUsePerPod | ||
} | ||
|
||
func (b *BaseScalingContext) GetTargetValue() float64 { | ||
return b.targetValue | ||
} | ||
|
||
func (b *BaseScalingContext) GetScalingTolerance() (up float64, down float64) { | ||
return b.upTolerance, b.downTolerance | ||
} |
This file contains 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
Oops, something went wrong.