Search in sources :

Example 56 with INimbus

use of org.apache.storm.scheduler.INimbus in project storm by apache.

the class TestDefaultResourceAwareStrategy method testDefaultResourceAwareStrategyWithSettingAckerExecutors.

/**
 * test if the scheduling logic for the DefaultResourceAwareStrategy is correct
 * when topology.acker.executors is set.
 *
 * If yes, topology.acker.executors.per.worker setting will be ignored and calculated as
 * Math.ceil(topology.acker.executors / estimate num of workers) by Nimbus
 */
@ParameterizedTest
@ValueSource(ints = { -1, 0, 2, 300 })
public void testDefaultResourceAwareStrategyWithSettingAckerExecutors(int numOfAckersPerWorker) throws InvalidTopologyException {
    int spoutParallelism = 1;
    int boltParallelism = 2;
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout", new TestSpout(), spoutParallelism);
    builder.setBolt("bolt-1", new TestBolt(), boltParallelism).shuffleGrouping("spout");
    builder.setBolt("bolt-2", new TestBolt(), boltParallelism).shuffleGrouping("bolt-1");
    builder.setBolt("bolt-3", new TestBolt(), boltParallelism).shuffleGrouping("bolt-2");
    String topoName = "testTopology";
    StormTopology stormToplogy = builder.createTopology();
    INimbus iNimbus = new INimbusTest();
    Map<String, SupervisorDetails> supMap = genSupervisors(4, 4, 200, 2000);
    Config conf = createClusterConfig(50, 450, 0, null);
    conf.put(Config.TOPOLOGY_PRIORITY, 0);
    conf.put(Config.TOPOLOGY_NAME, topoName);
    conf.put(Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB, 2000);
    conf.put(Config.TOPOLOGY_SUBMITTER_USER, "user");
    conf.put(Config.TOPOLOGY_ACKER_EXECUTORS, 4);
    conf.put(Config.TOPOLOGY_RAS_ACKER_EXECUTORS_PER_WORKER, numOfAckersPerWorker);
    if (numOfAckersPerWorker == -1) {
    // Leave topology.acker.executors.per.worker unset
    } else {
        conf.put(Config.TOPOLOGY_RAS_ACKER_EXECUTORS_PER_WORKER, numOfAckersPerWorker);
    }
    int estimatedNumWorker = ServerUtils.getEstimatedWorkerCountForRasTopo(conf, stormToplogy);
    Nimbus.setUpAckerExecutorConfigs(topoName, conf, conf, estimatedNumWorker);
    conf.put(Config.TOPOLOGY_ACKER_RESOURCES_ONHEAP_MEMORY_MB, 250);
    conf.put(Config.TOPOLOGY_ACKER_CPU_PCORE_PERCENT, 50);
    TopologyDetails topo = new TopologyDetails("testTopology-id", conf, stormToplogy, 0, genExecsAndComps(StormCommon.systemTopology(conf, stormToplogy)), CURRENT_TIME, "user");
    Topologies topologies = new Topologies(topo);
    Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, conf);
    scheduler = new ResourceAwareScheduler();
    scheduler.prepare(conf, new StormMetricsRegistry());
    scheduler.schedule(topologies, cluster);
    // Sorted execs: [[6, 6], [2, 2], [4, 4], [5, 5], [1, 1], [3, 3], [0, 0], [8, 8], [7, 7], [10, 10], [9, 9]]
    // Ackers: [[8, 8], [7, 7], [10, 10], [9, 9]]
    HashSet<HashSet<ExecutorDetails>> expectedScheduling = new HashSet<>();
    expectedScheduling.add(new HashSet<>(Arrays.asList(// bolt-3
    new ExecutorDetails(6, 6), // bolt-1
    new ExecutorDetails(2, 2), // acker
    new ExecutorDetails(7, 7), // acker
    new ExecutorDetails(8, 8))));
    expectedScheduling.add(new HashSet<>(Arrays.asList(// bolt-3
    new ExecutorDetails(5, 5), // bolt-2
    new ExecutorDetails(4, 4), // acker
    new ExecutorDetails(9, 9), // acker
    new ExecutorDetails(10, 10))));
    expectedScheduling.add(new HashSet<>(Arrays.asList(// spout
    new ExecutorDetails(0, 0), // bolt-2
    new ExecutorDetails(3, 3), // bolt-1
    new ExecutorDetails(1, 1))));
    HashSet<HashSet<ExecutorDetails>> foundScheduling = new HashSet<>();
    SchedulerAssignment assignment = cluster.getAssignmentById("testTopology-id");
    for (Collection<ExecutorDetails> execs : assignment.getSlotToExecutors().values()) {
        foundScheduling.add(new HashSet<>(execs));
    }
    Assert.assertEquals(expectedScheduling, foundScheduling);
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) ResourceAwareScheduler(org.apache.storm.scheduler.resource.ResourceAwareScheduler) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) HashSet(java.util.HashSet) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 57 with INimbus

