Skip to content

Commit

Permalink
Change scale of clutch rps config params to be 100.0 (#90)
Browse files Browse the repository at this point in the history
* Change scale of clutch rps config params to be 100.0

Co-authored-by: Calvin Cheung <[email protected]>
  • Loading branch information
calvin681 and calvin681 authored Feb 4, 2021
1 parent 9bbb725 commit 3470a5b
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public RpsClutchConfigurationSelector(Integer stageNumber, StageSchedulingInfo s
@Override
public ClutchConfiguration apply(Map<Clutch.Metric, UpdateDoublesSketch> sketches) {
double setPoint = getSetpoint(sketches);
Tuple2<Double, Double> rope = getRope().map(x -> x * setPoint, y -> y * setPoint);
Tuple2<Double, Double> 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.
Expand Down Expand Up @@ -88,9 +88,9 @@ private double getSetpoint(Map<Clutch.Metric, UpdateDoublesSketch> 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<Double, Double> getRope() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "{" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testApply() {
rpsSketch.update(100);
Map<Clutch.Metric, UpdateDoublesSketch> 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());

Expand Down Expand Up @@ -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());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down

0 comments on commit 3470a5b

Please sign in to comment.