Skip to content

Commit 09d2b52

Browse files
committed
Apply auto formatting
1 parent fd7302c commit 09d2b52

2 files changed

Lines changed: 17 additions & 13 deletions

File tree

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@
99
@JsonTypeName("hpa")
1010
public class HorizontalPodAutoscalingPolicy implements IAutoscalingPolicy {
1111

12-
// TODO Maybe also include via adapter, upscaling/downscaling behavior not 100% as in Kubernetes, e.g. see HorizontalPodAutoscalerBehavior
12+
// TODO Maybe also include via adapter, upscaling/downscaling behavior not 100% as in Kubernetes, e.g. see
13+
// HorizontalPodAutoscalerBehavior
1314
// https://github.com/kubernetes/kubernetes/blob/master/pkg/apis/autoscaling/types.go#L113
1415

1516
private transient MultiDataPointReporter reporter = null;
@@ -26,8 +27,10 @@ public class HorizontalPodAutoscalingPolicy implements IAutoscalingPolicy {
2627
@Override
2728
public void apply(Microservice owner) {
2829
//https://github.com/kubernetes/kubernetes/blob/8caeec429ee1d2a9df7b7a41b21c626346b456fb/docs/design/horizontal-pod-autoscaler.md#autoscaling-algorithm
29-
// Scale-up can only happen if there was no rescaling within the last 3 minutes. Scale-down will wait for 5 minutes from the last rescaling.
30-
// Moreover any scaling will only be made if: avg(CurrentPodsConsumption) / Target drops below 0.9 or increases above 1.1 (10% tolerance)
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)
3134

3235
if (reporter == null) {
3336
reporter = new MultiDataPointReporter(String.format("AS[%s]_", owner.getPlainName()), owner.getModel());
@@ -49,11 +52,11 @@ public void apply(Microservice owner) {
4952
if (currentInstanceCount < minInstances) { //starts minimum instances
5053
owner.setInstancesCount(minInstances);
5154
reporter.addDatapoint("Decision", presentTime, "Spawn");
52-
reporter.addDatapoint("InstanceChange", presentTime, minInstances-currentInstanceCount);
55+
reporter.addDatapoint("InstanceChange", presentTime, minInstances - currentInstanceCount);
5356
} else if (currentInstanceCount > maxInstances) {
5457
owner.setInstancesCount(maxInstances);
5558
reporter.addDatapoint("Decision", presentTime, "Despawn");
56-
reporter.addDatapoint("InstanceChange", presentTime, maxInstances-currentInstanceCount);
59+
reporter.addDatapoint("InstanceChange", presentTime, maxInstances - currentInstanceCount);
5760
} else if (avg2Target > 1 && currentInstanceCount < maxInstances) {
5861
owner.scaleToInstancesCount(newInstanceCount);
5962
lastScaleUp = presentTime;
@@ -75,4 +78,4 @@ public void apply(Microservice owner) {
7578
owner.sendTraceNote(String.format("Changed target instance count to %d", owner.getInstancesCount()));
7679
}
7780
}
78-
}
81+
}

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,26 +39,27 @@ public void apply(Microservice owner) {
3939
if (currentInstanceCount < minInstances) { //starts minimum instances
4040
owner.setInstancesCount(minInstances);
4141
reporter.addDatapoint("Decision", presentTime, "Spawn");
42-
reporter.addDatapoint("InstanceChange", presentTime, minInstances-currentInstanceCount);
42+
reporter.addDatapoint("InstanceChange", presentTime, minInstances - currentInstanceCount);
4343
} else if (currentInstanceCount > maxInstances) {
4444
owner.setInstancesCount(maxInstances);
4545
reporter.addDatapoint("Decision", presentTime, "Despawn");
46-
reporter.addDatapoint("InstanceChange", presentTime, maxInstances-currentInstanceCount);
46+
reporter.addDatapoint("InstanceChange", presentTime, maxInstances - currentInstanceCount);
4747
} else if (avg >= upperBound && currentInstanceCount < maxInstances) {
4848
double upScalingFactor = avg / (upperBound - 0.01);
49-
int newInstanceCount = Math.min(maxInstances, (int) Math.max(1, Math.ceil(currentInstanceCount * upScalingFactor)));
49+
int newInstanceCount = Math.min(maxInstances, (int) Math.max(1,
50+
Math.ceil(currentInstanceCount * upScalingFactor)));
5051
owner.scaleToInstancesCount(newInstanceCount);
5152
lastScaleUp = presentTime;
5253
reporter.addDatapoint("Decision", presentTime, "Up");
5354
reporter.addDatapoint("InstanceChange", presentTime, newInstanceCount - currentInstanceCount);
54-
} else if (avg <= lowerBound
55-
&& currentInstanceCount > minInstances
56-
&& TimeUtil.subtract(presentTime, lastScaleUp).getTimeAsDouble() > holdTime) {
55+
} else if (avg <= lowerBound && currentInstanceCount > minInstances && TimeUtil.subtract(presentTime,
56+
lastScaleUp).getTimeAsDouble() > holdTime) {
5757
System.out.println(presentTime);
5858
System.out.println(lastScaleUp);
5959
System.out.println(holdTime);
6060
double downScaleFactor = Math.max(0.01, avg) / lowerBound;
61-
int newInstanceCount = Math.max(minInstances, (int) Math.max(1, Math.ceil(currentInstanceCount * downScaleFactor)));
61+
int newInstanceCount = Math.max(minInstances, (int) Math.max(1,
62+
Math.ceil(currentInstanceCount * downScaleFactor)));
6263
owner.scaleToInstancesCount(newInstanceCount);
6364
lastScaleUp = presentTime;
6465
reporter.addDatapoint("Decision", presentTime, "Down");

0 commit comments

Comments
 (0)