Search in sources :

Example 26 with ResourceMetrics

use of org.apache.storm.scheduler.resource.normalization.ResourceMetrics in project storm by apache.

the class TestResourceAwareScheduler method testMultipleSpoutsAndCyclicTopologies.

/**
 * Test multiple spouts and cyclic topologies
 */
@Test
public void testMultipleSpoutsAndCyclicTopologies() {
    TopologyBuilder builder = new TopologyBuilder();
    builder.setSpout("spout-1", new TestSpout(), 5);
    builder.setSpout("spout-2", new TestSpout(), 5);
    builder.setBolt("bolt-1", new TestBolt(), 5).shuffleGrouping("spout-1").shuffleGrouping("bolt-3");
    builder.setBolt("bolt-2", new TestBolt(), 5).shuffleGrouping("bolt-1");
    builder.setBolt("bolt-3", new TestBolt(), 5).shuffleGrouping("bolt-2").shuffleGrouping("spout-2");
    INimbus iNimbus = new INimbusTest();
    Map<String, SupervisorDetails> supMap = genSupervisors(25, 1, 100, 1000);
    Config config = createClusterConfig(100, 500, 500, null);
    StormTopology stormTopology = builder.createTopology();
    config.put(Config.TOPOLOGY_SUBMITTER_USER, "jerry");
    TopologyDetails topo = new TopologyDetails("topo-1", config, stormTopology, 0, genExecsAndComps(stormTopology), 0, "jerry");
    Topologies topologies = new Topologies(topo);
    Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<String, SchedulerAssignmentImpl>(), topologies, config);
    scheduler = new ResourceAwareScheduler();
    scheduler.prepare(config, new StormMetricsRegistry());
    scheduler.schedule(topologies, cluster);
    assertTrue("Topo scheduled?", cluster.getAssignmentById(topo.getId()) != null);
    assertEquals("Topo all executors scheduled?", 25, cluster.getAssignmentById(topo.getId()).getExecutorToSlot().size());
}
Also used : TopologyBuilder(org.apache.storm.topology.TopologyBuilder) DaemonConfig(org.apache.storm.DaemonConfig) 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) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) SchedulerAssignmentImpl(org.apache.storm.scheduler.SchedulerAssignmentImpl) 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 27 with ResourceMetrics

use of org.apache.storm.scheduler.resource.normalization.ResourceMetrics in project storm by apache.

the class TestDefaultEvictionStrategy method testEviction.

/**
 * The resources in the cluster are limited. In the first round of scheduling, all resources in the cluster is used.
 * User jerry submits another topology.  Since user jerry has his resource guarantees satisfied, and user bobby
 * has exceeded his resource guarantee, topo-3 from user bobby should be evicted.
 */
@Test
public void testEviction() {
    INimbus iNimbus = new INimbusTest();
    Map<String, SupervisorDetails> supMap = genSupervisors(4, 4, 100, 1000);
    Map<String, Map<String, Number>> resourceUserPool = userResourcePool(userRes("jerry", 200, 2000), userRes("bobby", 100, 1000), userRes("derek", 200, 2000));
    Config config = createClusterConfig(100, 500, 500, resourceUserPool);
    Topologies topologies = new Topologies(genTopology("topo-1", config, 1, 0, 1, 0, currentTime - 2, 10, "jerry"), genTopology("topo-2", config, 1, 0, 1, 0, currentTime - 2, 10, "bobby"), genTopology("topo-3", config, 1, 0, 1, 0, currentTime - 2, 20, "bobby"), genTopology("topo-4", config, 1, 0, 1, 0, currentTime - 2, 29, "derek"));
    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);
    assertTopologiesFullyScheduled(cluster, "topo-1", "topo-2", "topo-3", "topo-4");
    // user jerry submits another topology
    topologies = addTopologies(topologies, genTopology("topo-6", config, 1, 0, 1, 0, currentTime - 2, 20, "jerry"));
    cluster = new Cluster(cluster, topologies);
    scheduler.schedule(topologies, cluster);
    // topo-3 evicted (lowest priority)
    assertTopologiesFullyScheduled(cluster, "topo-1", "topo-2", "topo-4", "topo-6");
    assertTopologiesNotScheduled(cluster, "topo-3");
}
Also used : Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) ResourceAwareScheduler(org.apache.storm.scheduler.resource.ResourceAwareScheduler) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 28 with ResourceMetrics

