diff --git a/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/ClutchRpsPIDConfig.java b/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/ClutchRpsPIDConfig.java index 54e703683..21ffb1ce7 100644 --- a/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/ClutchRpsPIDConfig.java +++ b/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/ClutchRpsPIDConfig.java @@ -23,24 +23,24 @@ public class ClutchRpsPIDConfig extends ClutchPIDConfig { - public static final ClutchRpsPIDConfig DEFAULT = new ClutchRpsPIDConfig(0.0, Tuple.of(0.3, 0.0), 0.0, 0.0, - Option.of(0.75), Option.of(0.0), Option.of(0.0), Option.of(1.0), Option.of(1.0)); + public static final ClutchRpsPIDConfig DEFAULT = new ClutchRpsPIDConfig(0.0, Tuple.of(30.0, 0.0), 0.0, 0.0, + Option.of(75.0), Option.of(0.0), Option.of(0.0), Option.of(1.0), Option.of(1.0)); /** - * Percentile of RPS data points to use as set point. + * Percentile of RPS data points to use as set point. 99.0 means P99. */ public final double setPointPercentile; /** * Percentage threshold for scaling up. Use to delay scaling up during until a threshold is reached, effectively - * reducing the number of scaling activities. + * reducing the number of scaling activities. 10.0 means 10%. */ public final double scaleUpAbovePct; /** * Percentage threshold for scaling down. Use to delay scaling down during until a threshold is reached, effectively - * reducing the number of scaling activities. + * reducing the number of scaling activities. 10.0 means 10%. */ public final double scaleDownBelowPct; diff --git a/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsClutchConfigurationSelector.java b/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsClutchConfigurationSelector.java index a22e7eb8a..0a036f0f0 100644 --- a/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsClutchConfigurationSelector.java +++ b/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsClutchConfigurationSelector.java @@ -42,7 +42,7 @@ public RpsClutchConfigurationSelector(Integer stageNumber, StageSchedulingInfo s @Override public ClutchConfiguration apply(Map sketches) { double setPoint = getSetpoint(sketches); - Tuple2 rope = getRope().map(x -> x * setPoint, y -> y * setPoint); + Tuple2 rope = getRope().map(x -> x / 100.0 * setPoint, y -> y / 100.0 * setPoint); // Gain - number of ticks within the cooldown period. This is the minimum number of times PID output will accumulate // before an action is taken. @@ -88,9 +88,9 @@ private double getSetpoint(Map sketches) { private double getSetPointPercentile() { if (customConfig != null && customConfig.getRpsConfig().isDefined()) { - return customConfig.getRpsConfig().get().getSetPointPercentile(); + return customConfig.getRpsConfig().get().getSetPointPercentile() / 100.0; } - return ClutchRpsPIDConfig.DEFAULT.getSetPointPercentile(); + return ClutchRpsPIDConfig.DEFAULT.getSetPointPercentile() / 100.0; } private Tuple2 getRope() { diff --git a/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsScaleComputer.java b/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsScaleComputer.java index 6652f337a..14bbbce89 100644 --- a/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsScaleComputer.java +++ b/mantis-server/mantis-server-worker/src/main/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsScaleComputer.java @@ -13,13 +13,15 @@ public RpsScaleComputer(ClutchRpsPIDConfig rpsConfig) { this.rpsConfig = rpsConfig; } public Double apply(ClutchConfiguration config, Long currentScale, Double delta) { - if (delta > -rpsConfig.getScaleDownBelowPct() && delta < rpsConfig.getScaleUpAbovePct()) { + double scaleUpPct = rpsConfig.getScaleUpAbovePct() / 100.0; + double scaleDownPct = rpsConfig.getScaleDownBelowPct() / 100.0; + if (delta > -scaleDownPct && delta < scaleUpPct) { return (double) currentScale; } - if (delta >= rpsConfig.getScaleUpAbovePct()) { + if (delta >= scaleUpPct) { delta = delta * rpsConfig.getScaleUpMultiplier(); } - if (delta <= -rpsConfig.getScaleDownBelowPct()) { + if (delta <= -scaleDownPct) { delta = delta * rpsConfig.getScaleDownMultiplier(); } diff --git a/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/JobAutoScalerTest.java b/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/JobAutoScalerTest.java index abef36582..988bbb9e2 100644 --- a/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/JobAutoScalerTest.java +++ b/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/JobAutoScalerTest.java @@ -360,28 +360,28 @@ public void testGetClutchConfigurationFromJson() throws Exception { String json = "{" + " \"cooldownSeconds\": 100," + " \"rpsConfig\": {" + - " \"scaleUpAbovePct\": 0.3," + + " \"scaleUpAbovePct\": 30.0," + " \"scaleUpMultiplier\": 1.5" + " }" + "}"; final JobAutoScaler jobAutoScaler = new JobAutoScaler("jobId", null, null, null); ClutchConfiguration config = jobAutoScaler.getClutchConfiguration(json).get(1); - ClutchRpsPIDConfig expected = new ClutchRpsPIDConfig(0.0, Tuple.of(0.3, 0.0), 0.0, 0.0, Option.of(0.75), Option.of(0.3), Option.of(0.0), Option.of(1.5), Option.of(1.0)); + ClutchRpsPIDConfig expected = new ClutchRpsPIDConfig(0.0, Tuple.of(30.0, 0.0), 0.0, 0.0, Option.of(75.0), Option.of(30.0), Option.of(0.0), Option.of(1.5), Option.of(1.0)); assertEquals(Option.of(100L), config.getCooldownSeconds()); assertEquals(expected, config.getRpsConfig().get()); json = "{" + " \"cooldownSeconds\": 100," + " \"rpsConfig\": {" + - " \"rope\": [0.9, 0.8]," + - " \"setPointPercentile\": 0.95," + - " \"scaleDownBelowPct\": 1.5," + + " \"rope\": [90.0, 80.0]," + + " \"setPointPercentile\": 95.0," + + " \"scaleDownBelowPct\": 150.0," + " \"scaleDownMultiplier\": 0.5" + " }" + "}"; config = jobAutoScaler.getClutchConfiguration(json).get(1); - expected = new ClutchRpsPIDConfig(0.0, Tuple.of(0.9, 0.8), 0.0, 0.0, Option.of(0.95), Option.of(0.0), Option.of(1.5), Option.of(1.0), Option.of(0.5)); + expected = new ClutchRpsPIDConfig(0.0, Tuple.of(90.0, 80.0), 0.0, 0.0, Option.of(95.0), Option.of(0.0), Option.of(150.0), Option.of(1.0), Option.of(0.5)); assertEquals(expected, config.getRpsConfig().get()); json = "{" + diff --git a/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsClutchConfigurationSelectorTest.java b/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsClutchConfigurationSelectorTest.java index 2af74238b..97c74ba20 100644 --- a/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsClutchConfigurationSelectorTest.java +++ b/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsClutchConfigurationSelectorTest.java @@ -42,7 +42,7 @@ public void testApply() { rpsSketch.update(100); Map sketches = ImmutableMap.of(Clutch.Metric.RPS, rpsSketch); - ClutchRpsPIDConfig rpsConfig = new ClutchRpsPIDConfig(0.0, Tuple.of(0.2, 0.1), 0, 0, Option.none(), Option.none(), Option.none(), Option.none(), Option.none()); + ClutchRpsPIDConfig rpsConfig = new ClutchRpsPIDConfig(0.0, Tuple.of(20.0, 10.0), 0, 0, Option.none(), Option.none(), Option.none(), Option.none(), Option.none()); io.mantisrx.server.worker.jobmaster.clutch.ClutchConfiguration customConfig = new io.mantisrx.server.worker.jobmaster.clutch.ClutchConfiguration( 1, 10, 0, Option.none(), Option.of(300L), Option.none(), Option.none(), Option.none(), Option.none(), Option.none(), Option.of(rpsConfig), Option.none()); @@ -97,6 +97,7 @@ public void testSetPointQuantile() { ClutchConfiguration config = selector.apply(sketches); assertEquals(76.0, config.getSetPoint(), 1e-10); + assertEquals(Tuple.of(22.8, 0.0), config.getRope()); } diff --git a/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsScaleComputerTest.java b/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsScaleComputerTest.java index 76a2047f0..c7420fc9d 100644 --- a/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsScaleComputerTest.java +++ b/mantis-server/mantis-server-worker/src/test/java/io/mantisrx/server/worker/jobmaster/clutch/rps/RpsScaleComputerTest.java @@ -26,7 +26,7 @@ public class RpsScaleComputerTest { @Test public void testApply() { - ClutchRpsPIDConfig rpsConfig = new ClutchRpsPIDConfig(0.0, Tuple.of(0.0, 0.0), 0.0, 0.0, Option.none(), Option.of(0.4), Option.of(0.6), Option.of(2.0), Option.of(0.5)); + ClutchRpsPIDConfig rpsConfig = new ClutchRpsPIDConfig(0.0, Tuple.of(0.0, 0.0), 0.0, 0.0, Option.none(), Option.of(40.0), Option.of(60.0), Option.of(2.0), Option.of(0.5)); RpsScaleComputer scaleComputer = new RpsScaleComputer(rpsConfig); ClutchConfiguration config = ClutchConfiguration.builder().minSize(1).maxSize(1000).build();