diff options
author | Valerij Fredriksen <valerijf@verizonmedia.com> | 2020-01-02 12:53:28 +0100 |
---|---|---|
committer | Valerij Fredriksen <valerijf@verizonmedia.com> | 2020-01-02 12:53:28 +0100 |
commit | dd2362306f4edb773138ad9d6e0e7c99a6b1467e (patch) | |
tree | 1d74716a200cd2b8a78b28d58b02063bf1539b7c /node-admin | |
parent | eb7c0d96095c820ff811a3cba11e3c2564acbdd9 (diff) |
Add NodeAgentContext:normalizedVcpu
Diffstat (limited to 'node-admin')
4 files changed, 30 insertions, 5 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContext.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContext.java index 28764c6a7f2..33baed7b83f 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContext.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContext.java @@ -43,6 +43,14 @@ public interface NodeAgentContext extends TaskContext { String vespaUserOnHost(); /** + * The vcpu value in NodeSpec is multiplied by the speedup factor per cpu core compared to a historical baseline + * for a particular cpu generation of the host (see flavors.def cpuSpeedup). + * + * @return node vcpu without the cpu speedup factor. + */ + double normalizedVcpu(); + + /** * This method is the inverse of {@link #pathInNodeFromPathOnHost(Path)}} * * @param pathInNode absolute path in the container diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextImpl.java index 304664e541b..7e8c5080a7e 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentContextImpl.java @@ -40,11 +40,15 @@ public class NodeAgentContextImpl implements NodeAgentContext { private final Path pathToVespaHome; private final String vespaUser; private final String vespaUserOnHost; + private final double cpuSpeedup; public NodeAgentContextImpl(NodeSpec node, Acl acl, AthenzIdentity identity, DockerNetworking dockerNetworking, ZoneApi zone, Path pathToContainerStorage, Path pathToVespaHome, - String vespaUser, String vespaUserOnHost) { + String vespaUser, String vespaUserOnHost, double cpuSpeedup) { + if (cpuSpeedup <= 0) + throw new IllegalArgumentException("cpuSpeedUp must be positive, was: " + cpuSpeedup); + this.node = Objects.requireNonNull(node); this.acl = Objects.requireNonNull(acl); this.containerName = ContainerName.fromHostname(node.hostname()); @@ -56,6 +60,7 @@ public class NodeAgentContextImpl implements NodeAgentContext { this.logPrefix = containerName.asString() + ": "; this.vespaUser = vespaUser; this.vespaUserOnHost = vespaUserOnHost; + this.cpuSpeedup = cpuSpeedup; } @Override @@ -99,6 +104,11 @@ public class NodeAgentContextImpl implements NodeAgentContext { } @Override + public double normalizedVcpu() { + return node.vcpu() / cpuSpeedup; + } + + @Override public Path pathOnHostFromPathInNode(Path pathInNode) { if (! pathInNode.isAbsolute()) throw new IllegalArgumentException("Expected an absolute path in the container, got: " + pathInNode); @@ -186,6 +196,7 @@ public class NodeAgentContextImpl implements NodeAgentContext { private String vespaUser; private String vespaUserOnHost; private FileSystem fileSystem = FileSystems.getDefault(); + private double cpuSpeedUp = 1; public Builder(NodeSpec node) { this.nodeSpecBuilder = new NodeSpec.Builder(node); @@ -258,6 +269,11 @@ public class NodeAgentContextImpl implements NodeAgentContext { return this; } + public Builder cpuSpeedUp(double cpuSpeedUp) { + this.cpuSpeedUp = cpuSpeedUp; + return this; + } + public NodeAgentContextImpl build() { return new NodeAgentContextImpl( nodeSpecBuilder.build(), @@ -288,7 +304,8 @@ public class NodeAgentContextImpl implements NodeAgentContext { Optional.ofNullable(pathToContainerStorage).orElseGet(() -> fileSystem.getPath("/home/docker")), Optional.ofNullable(pathToVespaHome).orElseGet(() -> fileSystem.getPath("/opt/vespa")), Optional.ofNullable(vespaUser).orElse("vespa"), - Optional.ofNullable(vespaUserOnHost).orElse("container_vespa")); + Optional.ofNullable(vespaUserOnHost).orElse("container_vespa"), + cpuSpeedUp); } } } diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java index 7f9dec759a6..a461b6df98c 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImpl.java @@ -353,9 +353,9 @@ public class NodeAgentImpl implements NodeAgent { .map(appId -> containerCpuCap.with(FetchVector.Dimension.APPLICATION_ID, appId.serializedForm())) .orElse(containerCpuCap) .with(FetchVector.Dimension.HOSTNAME, context.node().hostname()) - .value() * context.node().vcpu(); + .value() * context.normalizedVcpu(); - return ContainerResources.from(cpuCap, context.node().vcpu(), context.node().memoryGb()); + return ContainerResources.from(cpuCap, context.normalizedVcpu(), context.node().memoryGb()); } private boolean noCpuCap(ZoneApi zone) { diff --git a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java index 17850b0fcbd..f07c63c9f4c 100644 --- a/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java +++ b/node-admin/src/test/java/com/yahoo/vespa/hosted/node/admin/nodeagent/NodeAgentImplTest.java @@ -239,7 +239,7 @@ public class NodeAgentImplTest { nodeAgent.doConverge(firstContext); NodeAgentContext secondContext = createContext(specBuilder.diskGb(200).build()); nodeAgent.doConverge(secondContext); - NodeAgentContext thirdContext = createContext(specBuilder.vcpu(4).build()); + NodeAgentContext thirdContext = new NodeAgentContextImpl.Builder(specBuilder.vcpu(5).build()).cpuSpeedUp(1.25).build(); nodeAgent.doConverge(thirdContext); ContainerResources resourcesAfterThird = ContainerResources.from(0, 4, 16); mockGetContainer(dockerImage, resourcesAfterThird, true); |