use of org.apache.storm.scheduler.resource.normalization.ResourceMetrics in project storm by apache.

the class TestDefaultEvictionStrategy method testOverGuaranteeEviction.

/**
 * If users are above his or her guarantee, check if topology eviction works correctly
 */
@Test
public void testOverGuaranteeEviction() {
    INimbus iNimbus = new INimbusTest();
    Map<String, SupervisorDetails> supMap = genSupervisors(4, 4, 100, 1000);
    Map<String, Map<String, Number>> resourceUserPool = userResourcePool(userRes("jerry", 70, 700), userRes("bobby", 100, 1000), userRes("derek", 25, 250));
    Config config = createClusterConfig(100, 500, 500, resourceUserPool);
    Topologies topologies = new Topologies(genTopology("topo-1", config, 1, 0, 1, 0, currentTime - 2, 20, "jerry"), genTopology("topo-3", config, 1, 0, 1, 0, currentTime - 2, 10, "bobby"), genTopology("topo-4", config, 1, 0, 1, 0, currentTime - 2, 10, "bobby"), genTopology("topo-5", config, 1, 0, 1, 0, currentTime - 2, 29, "derek"));
    Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config);
    scheduler = new ResourceAwareScheduler();
    scheduler.prepare(config, new StormMetricsRegistry());
    LOG.info("\n\n\t\tScheduling topos 1,3,4,5");
    scheduler.schedule(topologies, cluster);
    LOG.info("\n\n\t\tDone scheduling...");
    assertTopologiesFullyScheduled(cluster, "topo-1", "topo-3", "topo-4", "topo-5");
    // user derek submits another topology into a full cluster
    // topo6 should not be able to scheduled initially, but since topo6 has higher priority than topo5
    // topo5 will be evicted so that topo6 can be scheduled
    topologies = addTopologies(topologies, genTopology("topo-6", config, 1, 0, 1, 0, currentTime - 2, 10, "derek"));
    cluster = new Cluster(cluster, topologies);
    LOG.info("\n\n\t\tScheduling topos 1,3,4,5,6");
    scheduler.schedule(topologies, cluster);
    LOG.info("\n\n\t\tDone scheduling...");
    assertTopologiesFullyScheduled(cluster, "topo-1", "topo-3", "topo-4", "topo-6");
    assertTopologiesNotScheduled(cluster, "topo-5");
    // user jerry submits topo2
    topologies = addTopologies(topologies, genTopology("topo-2", config, 1, 0, 1, 0, currentTime - 2, 20, "jerry"));
    cluster = new Cluster(cluster, topologies);
    LOG.info("\n\n\t\tScheduling topos 1-6");
    scheduler.schedule(topologies, cluster);
    LOG.info("\n\n\t\tDone scheduling...");
    assertTopologiesFullyScheduled(cluster, "topo-1", "topo-3", "topo-4", "topo-6");
    assertTopologiesNotScheduled(cluster, "topo-2", "topo-5");
}
Also used : Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) ResourceAwareScheduler(org.apache.storm.scheduler.resource.ResourceAwareScheduler) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 29 with ResourceMetrics

use of org.apache.storm.scheduler.resource.normalization.ResourceMetrics in project storm by apache.

the class TestDefaultEvictionStrategy method testEvictMultipleTopologiesFromMultipleUsersInCorrectOrder.

