aboutsummaryrefslogtreecommitdiffstats
path: root/node-repository
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@gmail.com>2021-03-16 18:06:52 +0100
committerJon Bratseth <bratseth@gmail.com>2021-03-16 18:06:52 +0100
commitdf059fbf28800814e8a41a116b37c6c7c3c80a44 (patch)
treecfc1702fffc1f07faf75c74d8a67065a048eb09b /node-repository
parent67d6a9328aae84b75f7824d6e5fcc3f3fa1803fc (diff)
Add direct ResourceTarget test
Diffstat (limited to 'node-repository')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTarget.java2
-rw-r--r--node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTargetTest.java75
2 files changed, 76 insertions, 1 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTarget.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTarget.java
index 0bd1598085a..35717b97cf4 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTarget.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTarget.java
@@ -86,7 +86,7 @@ public class ResourceTarget {
growthRateHeadroom = Math.min(growthRateHeadroom, 1 / fractionOfMax + 0.1);
// How much headroom is needed to handle sudden arrival of additional traffic due to another zone going down?
- double maxTrafficShiftHeadroom = 10.0; // Cap to avoid extreme sizes from a current very small load
+ double maxTrafficShiftHeadroom = 10.0; // Cap to avoid extreme sizes from a current very small share
double trafficShiftHeadroom;
if (application.status().maxReadShare() == 0) // No traffic fraction data
trafficShiftHeadroom = 2.0; // assume we currently get half of the global share of traffic
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
new file mode 100644
index 00000000000..f616e3e8b9d
--- /dev/null
+++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/autoscale/ResourceTargetTest.java
@@ -0,0 +1,75 @@
+// Copyright Verizon Media. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.vespa.hosted.provision.autoscale;
+
+import com.yahoo.config.provision.ApplicationId;
+import com.yahoo.config.provision.ClusterResources;
+import com.yahoo.config.provision.ClusterSpec;
+import com.yahoo.config.provision.NodeResources;
+import com.yahoo.test.ManualClock;
+import com.yahoo.vespa.hosted.provision.applications.Application;
+import com.yahoo.vespa.hosted.provision.applications.Cluster;
+import com.yahoo.vespa.hosted.provision.applications.Status;
+import org.junit.Test;
+
+import java.time.Duration;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Optional;
+import java.util.function.IntFunction;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * @author bratseth
+ */
+public class ResourceTargetTest {
+
+ private static final double delta = 0.001;
+
+ @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(),
+ "");
+ application = application.with(cluster);
+
+ // No current traffic: 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)),
+ application),
+ delta);
+
+ // Almost current traffic: 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)),
+ application),
+ delta);
+ }
+
+
+ /** 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) {
+ 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;
+ }
+
+}