use of org.apache.storm.scheduler.INimbus in project storm by apache.

the class TestDefaultResourceAwareStrategy method testMultipleRacksWithFavoritism.

/**
 * Test whether strategy will choose correct rack
 */
@Test
public void testMultipleRacksWithFavoritism() {
    final Map<String, SupervisorDetails> supMap = new HashMap<>();
    final Map<String, SupervisorDetails> supMapRack0 = genSupervisors(10, 4, 0, 400, 8000);
    // generate another rack of supervisors with less resources
    final Map<String, SupervisorDetails> supMapRack1 = genSupervisors(10, 4, 10, 200, 4000);
    // generate some supervisors that are depleted of one resource
    final Map<String, SupervisorDetails> supMapRack2 = genSupervisors(10, 4, 20, 0, 8000);
    // generate some that has alot of memory but little of cpu
    final Map<String, SupervisorDetails> supMapRack3 = genSupervisors(10, 4, 30, 10, 8000 * 2 + 4000);
    // generate some that has alot of cpu but little of memory
    final Map<String, SupervisorDetails> supMapRack4 = genSupervisors(10, 4, 40, 400 + 200 + 10, 1000);
    supMap.putAll(supMapRack0);
    supMap.putAll(supMapRack1);
    supMap.putAll(supMapRack2);
    supMap.putAll(supMapRack3);
    supMap.putAll(supMapRack4);
    Config config = createClusterConfig(100, 500, 500, null);
    config.put(Config.TOPOLOGY_WORKER_MAX_HEAP_SIZE_MB, Double.MAX_VALUE);
    INimbus iNimbus = new INimbusTest();
    // create test DNSToSwitchMapping plugin
    DNSToSwitchMapping TestNetworkTopographyPlugin = new TestDNSToSwitchMapping(supMapRack0, supMapRack1, supMapRack2, supMapRack3, supMapRack4);
    Config t1Conf = new Config();
    t1Conf.putAll(config);
    final List<String> t1FavoredHostNames = Arrays.asList("host-41", "host-42", "host-43");
    t1Conf.put(Config.TOPOLOGY_SCHEDULER_FAVORED_NODES, t1FavoredHostNames);
    final List<String> t1UnfavoredHostIds = Arrays.asList("host-1", "host-2", "host-3");
    t1Conf.put(Config.TOPOLOGY_SCHEDULER_UNFAVORED_NODES, t1UnfavoredHostIds);
    // generate topologies
    TopologyDetails topo1 = genTopology("topo-1", t1Conf, 8, 0, 2, 0, CURRENT_TIME - 2, 10, "user");
    Config t2Conf = new Config();
    t2Conf.putAll(config);
    t2Conf.put(Config.TOPOLOGY_SCHEDULER_FAVORED_NODES, Arrays.asList("host-31", "host-32", "host-33"));
    t2Conf.put(Config.TOPOLOGY_SCHEDULER_UNFAVORED_NODES, Arrays.asList("host-11", "host-12", "host-13"));
    TopologyDetails topo2 = genTopology("topo-2", t2Conf, 8, 0, 2, 0, CURRENT_TIME - 2, 10, "user");
    Topologies topologies = new Topologies(topo1, topo2);
    Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config);
    List<String> supHostnames = new LinkedList<>();
    for (SupervisorDetails sup : supMap.values()) {
        supHostnames.add(sup.getHost());
    }
    Map<String, List<String>> rackToNodes = new HashMap<>();
    Map<String, String> resolvedSuperVisors = TestNetworkTopographyPlugin.resolve(supHostnames);
    for (Map.Entry<String, String> entry : resolvedSuperVisors.entrySet()) {
        String hostName = entry.getKey();
        String rack = entry.getValue();
        List<String> nodesForRack = rackToNodes.get(rack);
        if (nodesForRack == null) {
            nodesForRack = new ArrayList<>();
            rackToNodes.put(rack, nodesForRack);
        }
        nodesForRack.add(hostName);
    }
    cluster.setNetworkTopography(rackToNodes);
    DefaultResourceAwareStrategyOld rs = new DefaultResourceAwareStrategyOld();
    rs.prepareForScheduling(cluster, topo1);
    INodeSorter nodeSorter = new NodeSorterHostProximity(cluster, topo1, BaseResourceAwareStrategy.NodeSortType.DEFAULT_RAS);
    nodeSorter.prepare(null);
    Iterable<ObjectResourcesItem> sortedRacks = nodeSorter.getSortedRacks();
    Iterator<ObjectResourcesItem> it = sortedRacks.iterator();
    // Ranked first since rack-0 has the most balanced set of resources
    Assert.assertEquals("rack-0 should be ordered first", "rack-0", it.next().id);
    // Ranked second since rack-1 has a balanced set of resources but less than rack-0
    Assert.assertEquals("rack-1 should be ordered second", "rack-1", it.next().id);
    // Ranked third since rack-4 has a lot of cpu but not a lot of memory
    Assert.assertEquals("rack-4 should be ordered third", "rack-4", it.next().id);
    // Ranked fourth since rack-3 has alot of memory but not cpu
    Assert.assertEquals("rack-3 should be ordered fourth", "rack-3", it.next().id);
    // Ranked last since rack-2 has not cpu resources
    Assert.assertEquals("rack-2 should be ordered fifth", "rack-2", it.next().id);
    SchedulingResult schedulingResult = rs.schedule(cluster, topo1);
    assert (schedulingResult.isSuccess());
    SchedulerAssignment assignment = cluster.getAssignmentById(topo1.getId());
    for (WorkerSlot ws : assignment.getSlotToExecutors().keySet()) {
        String hostName = rs.idToNode(ws.getNodeId()).getHostname();
        String rackId = resolvedSuperVisors.get(hostName);
        Assert.assertTrue(ws + " is neither on a favored node " + t1FavoredHostNames + " nor the highest priority rack (rack-0)", t1FavoredHostNames.contains(hostName) || "rack-0".equals(rackId));
        Assert.assertFalse(ws + " is a part of an unfavored node " + t1UnfavoredHostIds, t1UnfavoredHostIds.contains(hostName));
    }
    Assert.assertEquals("All executors in topo-1 scheduled", 0, cluster.getUnassignedExecutors(topo1).size());
    // Test if topology is already partially scheduled on one rack
    Iterator<ExecutorDetails> executorIterator = topo2.getExecutors().iterator();
    List<String> nodeHostnames = rackToNodes.get("rack-1");
    for (int i = 0; i < topo2.getExecutors().size() / 2; i++) {
        String nodeHostname = nodeHostnames.get(i % nodeHostnames.size());
        RasNode node = rs.hostnameToNodes(nodeHostname).get(0);
        WorkerSlot targetSlot = node.getFreeSlots().iterator().next();
        ExecutorDetails targetExec = executorIterator.next();
        // to keep track of free slots
        node.assign(targetSlot, topo2, Arrays.asList(targetExec));
    }
    rs = new DefaultResourceAwareStrategyOld();
    // schedule topo2
    schedulingResult = rs.schedule(cluster, topo2);
    assert (schedulingResult.isSuccess());
    assignment = cluster.getAssignmentById(topo2.getId());
    for (WorkerSlot ws : assignment.getSlotToExecutors().keySet()) {
        // make sure all workers on scheduled in rack-1
        // The favored nodes would have put it on a different rack, but because that rack does not have free space to run the
        // topology it falls back to this rack
        Assert.assertEquals("assert worker scheduled on rack-1", "rack-1", resolvedSuperVisors.get(rs.idToNode(ws.getNodeId()).getHostname()));
    }
    Assert.assertEquals("All executors in topo-2 scheduled", 0, cluster.getUnassignedExecutors(topo2).size());
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) HashMap(java.util.HashMap) Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) NodeSorterHostProximity(org.apache.storm.scheduler.resource.strategies.scheduling.sorter.NodeSorterHostProximity) SchedulingResult(org.apache.storm.scheduler.resource.SchedulingResult) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) INodeSorter(org.apache.storm.scheduler.resource.strategies.scheduling.sorter.INodeSorter) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) RasNode(org.apache.storm.scheduler.resource.RasNode) DNSToSwitchMapping(org.apache.storm.networktopography.DNSToSwitchMapping) Topologies(org.apache.storm.scheduler.Topologies) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) LinkedList(java.util.LinkedList) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) Map(java.util.Map) HashMap(java.util.HashMap) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 58 with INimbus