@Test
public void testEvictMultipleTopologiesFromMultipleUsersInCorrectOrder() {
    INimbus iNimbus = new INimbusTest();
    Map<String, SupervisorDetails> supMap = genSupervisors(4, 4, 100, 1000);
    Map<String, Map<String, Number>> resourceUserPool = userResourcePool(userRes("jerry", 300, 3000), userRes("derek", 100, 1000));
    Config config = createClusterConfig(100, 500, 500, resourceUserPool);
    Topologies topologies = new Topologies(genTopology("topo-2", config, 1, 0, 1, 0, currentTime - 2, 10, "bobby"), genTopology("topo-3", config, 1, 0, 1, 0, currentTime - 2, 20, "bobby"), genTopology("topo-4", config, 1, 0, 1, 0, currentTime - 2, 29, "derek"), genTopology("topo-5", config, 1, 0, 1, 0, currentTime - 15, 29, "derek"));
    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);
    assertTopologiesFullyScheduled(cluster, "topo-2", "topo-3", "topo-4", "topo-5");
    // user jerry submits another topology
    topologies = addTopologies(topologies, genTopology("topo-1", config, 1, 0, 1, 0, currentTime - 2, 10, "jerry"));
    cluster = new Cluster(cluster, topologies);
    scheduler.schedule(topologies, cluster);
    // topo-3 evicted since user bobby don't have any resource guarantees and topo-3 is the lowest priority for user bobby
    assertTopologiesFullyScheduled(cluster, "topo-1", "topo-2", "topo-4", "topo-5");
    assertTopologiesNotScheduled(cluster, "topo-3");
    topologies = addTopologies(topologies, genTopology("topo-6", config, 1, 0, 1, 0, currentTime - 2, 10, "jerry"));
    cluster = new Cluster(cluster, topologies);
    scheduler.schedule(topologies, cluster);
    // topo-2 evicted since user bobby don't have any resource guarantees and topo-2 is the next lowest priority for user bobby
    assertTopologiesFullyScheduled(cluster, "topo-1", "topo-4", "topo-5");
    assertTopologiesNotScheduled(cluster, "topo-2", "topo-3");
    topologies = addTopologies(topologies, genTopology("topo-7", config, 1, 0, 1, 0, currentTime - 2, 10, "jerry"));
    cluster = new Cluster(cluster, topologies);
    scheduler.schedule(topologies, cluster);
    // since user derek has exceeded his resource guarantee while user jerry has not topo-5 or topo-4 could be evicted because they have the same priority
    // but topo-4 was submitted earlier thus we choose that one to evict (somewhat arbitrary)
    assertTopologiesFullyScheduled(cluster, "topo-1", "topo-5", "topo-7");
    assertTopologiesNotScheduled(cluster, "topo-2", "topo-3", "topo-4");
}
Also used : Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Cluster(org.apache.storm.scheduler.Cluster) INimbus(org.apache.storm.scheduler.INimbus) ResourceAwareScheduler(org.apache.storm.scheduler.resource.ResourceAwareScheduler) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 30 with ResourceMetrics

use of org.apache.storm.scheduler.resource.normalization.ResourceMetrics in project storm by apache.

the class TestFIFOSchedulingPriorityStrategy method testFIFOEvictionStrategy.

