Search in sources :

Example 16 with PackingPlan

use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.

the class ResourceCompliantRRPackingTest method testRepackPadding.

/**
   * Test the scenario ram map config is partially set and scaling is requested
   */
@Test
public void testRepackPadding() throws Exception {
    int paddingPercentage = 50;
    topologyConfig.setContainerPaddingPercentage(paddingPercentage);
    // Explicit set component ram map
    ByteAmount boltRam = ByteAmount.fromGigabytes(4);
    ByteAmount maxContainerRam = ByteAmount.fromGigabytes(10);
    topologyConfig.setComponentRam(BOLT_NAME, boltRam);
    topologyConfig.setContainerRamRequested(maxContainerRam);
    TopologyAPI.Topology topologyExplicitRamMap = getTopology(spoutParallelism, boltParallelism, topologyConfig);
    int numScalingInstances = 3;
    Map<String, Integer> componentChanges = new HashMap<>();
    componentChanges.put(BOLT_NAME, numScalingInstances);
    int numContainersBeforeRepack = 3;
    PackingPlan newPackingPlan = doScalingTest(topologyExplicitRamMap, componentChanges, boltRam, boltParallelism, instanceDefaultResources.getRam(), spoutParallelism, numContainersBeforeRepack, totalInstances);
    Assert.assertEquals(6, newPackingPlan.getContainers().size());
    Assert.assertEquals((Integer) (totalInstances + numScalingInstances), newPackingPlan.getInstanceCount());
    AssertPacking.assertContainers(newPackingPlan.getContainers(), BOLT_NAME, SPOUT_NAME, boltRam, instanceDefaultResources.getRam(), null);
    for (PackingPlan.ContainerPlan containerPlan : newPackingPlan.getContainers()) {
        //Each container either contains a single bolt or 1 bolt and 2 spouts or 1 bolt and 1 spout
        if (containerPlan.getInstances().size() == 1) {
            Assert.assertEquals(boltRam.increaseBy(paddingPercentage), containerPlan.getRequiredResource().getRam());
        }
        if (containerPlan.getInstances().size() == 2) {
            Assert.assertEquals(boltRam.plus(instanceDefaultResources.getRam()).increaseBy(paddingPercentage), containerPlan.getRequiredResource().getRam());
        }
        if (containerPlan.getInstances().size() == 3) {
            Assert.assertEquals(boltRam.plus(instanceDefaultResources.getRam().multiply(2)).increaseBy(paddingPercentage), containerPlan.getRequiredResource().getRam());
        }
    }
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount) HashMap(java.util.HashMap) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Test(org.junit.Test)

Example 17 with PackingPlan

use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.

the class ResourceCompliantRRPackingTest method testDefaultContainerSizeWithPadding.

/**
   * Test the scenario where the max container size is the default and padding is configured
   */
@Test
public void testDefaultContainerSizeWithPadding() throws Exception {
    int numContainers = 2;
    int padding = 50;
    topologyConfig.setContainerPaddingPercentage(padding);
    TopologyAPI.Topology newTopology = getTopology(spoutParallelism, boltParallelism, topologyConfig);
    PackingPlan packingPlan = pack(newTopology);
    Assert.assertEquals(numContainers, packingPlan.getContainers().size());
    Assert.assertEquals(totalInstances, packingPlan.getInstanceCount());
}
Also used : PackingPlan(com.twitter.heron.spi.packing.PackingPlan) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Test(org.junit.Test)

Example 18 with PackingPlan

use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.

the class ResourceCompliantRRPackingTest method scaleDownAndUpNoPadding.

/**
   * Test the scenario where scaling down and up is simultaneously requested and padding is
   * configured
   */
@Test
public void scaleDownAndUpNoPadding() throws Exception {
    int paddingPercentage = 0;
    int numContainers = 1;
    topologyConfig.setContainerPaddingPercentage(paddingPercentage);
    // Explicit set resources for container
    ByteAmount maxContainerRam = ByteAmount.fromGigabytes(12);
    // Explicit set component ram map
    ByteAmount spoutRam = ByteAmount.fromGigabytes(4);
    topologyConfig.setContainerRamRequested(maxContainerRam);
    topologyConfig.setComponentRam(SPOUT_NAME, spoutRam);
    topologyConfig.setNumStmgrs(numContainers);
    int noBolts = 3;
    int noSpouts = 1;
    TopologyAPI.Topology topologyExplicitRamMap = getTopology(noSpouts, noBolts, topologyConfig);
    int spoutScalingUp = 1;
    int boltScalingDown = -1;
    Map<String, Integer> componentChanges = new HashMap<>();
    // 2 spouts
    componentChanges.put(SPOUT_NAME, spoutScalingUp);
    // 2 bolts
    componentChanges.put(BOLT_NAME, boltScalingDown);
    int numContainersBeforeRepack = 1;
    PackingPlan newPackingPlan = doScalingTest(topologyExplicitRamMap, componentChanges, instanceDefaultResources.getRam(), noBolts, spoutRam, noSpouts, numContainersBeforeRepack, noSpouts + noBolts);
    Assert.assertEquals(2, newPackingPlan.getContainers().size());
    Assert.assertEquals((Integer) (noSpouts + noBolts + spoutScalingUp + boltScalingDown), newPackingPlan.getInstanceCount());
    AssertPacking.assertNumInstances(newPackingPlan.getContainers(), BOLT_NAME, noBolts + boltScalingDown);
    AssertPacking.assertNumInstances(newPackingPlan.getContainers(), SPOUT_NAME, noSpouts + spoutScalingUp);
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount) HashMap(java.util.HashMap) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Test(org.junit.Test)