use of org.apache.storm.scheduler.INimbus in project storm by apache.

the class TestResourceAwareScheduler method testScheduleResilience.

@Test
public void testScheduleResilience() {
    INimbus iNimbus = new INimbusTest();
    Map<String, SupervisorDetails> supMap = genSupervisors(2, 2, 400, 2000);
    TopologyBuilder builder1 = new TopologyBuilder();
    builder1.setSpout("wordSpout1", new TestWordSpout(), 3);
    StormTopology stormTopology1 = builder1.createTopology();
    Config config1 = new Config();
    config1.putAll(defaultTopologyConf);
    Map<ExecutorDetails, String> executorMap1 = genExecsAndComps(stormTopology1);
    TopologyDetails topology1 = new TopologyDetails("topology1", config1, stormTopology1, 3, executorMap1, 0, "user");
    TopologyBuilder builder2 = new TopologyBuilder();
    builder2.setSpout("wordSpout2", new TestWordSpout(), 2);
    StormTopology stormTopology2 = builder2.createTopology();
    Config config2 = new Config();
    config2.putAll(defaultTopologyConf);
    // memory requirement is large enough so that two executors can not be fully assigned to one node
    config2.put(Config.TOPOLOGY_COMPONENT_RESOURCES_ONHEAP_MEMORY_MB, 1280.0);
    Map<ExecutorDetails, String> executorMap2 = genExecsAndComps(stormTopology2);
    TopologyDetails topology2 = new TopologyDetails("topology2", config2, stormTopology2, 2, executorMap2, 0, "user");
    // Test1: When a worker fails, RAS does not alter existing assignments on healthy workers
    scheduler = new ResourceAwareScheduler();
    Topologies topologies = new Topologies(topology2);
    Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config1);
    scheduler.prepare(config1, new StormMetricsRegistry());
    scheduler.schedule(topologies, cluster);
    SchedulerAssignment assignment = cluster.getAssignmentById(topology2.getId());
    // pick a worker to mock as failed
    WorkerSlot failedWorker = new ArrayList<>(assignment.getSlots()).get(0);
    Map<ExecutorDetails, WorkerSlot> executorToSlot = assignment.getExecutorToSlot();
    List<ExecutorDetails> failedExecutors = new ArrayList<>();
    for (Map.Entry<ExecutorDetails, WorkerSlot> entry : executorToSlot.entrySet()) {
        if (entry.getValue().equals(failedWorker)) {
            failedExecutors.add(entry.getKey());
        }
    }
    for (ExecutorDetails executor : failedExecutors) {
        // remove executor details assigned to the failed worker
        executorToSlot.remove(executor);
    }
    Map<ExecutorDetails, WorkerSlot> copyOfOldMapping = new HashMap<>(executorToSlot);
    Set<ExecutorDetails> healthyExecutors = copyOfOldMapping.keySet();
    scheduler.schedule(topologies, cluster);
    SchedulerAssignment newAssignment = cluster.getAssignmentById(topology2.getId());
    Map<ExecutorDetails, WorkerSlot> newExecutorToSlot = newAssignment.getExecutorToSlot();
    for (ExecutorDetails executor : healthyExecutors) {
        assertEquals(copyOfOldMapping.get(executor), newExecutorToSlot.get(executor));
    }
    assertFalse(cluster.needsSchedulingRas(topology2));
    assertTrue(cluster.getStatusMap().get(topology2.getId()).startsWith("Running - Fully Scheduled by DefaultResourceAwareStrategy"));
    // end of Test1
    // Test2: When a supervisor fails, RAS does not alter existing assignments
    executorToSlot = new HashMap<>();
    executorToSlot.put(new ExecutorDetails(0, 0), new WorkerSlot("r000s000", 0));
    executorToSlot.put(new ExecutorDetails(1, 1), new WorkerSlot("r000s000", 1));
    executorToSlot.put(new ExecutorDetails(2, 2), new WorkerSlot("r000s001", 1));
    Map<String, SchedulerAssignment> existingAssignments = new HashMap<>();
    assignment = new SchedulerAssignmentImpl(topology1.getId(), executorToSlot, null, null);
    existingAssignments.put(topology1.getId(), assignment);
    copyOfOldMapping = new HashMap<>(executorToSlot);
    Set<ExecutorDetails> existingExecutors = copyOfOldMapping.keySet();
    Map<String, SupervisorDetails> supMap1 = new HashMap<>(supMap);
    // mock the supervisor r000s000 as a failed supervisor
    supMap1.remove("r000s000");
    topologies = new Topologies(topology1);
    Cluster cluster1 = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap1, existingAssignments, topologies, config1);
    scheduler.schedule(topologies, cluster1);
    newAssignment = cluster1.getAssignmentById(topology1.getId());
    newExecutorToSlot = newAssignment.getExecutorToSlot();
    for (ExecutorDetails executor : existingExecutors) {
        assertEquals(copyOfOldMapping.get(executor), newExecutorToSlot.get(executor));
    }
    assertEquals("Fully Scheduled", cluster1.getStatusMap().get(topology1.getId()));
    // end of Test2
    // Test3: When a supervisor and a worker on it fails, RAS does not alter existing assignments
    executorToSlot = new HashMap<>();
    // the worker to orphan
    executorToSlot.put(new ExecutorDetails(0, 0), new WorkerSlot("r000s000", 1));
    // the worker that fails
    executorToSlot.put(new ExecutorDetails(1, 1), new WorkerSlot("r000s000", 2));
    // the healthy worker
    executorToSlot.put(new ExecutorDetails(2, 2), new WorkerSlot("r000s001", 1));
    existingAssignments = new HashMap<>();
    assignment = new SchedulerAssignmentImpl(topology1.getId(), executorToSlot, null, null);
    existingAssignments.put(topology1.getId(), assignment);
    // delete one worker of r000s000 (failed) from topo1 assignment to enable actual schedule for testing
    executorToSlot.remove(new ExecutorDetails(1, 1));
    copyOfOldMapping = new HashMap<>(executorToSlot);
    // namely the two eds on the orphaned worker and the healthy worker
    existingExecutors = copyOfOldMapping.keySet();
    supMap1 = new HashMap<>(supMap);
    // mock the supervisor r000s000 as a failed supervisor
    supMap1.remove("r000s000");
    topologies = new Topologies(topology1);
    cluster1 = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap1, existingAssignments, topologies, config1);
    scheduler.schedule(topologies, cluster1);
    newAssignment = cluster1.getAssignmentById(topology1.getId());
    newExecutorToSlot = newAssignment.getExecutorToSlot();
    for (ExecutorDetails executor : existingExecutors) {
        assertEquals(copyOfOldMapping.get(executor), newExecutorToSlot.get(executor));
    }
    assertFalse(cluster1.needsSchedulingRas(topology1));
    assertEquals("Fully Scheduled", cluster1.getStatusMap().get(topology1.getId()));
    // end of Test3
    // Test4: Scheduling a new topology does not disturb other assignments unnecessarily
    topologies = new Topologies(topology1);
    cluster1 = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config1);
    scheduler.schedule(topologies, cluster1);
    assignment = cluster1.getAssignmentById(topology1.getId());
    executorToSlot = assignment.getExecutorToSlot();
    copyOfOldMapping = new HashMap<>(executorToSlot);
    topologies = addTopologies(topologies, topology2);
    cluster1 = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config1);
    scheduler.schedule(topologies, cluster1);
    newAssignment = cluster1.getAssignmentById(topology1.getId());
    newExecutorToSlot = newAssignment.getExecutorToSlot();
    for (ExecutorDetails executor : copyOfOldMapping.keySet()) {
        assertEquals(copyOfOldMapping.get(executor), newExecutorToSlot.get(executor));
    }
    assertFalse(cluster1.needsSchedulingRas(topology1));
    assertFalse(cluster1.needsSchedulingRas(topology2));
    String expectedStatusPrefix = "Running - Fully Scheduled by DefaultResourceAwareStrategy";
    assertTrue(cluster1.getStatusMap().get(topology1.getId()).startsWith(expectedStatusPrefix));
    assertTrue(cluster1.getStatusMap().get(topology2.getId()).startsWith(expectedStatusPrefix));
}
Also used : ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) HashMap(java.util.HashMap) DaemonConfig(org.apache.storm.DaemonConfig) Config(org.apache.storm.Config) StormTopology(org.apache.storm.generated.StormTopology) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) ArrayList(java.util.ArrayList) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) SchedulerAssignmentImpl(org.apache.storm.scheduler.SchedulerAssignmentImpl) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) TestWordSpout(org.apache.storm.testing.TestWordSpout) Map(java.util.Map) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Test(org.junit.jupiter.api.Test) PerformanceTest(org.apache.storm.testing.PerformanceTest)