@Test
public void testFIFOEvictionStrategy() {
    try (Time.SimulatedTime sim = new Time.SimulatedTime()) {
        INimbus iNimbus = new INimbusTest();
        Map<String, SupervisorDetails> supMap = genSupervisors(4, 4, 100.0, 1000.0);
        Map<String, Map<String, Number>> resourceUserPool = userResourcePool(userRes("jerry", 200.0, 2000.0));
        Config config = createClusterConfig(100, 500, 500, resourceUserPool);
        config.put(DaemonConfig.RESOURCE_AWARE_SCHEDULER_PRIORITY_STRATEGY, FIFOSchedulingPriorityStrategy.class.getName());
        Topologies topologies = new Topologies(genTopology("topo-1-jerry", config, 1, 0, 1, 0, Time.currentTimeSecs() - 250, 20, "jerry"), genTopology("topo-2-bobby", config, 1, 0, 1, 0, Time.currentTimeSecs() - 200, 10, "bobby"), genTopology("topo-3-bobby", config, 1, 0, 1, 0, Time.currentTimeSecs() - 300, 20, "bobby"), genTopology("topo-4-derek", config, 1, 0, 1, 0, Time.currentTimeSecs() - 201, 29, "derek"));
        Cluster cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config);
        ResourceAwareScheduler rs = new ResourceAwareScheduler();
        rs.prepare(config, new StormMetricsRegistry());
        try {
            rs.schedule(topologies, cluster);
            assertTopologiesFullyScheduled(cluster, "topo-1-jerry", "topo-2-bobby", "topo-3-bobby", "topo-4-derek");
            LOG.info("\n\n\t\tINSERTING topo-5");
            // new topology needs to be scheduled
            // topo-3 should be evicted since its been up the longest
            topologies = addTopologies(topologies, genTopology("topo-5-derek", config, 1, 0, 1, 0, Time.currentTimeSecs() - 15, 29, "derek"));
            cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config);
            rs.schedule(topologies, cluster);
            assertTopologiesFullyScheduled(cluster, "topo-1-jerry", "topo-2-bobby", "topo-4-derek", "topo-5-derek");
            assertTopologiesNotScheduled(cluster, "topo-3-bobby");
            LOG.info("\n\n\t\tINSERTING topo-6");
            // new topology needs to be scheduled.  topo-4 should be evicted. Even though topo-1 from user jerry is older, topo-1 will not be evicted
            // since user jerry has enough resource guarantee
            topologies = addTopologies(topologies, genTopology("topo-6-bobby", config, 1, 0, 1, 0, Time.currentTimeSecs() - 10, 29, "bobby"));
            cluster = new Cluster(iNimbus, new ResourceMetrics(new StormMetricsRegistry()), supMap, new HashMap<>(), topologies, config);
            rs.schedule(topologies, cluster);
            assertTopologiesFullyScheduled(cluster, "topo-1-jerry", "topo-2-bobby", "topo-5-derek", "topo-6-bobby");
            assertTopologiesNotScheduled(cluster, "topo-3-bobby", "topo-4-derek");
        } finally {
            rs.cleanup();
        }
    }
}
Also used : HashMap(java.util.HashMap) DaemonConfig(org.apache.storm.DaemonConfig) Config(org.apache.storm.Config) StormMetricsRegistry(org.apache.storm.metric.StormMetricsRegistry) Cluster(org.apache.storm.scheduler.Cluster) Time(org.apache.storm.utils.Time) INimbus(org.apache.storm.scheduler.INimbus) ResourceAwareScheduler(org.apache.storm.scheduler.resource.ResourceAwareScheduler) TestUtilsForResourceAwareScheduler(org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler) ResourceMetrics(org.apache.storm.scheduler.resource.normalization.ResourceMetrics) Topologies(org.apache.storm.scheduler.Topologies) SupervisorDetails(org.apache.storm.scheduler.SupervisorDetails) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Aggregations

StormMetricsRegistry (org.apache.storm.metric.StormMetricsRegistry)61 Cluster (org.apache.storm.scheduler.Cluster)61 SupervisorDetails (org.apache.storm.scheduler.SupervisorDetails)61 ResourceMetrics (org.apache.storm.scheduler.resource.normalization.ResourceMetrics)61 Topologies (org.apache.storm.scheduler.Topologies)60 Config (org.apache.storm.Config)59 INimbus (org.apache.storm.scheduler.INimbus)58 TopologyDetails (org.apache.storm.scheduler.TopologyDetails)50 TestUtilsForResourceAwareScheduler (org.apache.storm.scheduler.resource.TestUtilsForResourceAwareScheduler)49 HashMap (java.util.HashMap)40 DaemonConfig (org.apache.storm.DaemonConfig)36 Test (org.junit.jupiter.api.Test)35 ResourceAwareScheduler (org.apache.storm.scheduler.resource.ResourceAwareScheduler)29 TopologyBuilder (org.apache.storm.topology.TopologyBuilder)27 SchedulerAssignment (org.apache.storm.scheduler.SchedulerAssignment)26 ExecutorDetails (org.apache.storm.scheduler.ExecutorDetails)25 Map (java.util.Map)24 HashSet (java.util.HashSet)22 StormTopology (org.apache.storm.generated.StormTopology)21 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)21