Skip to content

Commit c3bd15a

Browse files
committed
Apply review comments
Move comments to javadoc and give precedence to hard constraint checks (minimum instances, max instances) instead of aborting early due to tolerance area checks.
1 parent 09d2b52 commit c3bd15a

1 file changed

Lines changed: 19 additions & 17 deletions

File tree

src/main/java/cambio/simulator/entities/patterns/HorizontalPodAutoscalingPolicy.java

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,21 @@
66
import cambio.simulator.parsing.JsonTypeName;
77
import desmoj.core.simulator.TimeInstant;
88

9+
/**
10+
* AN implementation based on Kubernetes
11+
* <a href="https://github.com/kubernetes/kubernetes/blob/8caeec429ee1d2a9df7b7a41b21c626346b456fb/docs/design/horizontal-pod-autoscaler.md#autoscaling-algorithm">Horizontal Pod Autoscaler</a>.
12+
* <p>
13+
* By default, scale-up can only happen if there was no rescaling within the last 3 minutes. Scale-down will wait for 5
14+
* minutes from the last rescaling. Moreover, any scaling will only be made if: avg(CurrentPodsConsumption) / Target
15+
* drops below 0.9 or increases above 1.1 (10% tolerance)
16+
* <p>
17+
* TODO Maybe also include via adapter, upscaling/downscaling behavior not 100% as in Kubernetes, e.g. see
18+
* <a href="https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/autoscaling/types.go#L113">HorizontalPodAutoscalerBehavior Implementation</a>
19+
* In particular, Kubernetes mentions different holdTimes for up- and downscaling, as well as a 30s evaluation
20+
* frequency (MiSim probably evaluates every time unit. Thus, reacts faster.)
21+
*/
922
@JsonTypeName("hpa")
1023
public class HorizontalPodAutoscalingPolicy implements IAutoscalingPolicy {
11-
12-
// TODO Maybe also include via adapter, upscaling/downscaling behavior not 100% as in Kubernetes, e.g. see
13-
// HorizontalPodAutoscalerBehavior
14-
// https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/autoscaling/types.go#L113
15-
1624
private transient MultiDataPointReporter reporter = null;
1725
private double targetUtilization = 0.8;
1826
private int minInstances = 1;
@@ -26,12 +34,6 @@ public class HorizontalPodAutoscalingPolicy implements IAutoscalingPolicy {
2634

2735
@Override
2836
public void apply(Microservice owner) {
29-
//https://github.com/kubernetes/kubernetes/blob/8caeec429ee1d2a9df7b7a41b21c626346b456fb/docs/design/horizontal-pod-autoscaler.md#autoscaling-algorithm
30-
// Scale-up can only happen if there was no rescaling within the last 3 minutes. Scale-down will wait for 5
31-
// minutes from the last rescaling.
32-
// Moreover any scaling will only be made if: avg(CurrentPodsConsumption) / Target drops below 0.9 or
33-
// increases above 1.1 (10% tolerance)
34-
3537
if (reporter == null) {
3638
reporter = new MultiDataPointReporter(String.format("AS[%s]_", owner.getPlainName()), owner.getModel());
3739
}
@@ -40,9 +42,6 @@ public void apply(Microservice owner) {
4042
int currentInstanceCount = owner.getInstancesCount();
4143
double avg2Target = owner.getAverageRelativeUtilization() / targetUtilization;
4244
// Tolerance area
43-
if (avg2Target > 0.9 && avg2Target < 1.1) {
44-
return;
45-
}
4645

4746
int newInstanceCount = (int) Math.ceil(avg2Target * currentInstanceCount);
4847

@@ -57,14 +56,17 @@ public void apply(Microservice owner) {
5756
owner.setInstancesCount(maxInstances);
5857
reporter.addDatapoint("Decision", presentTime, "Despawn");
5958
reporter.addDatapoint("InstanceChange", presentTime, maxInstances - currentInstanceCount);
59+
} else if (avg2Target > 0.9 && avg2Target < 1.1) {
60+
// Tolerance area
61+
reporter.addDatapoint("Decision", presentTime, "Hold");
62+
reporter.addDatapoint("InstanceChange", presentTime, 0);
6063
} else if (avg2Target > 1 && currentInstanceCount < maxInstances) {
6164
owner.scaleToInstancesCount(newInstanceCount);
6265
lastScaleUp = presentTime;
6366
reporter.addDatapoint("Decision", presentTime, "Up");
6467
reporter.addDatapoint("InstanceChange", presentTime, newInstanceCount - currentInstanceCount);
65-
} else if (avg2Target < 1
66-
&& currentInstanceCount > minInstances
67-
&& TimeUtil.subtract(presentTime, lastScaleUp).getTimeAsDouble() > holdTime) {
68+
} else if (avg2Target < 1 && currentInstanceCount > minInstances && TimeUtil.subtract(presentTime,
69+
lastScaleUp).getTimeAsDouble() > holdTime) {
6870
owner.scaleToInstancesCount(newInstanceCount);
6971
lastScaleUp = presentTime;
7072
reporter.addDatapoint("Decision", presentTime, "Down");

0 commit comments

Comments
 (0)