Search in sources :

Example 36 with Resource

use of org.apache.heron.spi.packing.Resource in project heron by twitter.

the class PackingUtils method computeTotalResourceChange.

/**
 * Identifies the resources reclaimed by the components that will be scaled down
 *
 * @return Total resources reclaimed
 */
public static Resource computeTotalResourceChange(TopologyAPI.Topology topology, Map<String, Integer> componentChanges, Resource defaultInstanceResources, ScalingDirection scalingDirection) {
    double cpu = 0;
    ByteAmount ram = ByteAmount.ZERO;
    ByteAmount disk = ByteAmount.ZERO;
    Map<String, ByteAmount> ramMap = TopologyUtils.getComponentRamMapConfig(topology);
    Map<String, Integer> componentsToScale = PackingUtils.getComponentsToScale(componentChanges, scalingDirection);
    for (String component : componentsToScale.keySet()) {
        int parallelismChange = Math.abs(componentChanges.get(component));
        cpu += parallelismChange * defaultInstanceResources.getCpu();
        disk = disk.plus(defaultInstanceResources.getDisk().multiply(parallelismChange));
        if (ramMap.containsKey(component)) {
            ram = ram.plus(ramMap.get(component).multiply(parallelismChange));
        } else {
            ram = ram.plus(defaultInstanceResources.getRam().multiply(parallelismChange));
        }
    }
    return new Resource(cpu, ram, disk);
}
Also used : ByteAmount(org.apache.heron.common.basics.ByteAmount) Resource(org.apache.heron.spi.packing.Resource)

Example 37 with Resource

use of org.apache.heron.spi.packing.Resource in project heron by twitter.

the class PackingUtils method finalizePadding.

/**
 * Finalize padding by taking Math.max(containerResource * paddingPercent, paddingValue)
 *
 * @param containerResource max container resource
 * @param padding padding value
 * @param paddingPercentage padding percent
 * @return finalized padding amount
 */
public static Resource finalizePadding(Resource containerResource, Resource padding, int paddingPercentage) {
    double cpuPadding = Math.max(padding.getCpu(), containerResource.getCpu() * paddingPercentage / 100);
    ByteAmount ramPadding = ByteAmount.fromBytes(Math.max(padding.getRam().asBytes(), containerResource.getRam().asBytes() * paddingPercentage / 100));
    ByteAmount diskPadding = ByteAmount.fromBytes(Math.max(padding.getDisk().asBytes(), containerResource.getDisk().asBytes() * paddingPercentage / 100));
    return new Resource(cpuPadding, ramPadding, diskPadding);
}
Also used : ByteAmount(org.apache.heron.common.basics.ByteAmount) Resource(org.apache.heron.spi.packing.Resource)

Example 38 with Resource

use of org.apache.heron.spi.packing.Resource in project heron by twitter.

the class PackingPlanBuilder method getContainers.

/**
 * Generates the containers that correspond to the current packing plan
 * along with their associated instances.
 *
 * @return Map of containers for the current packing plan, keyed by containerId
 */
@VisibleForTesting
static Map<Integer, Container> getContainers(PackingPlan currentPackingPlan, Resource maxContainerResource, Resource padding, Map<String, TreeSet<Integer>> componentIndexes, TreeSet<Integer> taskIds) {
    Map<Integer, Container> containers = new HashMap<>();
    Resource capacity = maxContainerResource;
    for (PackingPlan.ContainerPlan currentContainerPlan : currentPackingPlan.getContainers()) {
        Container container = new Container(currentContainerPlan.getId(), capacity, padding);
        for (PackingPlan.InstancePlan instancePlan : currentContainerPlan.getInstances()) {
            addToContainer(container, instancePlan, componentIndexes, taskIds);
        }
        containers.put(currentContainerPlan.getId(), container);
    }
    return containers;
}
Also used : HashMap(java.util.HashMap) PackingPlan(org.apache.heron.spi.packing.PackingPlan) Resource(org.apache.heron.spi.packing.Resource) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 39 with Resource