Example 19 with PackingPlan

use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.

the class ResourceCompliantRRPackingTest method testEvenPacking.

/**
   * test even packing of instances
   */
@Test
public void testEvenPacking() throws Exception {
    int numContainers = 2;
    int componentParallelism = 4;
    // Set up the topology and its config
    topologyConfig.put(com.twitter.heron.api.Config.TOPOLOGY_STMGRS, numContainers);
    TopologyAPI.Topology newTopology = getTopology(componentParallelism, componentParallelism, topologyConfig);
    int numInstance = TopologyUtils.getTotalInstance(newTopology);
    // Two components
    Assert.assertEquals(2 * componentParallelism, numInstance);
    PackingPlan output = pack(newTopology);
    Assert.assertEquals(numContainers, output.getContainers().size());
    Assert.assertEquals((Integer) numInstance, output.getInstanceCount());
    for (PackingPlan.ContainerPlan container : output.getContainers()) {
        Assert.assertEquals(numInstance / numContainers, container.getInstances().size());
        Assert.assertEquals(2, countComponent("spout", container.getInstances()));
        Assert.assertEquals(2, countComponent("bolt", container.getInstances()));
    }
}
Also used : PackingPlan(com.twitter.heron.spi.packing.PackingPlan) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) Test(org.junit.Test)

Example 20 with PackingPlan

use of com.twitter.heron.spi.packing.PackingPlan in project heron by twitter.

the class ResourceCompliantRRPackingTest method testContainerRequestedResourcesSingleContainer.

/**
   * Test the scenario where container level resource config are set
   */
@Test
public void testContainerRequestedResourcesSingleContainer() throws Exception {
    int numContainers = 1;
    // Set up the topology and its config
    topologyConfig.put(com.twitter.heron.api.Config.TOPOLOGY_STMGRS, numContainers);
    // Explicit set resources for container
    ByteAmount containerRam = ByteAmount.fromGigabytes(10);
    ByteAmount containerDisk = ByteAmount.fromGigabytes(20);
    float containerCpu = 30;
    topologyConfig.setContainerRamRequested(containerRam);
    topologyConfig.setContainerDiskRequested(containerDisk);
    topologyConfig.setContainerCpuRequested(containerCpu);
    TopologyAPI.Topology topologyExplicitResourcesConfig = getTopology(spoutParallelism, boltParallelism, topologyConfig);
    PackingPlan packingPlanExplicitResourcesConfig = pack(topologyExplicitResourcesConfig);
    Assert.assertEquals(numContainers, packingPlanExplicitResourcesConfig.getContainers().size());
    Assert.assertEquals(totalInstances, packingPlanExplicitResourcesConfig.getInstanceCount());
    for (PackingPlan.ContainerPlan containerPlan : packingPlanExplicitResourcesConfig.getContainers()) {
        Assert.assertEquals(Math.round(PackingUtils.increaseBy(totalInstances * instanceDefaultResources.getCpu(), DEFAULT_CONTAINER_PADDING)), (long) containerPlan.getRequiredResource().getCpu());
        Assert.assertEquals(instanceDefaultResources.getRam().multiply(totalInstances).increaseBy(DEFAULT_CONTAINER_PADDING), containerPlan.getRequiredResource().getRam());
        Assert.assertEquals(instanceDefaultResources.getDisk().multiply(totalInstances).increaseBy(DEFAULT_CONTAINER_PADDING), containerPlan.getRequiredResource().getDisk());
        // All instances' resource requirement should be equal
        // So the size of set should be 1
        Set<Resource> resources = new HashSet<>();
        for (PackingPlan.InstancePlan instancePlan : containerPlan.getInstances()) {
            resources.add(instancePlan.getResource());
        }
        Assert.assertEquals(1, resources.size());
        Assert.assertEquals(instanceDefaultResources.getRam(), resources.iterator().next().getRam());
    }
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Resource(com.twitter.heron.spi.packing.Resource) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

PackingPlan (com.twitter.heron.spi.packing.PackingPlan)87 Test (org.junit.Test)63 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)34 ByteAmount (com.twitter.heron.common.basics.ByteAmount)27 HashSet (java.util.HashSet)22 HashMap (java.util.HashMap)20 Config (com.twitter.heron.spi.common.Config)18 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)13 Resource (com.twitter.heron.spi.packing.Resource)10 InstanceId (com.twitter.heron.spi.packing.InstanceId)7 SchedulerStateManagerAdaptor (com.twitter.heron.spi.statemgr.SchedulerStateManagerAdaptor)7 Pair (com.twitter.heron.common.basics.Pair)6 RoundRobinPacking (com.twitter.heron.packing.roundrobin.RoundRobinPacking)5 PackingPlanProtoDeserializer (com.twitter.heron.spi.packing.PackingPlanProtoDeserializer)4 EvaluatorRequest (org.apache.reef.driver.evaluator.EvaluatorRequest)4 VisibleForTesting (com.google.common.annotations.VisibleForTesting)3 PackingPlans (com.twitter.heron.proto.system.PackingPlans)3 LauncherUtils (com.twitter.heron.scheduler.utils.LauncherUtils)3 ContainerPlan (com.twitter.heron.spi.packing.PackingPlan.ContainerPlan)3 PackingPlanProtoSerializer (com.twitter.heron.spi.packing.PackingPlanProtoSerializer)3