summaryrefslogtreecommitdiffstats
path: root/node-repository/src
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2021-09-28 06:04:38 +0200
committerHenning Baldersheim <balder@yahoo-inc.com>2021-09-28 06:04:38 +0200
commit66d9771b3ce3a012ecb0424ea471dbd01c91bc73 (patch)
treebc7b2372bd170088eaddfa38a4bb13e8de70f1a5 /node-repository/src
parent76c5257bc2c385fb0cea0ac46e7d4747bcff1001 (diff)
Compute capacity once for each host, instead of once per host per node.
Diffstat (limited to 'node-repository/src')
-rw-r--r--node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/NodeMover.java26
1 files changed, 22 insertions, 4 deletions
diff --git a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/NodeMover.java b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/NodeMover.java
index 54e9886d2b7..b0d69c40a86 100644
--- a/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/NodeMover.java
+++ b/node-repository/src/main/java/com/yahoo/vespa/hosted/provision/maintenance/NodeMover.java
@@ -3,6 +3,7 @@ package com.yahoo.vespa.hosted.provision.maintenance;
import com.yahoo.config.provision.ApplicationId;
import com.yahoo.config.provision.Deployer;
+import com.yahoo.config.provision.NodeResources;
import com.yahoo.config.provision.NodeType;
import com.yahoo.jdisc.Metric;
import com.yahoo.vespa.hosted.provision.Node;
@@ -12,6 +13,8 @@ import com.yahoo.vespa.hosted.provision.provisioning.HostCapacity;
import java.time.Duration;
import java.time.Instant;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Random;
import java.util.Set;
@@ -38,6 +41,19 @@ public abstract class NodeMover<MOVE> extends NodeRepositoryMaintainer {
/** Returns a suggested move for given node */
protected abstract MOVE suggestedMove(Node node, Node fromHost, Node toHost, NodeList allNodes);
+ private static class HostWithResources {
+ private final Node node;
+ private final NodeResources hostResources;
+ HostWithResources(Node node, NodeResources hostResources) {
+ this.node = node;
+ this.hostResources = hostResources;
+ }
+ boolean hasCapacity(NodeResources requested) {
+ return hostResources.satisfies(requested);
+ }
+
+ }
+
/** Find the best possible move */
protected final MOVE findBestMove(NodeList allNodes) {
HostCapacity capacity = new HostCapacity(allNodes, nodeRepository().resourcesCalculator());
@@ -48,17 +64,19 @@ public abstract class NodeMover<MOVE> extends NodeRepositoryMaintainer {
.state(Node.State.active)
.shuffle(random);
Set<Node> spares = capacity.findSpareHosts(allNodes.asList(), nodeRepository().spareCount());
+ List<HostWithResources> hostResources = new ArrayList<>();
+ allNodes.matching(nodeRepository().nodes()::canAllocateTenantNodeTo).forEach(host -> hostResources.add(new HostWithResources(host, capacity.availableCapacityOf(host))));
for (Node node : activeNodes) {
if (node.parentHostname().isEmpty()) continue;
ApplicationId applicationId = node.allocation().get().owner();
if (applicationId.instance().isTester()) continue;
if (deployedRecently(applicationId)) continue;
- for (Node toHost : allNodes.matching(nodeRepository().nodes()::canAllocateTenantNodeTo)) {
- if (toHost.hostname().equals(node.parentHostname().get())) continue;
+ for (HostWithResources toHost : hostResources) {
+ if (toHost.node.hostname().equals(node.parentHostname().get())) continue;
if (spares.contains(toHost)) continue; // Do not offer spares as a valid move as they are reserved for replacement of failed nodes
- if ( ! capacity.hasCapacity(toHost, node.resources())) continue;
+ if ( ! toHost.hasCapacity(node.resources())) continue;
- MOVE suggestedMove = suggestedMove(node, allNodes.parentOf(node).get(), toHost, allNodes);
+ MOVE suggestedMove = suggestedMove(node, allNodes.parentOf(node).get(), toHost.node, allNodes);
bestMove = bestMoveOf(bestMove, suggestedMove);
}
}