use of org.apache.heron.spi.packing.Resource in project heron by twitter.

the class PackingPlanBuilder method initContainers.

private void initContainers() {
    assertResourceSettings();
    if (this.componentIndexes == null) {
        this.componentIndexes = new HashMap<>();
    }
    if (this.taskIds == null) {
        this.taskIds = new TreeSet<>();
    }
    // if this is the first time called, initialize container map with empty or existing containers
    if (this.containers == null) {
        if (this.existingPacking == null) {
            this.containers = new HashMap<>();
            for (int containerId = 1; containerId <= numContainers; containerId++) {
                this.containers.put(containerId, new Container(containerId, this.maxContainerResource, this.requestedContainerPadding));
            }
        } else {
            this.containers = getContainers(this.existingPacking, this.maxContainerResource, this.requestedContainerPadding, this.componentIndexes, this.taskIds);
        }
    }
    if (this.numContainers > this.containers.size()) {
        List<Scorer<Container>> scorers = new ArrayList<>();
        scorers.add(new ContainerIdScorer());
        List<Container> sortedContainers = sortContainers(scorers, this.containers.values());
        int nextContainerId = sortedContainers.get(sortedContainers.size() - 1).getContainerId() + 1;
        Resource capacity = this.containers.get(sortedContainers.get(0).getContainerId()).getCapacity();
        for (int i = 0; i < numContainers - this.containers.size(); i++) {
            this.containers.put(nextContainerId, new Container(nextContainerId, capacity, this.requestedContainerPadding));
            nextContainerId++;
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Resource(org.apache.heron.spi.packing.Resource) PackingConstraint(org.apache.heron.packing.constraints.PackingConstraint) InstanceConstraint(org.apache.heron.packing.constraints.InstanceConstraint)

Example 40 with Resource

use of org.apache.heron.spi.packing.Resource in project heron by twitter.

the class ScorerTest method init.

@Before
public void init() throws ResourceExceededException {
    Resource containerCapacity = new Resource(1000, ByteAmount.fromGigabytes(100), ByteAmount.fromGigabytes(100));
    testContainers = new Container[] { new Container(1, containerCapacity, Resource.EMPTY_RESOURCE), new Container(3, containerCapacity, Resource.EMPTY_RESOURCE), new Container(4, containerCapacity, Resource.EMPTY_RESOURCE) };
    addInstance(testContainers[0], "A", 0);
    addInstance(testContainers[0], "A", 1);
    addInstance(testContainers[0], "B", 2);
    addInstance(testContainers[0], "B", 3);
    addInstance(testContainers[1], "A", 4);
    addInstance(testContainers[1], "B", 5);
    addInstance(testContainers[1], "B", 6);
    addInstance(testContainers[2], "A", 7);
    addInstance(testContainers[2], "A", 8);
}
Also used : Resource(org.apache.heron.spi.packing.Resource) Before(org.junit.Before)

Aggregations

Resource (org.apache.heron.spi.packing.Resource)47 PackingPlan (org.apache.heron.spi.packing.PackingPlan)25 Test (org.junit.Test)22 HashSet (java.util.HashSet)18 ByteAmount (org.apache.heron.common.basics.ByteAmount)17 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)7 HashMap (java.util.HashMap)6 Config (org.apache.heron.spi.common.Config)6 Task (com.hashicorp.nomad.apimodel.Task)4 ArrayList (java.util.ArrayList)4 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)4 InstanceId (org.apache.heron.spi.packing.InstanceId)4 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 Job (com.hashicorp.nomad.apimodel.Job)2 TaskGroup (com.hashicorp.nomad.apimodel.TaskGroup)2 Quantity (io.kubernetes.client.custom.Quantity)2 V1Container (io.kubernetes.client.openapi.models.V1Container)2 V1ContainerBuilder (io.kubernetes.client.openapi.models.V1ContainerBuilder)2 List (java.util.List)2