-
Notifications
You must be signed in to change notification settings - Fork 266
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
Add AIBrix Custom Autoscaling Algorithm APA #223
Merged
Merged
Changes from all commits
Commits
Show all changes
4 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 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,18 @@ | ||
apiVersion: autoscaling.aibrix.ai/v1alpha1 | ||
kind: PodAutoscaler | ||
metadata: | ||
name: podautoscaler-example-mock-llama-apa | ||
labels: | ||
app.kubernetes.io/name: aibrix | ||
app.kubernetes.io/managed-by: kustomize | ||
namespace: aibrix-system | ||
spec: | ||
scaleTargetRef: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
name: llama2-70b | ||
minReplicas: 1 | ||
maxReplicas: 10 | ||
targetMetric: "avg_prompt_throughput_toks_per_s" | ||
targetValue: "20" | ||
scalingStrategy: "APA" |
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 |
---|---|---|
|
@@ -144,10 +144,8 @@ func (r *PodAutoscalerReconciler) Reconcile(ctx context.Context, req ctrl.Reques | |
switch pa.Spec.ScalingStrategy { | ||
case autoscalingv1alpha1.HPA: | ||
return r.reconcileHPA(ctx, pa) | ||
case autoscalingv1alpha1.KPA: | ||
case autoscalingv1alpha1.KPA, autoscalingv1alpha1.APA: | ||
return r.reconcileKPA(ctx, pa) | ||
case autoscalingv1alpha1.APA: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's have some discussion here. I think we should create a new autoscaler. I understand some common parts have been implemented. We just need to figure out the long term plan. It looks good to me for short term |
||
return r.reconcileAPA(ctx, pa) | ||
default: | ||
return ctrl.Result{}, fmt.Errorf("unknown autoscaling strategy: %s", pa.Spec.ScalingStrategy) | ||
} | ||
|
@@ -315,10 +313,9 @@ func (r *PodAutoscalerReconciler) reconcileKPA(ctx context.Context, pa autoscali | |
rescale = desiredReplicas != currentReplicas | ||
} | ||
|
||
r.EventRecorder.Eventf(&pa, corev1.EventTypeNormal, "KPAAlgorithmRun", | ||
"KPA algorithm run. currentReplicas: %d, desiredReplicas: %d, rescale: %t", | ||
desiredReplicas, currentReplicas, rescale) | ||
|
||
r.EventRecorder.Eventf(&pa, corev1.EventTypeNormal, "AlgorithmRun", | ||
"%s algorithm run. currentReplicas: %d, desiredReplicas: %d, rescale: %t", | ||
pa.Spec.ScalingStrategy, currentReplicas, desiredReplicas, rescale) | ||
if rescale { | ||
|
||
if err := r.updateScale(ctx, pa.Namespace, targetGR, scale, desiredReplicas); err != nil { | ||
|
@@ -496,7 +493,7 @@ func (r *PodAutoscalerReconciler) computeReplicasForMetrics(ctx context.Context, | |
metricKey := metrics.NewNamespaceNameMetric(pa.Namespace, pa.Spec.ScaleTargetRef.Name, pa.Spec.TargetMetric) | ||
|
||
// Calculate the desired number of pods using the autoscaler logic. | ||
scaleResult := r.Autoscaler.Scale(int(originalReadyPodsCount), metricKey, currentTimestamp) | ||
scaleResult := r.Autoscaler.Scale(int(originalReadyPodsCount), metricKey, currentTimestamp, pa.Spec.ScalingStrategy) | ||
if scaleResult.ScaleValid { | ||
logger.V(4).Info("Successfully called Scale Algorithm", "scaleResult", scaleResult) | ||
return scaleResult.DesiredPodCount, metricKey.MetricName, currentTimestamp, nil | ||
|
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,79 @@ | ||
/* | ||
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 scaler | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
autoscalingv1alpha1 "github.com/aibrix/aibrix/api/autoscaling/v1alpha1" | ||
|
||
"github.com/aibrix/aibrix/pkg/controller/podautoscaler/metrics" | ||
) | ||
|
||
// TestHcpaScale tests the APA behavior. For now, APA implements HCPA algorithm. | ||
func TestAPAScale(t *testing.T) { | ||
readyPodCount := 5 | ||
kpaMetricsClient := metrics.NewKPAMetricsClient() | ||
now := time.Now() | ||
metricKey := metrics.NewNamespaceNameMetric("test_ns", "llama-70b", "ttot") | ||
_ = kpaMetricsClient.UpdateMetricIntoWindow(metricKey, now.Add(-60*time.Second), 10.0) | ||
_ = kpaMetricsClient.UpdateMetricIntoWindow(metricKey, now.Add(-50*time.Second), 11.0) | ||
_ = kpaMetricsClient.UpdateMetricIntoWindow(metricKey, now.Add(-40*time.Second), 12.0) | ||
_ = kpaMetricsClient.UpdateMetricIntoWindow(metricKey, now.Add(-30*time.Second), 13.0) | ||
_ = kpaMetricsClient.UpdateMetricIntoWindow(metricKey, now.Add(-20*time.Second), 14.0) | ||
_ = kpaMetricsClient.UpdateMetricIntoWindow(metricKey, now.Add(-10*time.Second), 100.0) | ||
|
||
kpaScaler, err := NewKpaAutoscaler(readyPodCount, | ||
&DeciderKpaSpec{ | ||
MaxScaleUpRate: 2, | ||
MaxScaleDownRate: 2, | ||
ScalingMetric: metricKey.MetricName, | ||
TargetValue: 10, | ||
TotalValue: 500, | ||
PanicThreshold: 2.0, | ||
StableWindow: 60 * time.Second, | ||
ScaleDownDelay: 10 * time.Second, | ||
ActivationScale: 2, | ||
UpFluctuationTolerance: 0.1, | ||
DownFluctuationTolerance: 0.2, | ||
}, | ||
) | ||
kpaScaler.metricsClient = kpaMetricsClient | ||
if err != nil { | ||
t.Errorf("Failed to create KpaAutoscaler: %v", err) | ||
} | ||
ticker := time.NewTicker(10 * time.Second) | ||
defer ticker.Stop() | ||
|
||
// test 1: | ||
result := kpaScaler.Scale(readyPodCount, metricKey, now, autoscalingv1alpha1.APA) | ||
// recent rapid rising metric value make scaler adapt turn on panic mode | ||
if result.DesiredPodCount != 10 { | ||
t.Errorf("result.DesiredPodCount = 10, got %d", result.DesiredPodCount) | ||
} | ||
|
||
// test 2: | ||
// 1.1 means APA won't scale up unless current usage > TargetValue * (1+1.1), i.e. 210% | ||
// In this test case with UpFluctuationTolerance = 1.1, APA will not scale up. | ||
kpaScaler.deciderSpec.UpFluctuationTolerance = 1.1 | ||
result = kpaScaler.Scale(readyPodCount, metricKey, now, autoscalingv1alpha1.APA) | ||
// recent rapid rising metric value make scaler adapt turn on panic mode | ||
if result.DesiredPodCount != int32(readyPodCount) { | ||
t.Errorf("result should remain previous replica = %d, but got %d", readyPodCount, result.DesiredPodCount) | ||
} | ||
} |
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.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's create a separate service account this time
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a commit to address this change. 2a5b389