Example 59 with INimbus

use of org.apache.storm.scheduler.INimbus in project storm by apache.

the class TestResourceAwareScheduler method testNodeFreeSlot.

/**
 * test if free slots on nodes work correctly
 */
@Test
public void testNodeFreeSlot() {
    INimbus iNimbus = new INimbusTest();
    Map<String, SupervisorDetails> supMap = genSupervisors(4, 4, 100, 1000);
    Config config = createClusterConfig(100, 500, 500, null);
    Topologies topologies = new Topologies(genTopology("topo-1", config, 1, 0, 2, 0, currentTime - 2, 29, "user"), genTopology("topo-2", config, 1, 0, 2, 0, currentTime - 2, 10, "user"));
    Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config);
    scheduler = new ResourceAwareScheduler();
    scheduler.prepare(config, new StormMetricsRegistry());
    scheduler.schedule(topologies, cluster);
    Map<String, RasNode> nodes = RasNodes.getAllNodesFrom(cluster);
    for (SchedulerAssignment assignment : cluster.getAssignments().values()) {
        for (Entry<WorkerSlot, WorkerResources> entry : new HashMap<>(assignment.getScheduledResources()).entrySet()) {
            WorkerSlot ws = entry.getKey();
            WorkerResources wr = entry.getValue();
            double memoryBefore = nodes.get(ws.getNodeId()).getAvailableMemoryResources();
            double cpuBefore = nodes.get(ws.getNodeId()).getAvailableCpuResources();
            double memoryUsedByWorker = wr.get_mem_on_heap() + wr.get_mem_off_heap();
            assertEquals("Check if memory used by worker is calculated correctly", 1000.0, memoryUsedByWorker, 0.001);
            double cpuUsedByWorker = wr.get_cpu();
            assertEquals("Check if CPU used by worker is calculated correctly", 100.0, cpuUsedByWorker, 0.001);
            nodes.get(ws.getNodeId()).free(ws);
            double memoryAfter = nodes.get(ws.getNodeId()).getAvailableMemoryResources();
            double cpuAfter = nodes.get(ws.getNodeId()).getAvailableCpuResources();
            assertEquals("Check if free correctly frees amount of memory", memoryBefore + memoryUsedByWorker, memoryAfter, 0.001);
            assertEquals("Check if free correctly frees amount of memory", cpuBefore + cpuUsedByWorker, cpuAfter, 0.001);
            assertFalse("Check if worker was removed from assignments", assignment.getSlotToExecutors().containsKey(ws));
        }
    }
}
Also used : WorkerResources(org.apache.storm.generated.WorkerResources) DaemonConfig(org.apache.storm.DaemonConfig) Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) Test(org.junit.jupiter.api.Test) PerformanceTest(org.apache.storm.testing.PerformanceTest)

