diff options
author | Henning Baldersheim <balder@yahoo-inc.com> | 2021-09-28 13:25:56 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-09-28 13:25:56 +0200 |
commit | 3e0bb5b34c0c0868b641ab338698bd14e8b64d04 (patch) | |
tree | c1b0fa6aa23055b542b4a757e404930ba8ea87ea | |
parent | 1b40ad9707a389ec1910d7d643648f200805b304 (diff) | |
parent | 78e7203c4201dd3960d6b85b0e2d2be643c2a431 (diff) |
Merge pull request #19319 from vespa-engine/hmusum/add-micro-benchmark
Add micro benchmark of finding children of a host
-rw-r--r-- | node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeListMicroBenchmarkTest.java | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeListMicroBenchmarkTest.java b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeListMicroBenchmarkTest.java new file mode 100644 index 00000000000..a1edbec5769 --- /dev/null +++ b/node-repository/src/test/java/com/yahoo/vespa/hosted/provision/NodeListMicroBenchmarkTest.java @@ -0,0 +1,100 @@ +// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. +package com.yahoo.vespa.hosted.provision; + +import com.yahoo.config.provision.Flavor; +import com.yahoo.config.provision.NodeFlavors; +import com.yahoo.config.provision.NodeResources; +import com.yahoo.config.provision.NodeType; +import com.yahoo.config.provisioning.FlavorsConfig; +import com.yahoo.vespa.hosted.provision.node.IP; +import com.yahoo.vespa.hosted.provision.provisioning.FlavorConfigBuilder; +import com.yahoo.vespa.hosted.provision.provisioning.ProvisioningTester; +import org.junit.Test; + +import java.time.Duration; +import java.time.Instant; +import java.util.ArrayList; +import java.util.Collection; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Optional; +import java.util.Random; +import java.util.Set; +import java.util.stream.Collectors; + +/** + * @author hmusum + */ +public class NodeListMicroBenchmarkTest { + + private static final NodeFlavors nodeFlavors = createNodeFlavors(); + private final NodeResources resources0 = new NodeResources(1, 30, 20, 1.5); + private int nodeCounter = 0; + private static final int hostCount = 1000; + + @Test + public void testChildrenOf() { + List<Node> nodes = createHosts(); + + List<Node> childNodes = nodes.stream().map(host -> createNodes(host.hostname())).flatMap(Collection::stream).collect(Collectors.toList()); + nodes.addAll(childNodes); + NodeList nodeList = new NodeList(nodes, false); + + int iterations = 100000; + Random random = new Random(0); + ArrayList<Integer> indexes = new ArrayList<>(); + for (int i = 0; i < iterations; i++) { + indexes.add(random.nextInt(hostCount)); + } + + Instant start = Instant.now(); + for (int i = 0; i < iterations; i++) { + nodeList.childrenOf(nodes.get(indexes.get(i))); + } + Duration duration = Duration.between(start, Instant.now()); + System.out.println("Calling NodeList.childrenOf took " + duration + " (" + duration.toNanos() / iterations / 1000 + " microseconds per invocation)"); + } + + private List<Node> createHosts() { + List<Node> hosts = new ArrayList<>(); + for (int i = 0; i < hostCount; i++) { + hosts.add(Node.create("host" + i, IP.Config.of(Set.of("::1"), createIps(), List.of()), + "host" + i, getFlavor("host"), NodeType.host).build()); + } + return hosts; + } + + private List<Node> createNodes(String parentHostname) { + List<Node> nodes = new ArrayList<>(); + for (int i = 0; i < 10; i++) { + nodeCounter++; + Node node = Node.reserve(Set.of("::2"), "node" + nodeCounter, parentHostname, resources0, NodeType.tenant).build(); + nodes.add(node); + } + return nodes; + } + + private static NodeFlavors createNodeFlavors() { + FlavorConfigBuilder builder = new FlavorConfigBuilder(); + builder.addFlavor("host", 30, 30, 40, 3, Flavor.Type.BARE_METAL); + builder.addFlavor("node", 3, 3, 4, 3, Flavor.Type.DOCKER_CONTAINER); + FlavorsConfig flavorsConfig = builder.build(); + return new NodeFlavors(Optional.ofNullable(flavorsConfig).orElseGet(ProvisioningTester::createConfig)); + } + + private Flavor getFlavor(String name) { + return nodeFlavors.getFlavor(name).orElseThrow(() -> new RuntimeException("Unknown flavor")); + } + + private Set<String> createIps() { + // Allow 4 containers + int start = 2; + int count = 4; + Set<String> ipAddressPool = new LinkedHashSet<>(); + for (int i = start; i < (start + count); i++) { + ipAddressPool.add("::" + i); + } + return ipAddressPool; + } + +} |