diff options
author | Jon Bratseth <bratseth@gmail.com> | 2021-03-17 10:08:02 +0100 |
---|---|---|
committer | Jon Bratseth <bratseth@gmail.com> | 2021-03-17 10:08:02 +0100 |
commit | 26380d3b13a9524dc7cf285aeb65aea1dad0fd3e (patch) | |
tree | 2ec73e388dfc590ef96515649ea8fafe7fd657a5 /node-repository | |
parent | 4632ccb8afb788dd5cf19e6137391637bc796d61 (diff) |
Add growth headroom test
Diffstat (limited to 'node-repository')
-rw-r--r-- | node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTargetTest.java | 60 |
1 files changed, 42 insertions, 18 deletions
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTargetTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTargetTest.java index f616e3e8b9d..6b7c1790bc4 100644 --- a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTargetTest.java +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTargetTest.java @@ -29,47 +29,71 @@ public class ResourceTargetTest { @Test public void test_traffic_headroom() { Application application = Application.empty(ApplicationId.from("t1", "a1", "i1")); - Cluster cluster = new Cluster(ClusterSpec.Id.from("test"), - false, - new ClusterResources(5, 1, new NodeResources(1, 10, 100, 1)), - new ClusterResources(5, 1, new NodeResources(1, 10, 100, 1)), - Optional.empty(), - Optional.empty(), - List.of(), - ""); + Cluster cluster = cluster(new NodeResources(1, 10, 100, 1)); application = application.with(cluster); - // No current traffic: Ideal load is low but capped + // No current traffic share: Ideal load is low but capped application = application.with(new Status(0.0, 1.0)); assertEquals(0.131, ResourceTarget.idealCpuLoad(Duration.ofMinutes(10), - new ClusterTimeseries(cluster.id(), - loadSnapshots(100, t -> t == 0 ? 10000.0 : 0.0, t -> 0.0)), + timeseries(cluster,100, t -> t == 0 ? 10000.0 : 0.0, t -> 0.0), application), delta); - // Almost current traffic: Ideal load is low but capped + // Almost no current traffic share: Ideal load is low but capped application = application.with(new Status(0.0001, 1.0)); assertEquals(0.131, ResourceTarget.idealCpuLoad(Duration.ofMinutes(10), - new ClusterTimeseries(cluster.id(), - loadSnapshots(100, t -> t == 0 ? 10000.0 : 0.0, t -> 0.0)), + timeseries(cluster,100, t -> t == 0 ? 10000.0 : 0.0, t -> 0.0), application), delta); } + @Test + public void test_growth_headroom() { + Application application = Application.empty(ApplicationId.from("t1", "a1", "i1")); + Cluster cluster = cluster(new NodeResources(1, 10, 100, 1)); + application = application.with(cluster); + + // No current traffic: Ideal load is low but capped + assertEquals(0.275, + ResourceTarget.idealCpuLoad(Duration.ofMinutes(10), + timeseries(cluster,100, t -> t == 0 ? 10000.0 : 0.0, t -> 0.0), + application), + delta); + + // Almost current traffic: Ideal load is low but capped + application = application.with(new Status(0.0001, 1.0)); + assertEquals(0.04, + ResourceTarget.idealCpuLoad(Duration.ofMinutes(10), + timeseries(cluster,100, t -> t == 0 ? 10000.0 : 0.0001, t -> 0.0), + application), + delta); + } + + private Cluster cluster(NodeResources resources) { + return new Cluster(ClusterSpec.Id.from("test"), + false, + new ClusterResources(5, 1, resources), + new ClusterResources(5, 1, resources), + Optional.empty(), + Optional.empty(), + List.of(), + ""); + } /** Creates the given number of measurements, spaced 5 minutes between, using the given function */ - private List<ClusterMetricSnapshot> loadSnapshots(int measurements, - IntFunction<Double> queryRate, - IntFunction<Double> writeRate) { + private ClusterTimeseries timeseries(Cluster cluster, + int measurements, + IntFunction<Double> queryRate, + IntFunction<Double> writeRate) { List<ClusterMetricSnapshot> snapshots = new ArrayList<>(measurements); ManualClock clock = new ManualClock(); for (int i = 0; i < measurements; i++) { snapshots.add(new ClusterMetricSnapshot(clock.instant(), queryRate.apply(i), writeRate.apply(i))); clock.advance(Duration.ofMinutes(5)); } - return snapshots; + return new ClusterTimeseries(cluster.id(),snapshots); } } |