Example 60 with INimbus

use of org.apache.storm.scheduler.INimbus in project storm by apache.

the class TestResourceAwareScheduler method testLargeTopologiesCommon.

public void testLargeTopologiesCommon(final String strategy, final boolean includeGpu, final int multiplier) {
    INimbus iNimbus = new INimbusTest();
    Map<String, SupervisorDetails> supMap = genSupervisorsWithRacks(25 * multiplier, 40, 66, 3 * multiplier, 0, 4700, 226200, new HashMap<>());
    if (includeGpu) {
        HashMap<String, Double> extraResources = new HashMap<>();
        extraResources.put("my.gpu", 1.0);
        supMap.putAll(genSupervisorsWithRacks(3 * multiplier, 40, 66, 0, 0, 4700, 226200, extraResources));
    }
    Config config = new Config();
    config.putAll(createClusterConfig(88, 775, 25, null));
    config.put(Config.TOPOLOGY_SCHEDULER_STRATEGY, strategy);
    scheduler = new ResourceAwareScheduler();
    Map<String, TopologyDetails> topologyDetailsMap = new HashMap<>();
    for (int i = 0; i < 11 * multiplier; i++) {
        TopologyDetails td = genTopology(String.format("topology-%05d", i), config, 5, 40, 30, 114, 0, 0, "user", 8192);
        topologyDetailsMap.put(td.getId(), td);
    }
    if (includeGpu) {
        for (int i = 0; i < multiplier; i++) {
            TopologyBuilder builder = topologyBuilder(5, 40, 30, 114);
            builder.setBolt("gpu-bolt", new TestBolt(), 40).addResource("my.gpu", 1.0).shuffleGrouping("spout-0");
            TopologyDetails td = topoToTopologyDetails(String.format("topology-gpu-%05d", i), config, builder.createTopology(), 0, 0, "user", 8192);
            topologyDetailsMap.put(td.getId(), td);
        }
    }
    Topologies topologies = new Topologies(topologyDetailsMap);
    Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config);
    long startTime = Time.currentTimeMillis();
    scheduler.prepare(config, new StormMetricsRegistry());
    scheduler.schedule(topologies, cluster);
    long schedulingDuration = Time.currentTimeMillis() - startTime;
    LOG.info("Scheduling took " + schedulingDuration + " ms");
    LOG.info("HAS {} SLOTS USED", cluster.getUsedSlots().size());
    Map<String, SchedulerAssignment> assignments = new TreeMap<>(cluster.getAssignments());
    for (Entry<String, SchedulerAssignment> entry : assignments.entrySet()) {
        SchedulerAssignment sa = entry.getValue();
        Map<String, AtomicLong> slotsPerRack = new TreeMap<>();
        for (WorkerSlot slot : sa.getSlots()) {
            String nodeId = slot.getNodeId();
            String rack = supervisorIdToRackName(nodeId);
            slotsPerRack.computeIfAbsent(rack, (r) -> new AtomicLong(0)).incrementAndGet();
        }
        LOG.info("{} => {}", entry.getKey(), slotsPerRack);
    }
}
Also used : Arrays(java.util.Arrays) ConstraintSolverStrategy(org.apache.storm.scheduler.resource.strategies.scheduling.ConstraintSolverStrategy) DefaultResourceAwareStrategy(org.apache.storm.scheduler.resource.strategies.scheduling.DefaultResourceAwareStrategy) LoggerFactory(org.slf4j.LoggerFactory) INimbus(org.apache.storm.scheduler.INimbus) DaemonConfig(org.apache.storm.DaemonConfig) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) Map(java.util.Map) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) After(org.junit.After) Duration(java.time.Duration) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) TestWordSpout(org.apache.storm.testing.TestWordSpout) SchedulerAssignmentImpl(org.apache.storm.scheduler.SchedulerAssignmentImpl) DisallowedStrategyException(org.apache.storm.utils.DisallowedStrategyException) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment) Collection(java.util.Collection) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) Set(java.util.Set) NormalizedResources(org.apache.storm.scheduler.resource.normalization.NormalizedResources) TestWordCounter(org.apache.storm.testing.TestWordCounter) Time(org.apache.storm.utils.Time) Test(org.junit.jupiter.api.Test) WorkerResources(org.apache.storm.generated.WorkerResources) List(java.util.List) ConfigUtils(org.apache.storm.utils.ConfigUtils) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) Entry(java.util.Map.Entry) Config(org.apache.storm.Config) ExecutorDetails(org.apache.storm.scheduler.ExecutorDetails) IScheduler(org.apache.storm.scheduler.IScheduler) HashMap(java.util.HashMap) BaseResourceAwareStrategy(org.apache.storm.scheduler.resource.strategies.scheduling.BaseResourceAwareStrategy) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Topologies(org.apache.storm.scheduler.Topologies) ReflectionUtils(org.apache.storm.utils.ReflectionUtils) StormTopology(org.apache.storm.generated.StormTopology) DefaultResourceAwareStrategyOld(org.apache.storm.scheduler.resource.strategies.scheduling.DefaultResourceAwareStrategyOld) LinkedList(java.util.LinkedList) ConfigValidation(org.apache.storm.validation.ConfigValidation) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) GenericResourceAwareStrategy(org.apache.storm.scheduler.resource.strategies.scheduling.GenericResourceAwareStrategy) Logger(org.slf4j.Logger) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) Utils(org.apache.storm.utils.Utils) PerformanceTest(org.apache.storm.testing.PerformanceTest) Cluster(org.apache.storm.scheduler.Cluster) AtomicLong(java.util.concurrent.atomic.AtomicLong) TreeMap(java.util.TreeMap) Assertions(org.junit.jupiter.api.Assertions) Assert(org.junit.Assert) Collections(java.util.Collections) HashMap(java.util.HashMap) TopologyBuilder(org.apache.storm.topology.TopologyBuilder) DaemonConfig(org.apache.storm.DaemonConfig) Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) WorkerSlot(org.apache.storm.scheduler.WorkerSlot) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) TreeMap(java.util.TreeMap) TopologyDetails(org.apache.storm.scheduler.TopologyDetails) AtomicLong(java.util.concurrent.atomic.AtomicLong) SchedulerAssignment(org.apache.storm.scheduler.SchedulerAssignment)

Aggregations

INimbus (org.apache.storm.scheduler.INimbus)74 Cluster (org.apache.storm.scheduler.Cluster)72 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)72 Config (org.apache.storm.Config)71 Topologies (org.apache.storm.scheduler.Topologies)71 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)61 StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)60 ResourceMetrics (org.apache.storm.scheduler.resource.normalization.ResourceMetrics)58 HashMap (java.util.HashMap)53 TestUtilsForResourceAwareScheduler (org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler)51 DaemonConfig (org.apache.storm.DaemonConfig)36 Map (java.util.Map)35 Test (org.junit.jupiter.api.Test)34 ResourceAwareScheduler (org.apache.storm.scheduler.resource.ResourceAwareScheduler)32 Test (org.junit.Test)30 SchedulerAssignmentImpl (org.apache.storm.scheduler.SchedulerAssignmentImpl)29 ExecutorDetails (org.apache.storm.scheduler.ExecutorDetails)28 SchedulerAssignment (org.apache.storm.scheduler.SchedulerAssignment)28 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)28 HashSet (java.util.HashSet)23