Search in sources :

Example 16 with Resource

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

the class MesosScheduler method fillResourcesRequirementForBaseContainer.

/**
   * Fill the the resources requirement, i.e. cpu, memory and disk for the given container.
   * This method changes the BaseContainer passed in.
   * <p>
   * Notice: Currently we just make every container homogeneous,
   * requiring maximum resources for every container.
   *
   * @param container the BaseContainer to fill value in
   * @param containerIndex the index of the container
   * @param packing the packing plan
   */
protected void fillResourcesRequirementForBaseContainer(BaseContainer container, Integer containerIndex, PackingPlan packing) {
    PackingPlan updatedPackingPlan = packing.cloneWithHomogeneousScheduledResource();
    Resource maxResourceContainer = updatedPackingPlan.getContainers().iterator().next().getRequiredResource();
    double cpu = 0;
    ByteAmount disk = ByteAmount.ZERO;
    ByteAmount mem = ByteAmount.ZERO;
    for (PackingPlan.ContainerPlan cp : packing.getContainers()) {
        Resource containerResource = cp.getRequiredResource();
        cpu = Math.max(cpu, containerResource.getCpu());
        disk = disk.max(containerResource.getDisk());
        mem = mem.max(containerResource.getRam());
    }
    container.cpu = maxResourceContainer.getCpu();
    // Convert them from bytes to MB
    container.diskInMB = maxResourceContainer.getDisk().asMegabytes();
    container.memInMB = maxResourceContainer.getRam().asMegabytes();
    container.ports = SchedulerUtils.PORTS_REQUIRED_FOR_EXECUTOR;
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Resource(com.twitter.heron.spi.packing.Resource)

Example 17 with Resource

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

the class PackingPlanBuilder method addInstance.

// adds an instance to a container with id containerId. If that container does not exist, it will
// be lazily initialized, which could result in more containers than those requested using the
// updateNumContainers method
public PackingPlanBuilder addInstance(Integer containerId, String componentName) throws ResourceExceededException {
    initContainer(containerId);
    Integer taskId = taskIds.isEmpty() ? 1 : taskIds.last() + 1;
    Integer componentIndex = componentIndexes.get(componentName) != null ? componentIndexes.get(componentName).last() + 1 : 0;
    InstanceId instanceId = new InstanceId(componentName, taskId, componentIndex);
    Resource instanceResource = PackingUtils.getResourceRequirement(componentName, this.componentRamMap, this.defaultInstanceResource, this.maxContainerResource, this.requestedContainerPadding);
    try {
        addToContainer(containers.get(containerId), new PackingPlan.InstancePlan(instanceId, instanceResource), this.componentIndexes, this.taskIds);
    } catch (ResourceExceededException e) {
        throw new ResourceExceededException(String.format("Insufficient container resources to add instance %s with resources %s to container %d.", instanceId, instanceResource, containerId), e);
    }
    LOG.finest(String.format("Added to container %d instance %s", containerId, instanceId));
    return this;
}
Also used : InstanceId(com.twitter.heron.spi.packing.InstanceId) ResourceExceededException(com.twitter.heron.packing.ResourceExceededException) PackingPlan(com.twitter.heron.spi.packing.PackingPlan) Resource(com.twitter.heron.spi.packing.Resource)

Example 18 with Resource

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

the class PackingPlanBuilder method initContainers.

private void initContainers() {
    assertResourceSettings();
    Map<Integer, Container> newContainerMap = this.containers;
    HashMap<String, TreeSet<Integer>> newComponentIndexes = this.componentIndexes;
    TreeSet<Integer> newTaskIds = this.taskIds;
    if (newComponentIndexes == null) {
        newComponentIndexes = new HashMap<>();
    }
    if (newTaskIds == null) {
        newTaskIds = new TreeSet<>();
    }
    // if this is the first time called, initialize container map with empty or existing containers
    if (newContainerMap == null) {
        if (this.existingPacking == null) {
            newContainerMap = new HashMap<>();
            for (int containerId = 1; containerId <= numContainers; containerId++) {
                newContainerMap.put(containerId, new Container(containerId, this.maxContainerResource, this.requestedContainerPadding));
            }
        } else {
            try {
                newContainerMap = getContainers(this.existingPacking, this.requestedContainerPadding, newComponentIndexes, newTaskIds);
            } catch (ResourceExceededException e) {
                throw new PackingException("Could not initialize containers using existing packing plan", e);
            }
        }
    }
    if (this.numContainers > newContainerMap.size()) {
        List<Scorer<Container>> scorers = new ArrayList<>();
        scorers.add(new ContainerIdScorer());
        List<Container> sortedContainers = sortContainers(scorers, newContainerMap.values());
        int nextContainerId = sortedContainers.get(sortedContainers.size() - 1).getContainerId() + 1;
        Resource capacity = newContainerMap.get(sortedContainers.get(0).getContainerId()).getCapacity();
        for (int i = 0; i < numContainers - newContainerMap.size(); i++) {
            newContainerMap.put(nextContainerId, new Container(nextContainerId, capacity, this.requestedContainerPadding));
            nextContainerId++;
        }
    }
    this.containers = newContainerMap;
    this.componentIndexes = newComponentIndexes;
    this.taskIds = newTaskIds;
}
Also used : ResourceExceededException(com.twitter.heron.packing.ResourceExceededException) ArrayList(java.util.ArrayList) Resource(com.twitter.heron.spi.packing.Resource) TreeSet(java.util.TreeSet) PackingException(com.twitter.heron.spi.packing.PackingException)

Example 19 with Resource

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

the class ResourceCompliantRRPacking method newPackingPlanBuilder.

private PackingPlanBuilder newPackingPlanBuilder(PackingPlan existingPackingPlan) {
    List<TopologyAPI.Config.KeyValue> topologyConfig = topology.getTopologyConfig().getKvsList();
    double defaultCpu = this.defaultInstanceResources.getCpu() * DEFAULT_NUMBER_INSTANCES_PER_CONTAINER;
    ByteAmount defaultRam = this.defaultInstanceResources.getRam().multiply(DEFAULT_NUMBER_INSTANCES_PER_CONTAINER);
    ByteAmount defaultDisk = this.defaultInstanceResources.getDisk().multiply(DEFAULT_NUMBER_INSTANCES_PER_CONTAINER);
    int paddingPercentage = TopologyUtils.getConfigWithDefault(topologyConfig, TOPOLOGY_CONTAINER_PADDING_PERCENTAGE, DEFAULT_CONTAINER_PADDING_PERCENTAGE);
    Resource maxContainerResources = new Resource(TopologyUtils.getConfigWithDefault(topologyConfig, TOPOLOGY_CONTAINER_CPU_REQUESTED, (double) Math.round(PackingUtils.increaseBy(defaultCpu, paddingPercentage))), TopologyUtils.getConfigWithDefault(topologyConfig, TOPOLOGY_CONTAINER_RAM_REQUESTED, defaultRam.increaseBy(paddingPercentage)), TopologyUtils.getConfigWithDefault(topologyConfig, TOPOLOGY_CONTAINER_DISK_REQUESTED, defaultDisk.increaseBy(paddingPercentage)));
    return new PackingPlanBuilder(topology.getId(), existingPackingPlan).setMaxContainerResource(maxContainerResources).setDefaultInstanceResource(defaultInstanceResources).setRequestedContainerPadding(paddingPercentage).setRequestedComponentRam(TopologyUtils.getComponentRamMapConfig(topology));
}
Also used : ByteAmount(com.twitter.heron.common.basics.ByteAmount) PackingPlanBuilder(com.twitter.heron.packing.builder.PackingPlanBuilder) Resource(com.twitter.heron.spi.packing.Resource) TopologyAPI(com.twitter.heron.api.generated.TopologyAPI)

Example 20 with Resource

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

the class ResourceCompliantRRPacking method computeNumAdditionalContainers.

/**
   * Computes the additional number of containers needed to accommodate a scale up/down operation
   *
   * @param componentChanges parallelism changes for scale up/down
   * @param packingPlan existing packing plan
   * @return additional number of containers needed
   */
private int computeNumAdditionalContainers(Map<String, Integer> componentChanges, PackingPlan packingPlan) {
    Resource scaleDownResource = PackingUtils.computeTotalResourceChange(topology, componentChanges, defaultInstanceResources, PackingUtils.ScalingDirection.DOWN);
    Resource scaleUpResource = PackingUtils.computeTotalResourceChange(topology, componentChanges, defaultInstanceResources, PackingUtils.ScalingDirection.UP);
    Resource additionalResource = scaleUpResource.subtractAbsolute(scaleDownResource);
    return (int) additionalResource.divideBy(packingPlan.getMaxContainerResources());
}
Also used : Resource(com.twitter.heron.spi.packing.Resource)

Aggregations

Resource (com.twitter.heron.spi.packing.Resource)29 ByteAmount (com.twitter.heron.common.basics.ByteAmount)14 PackingPlan (com.twitter.heron.spi.packing.PackingPlan)14 TopologyAPI (com.twitter.heron.api.generated.TopologyAPI)8 HashSet (java.util.HashSet)8 Test (org.junit.Test)7 Config (com.twitter.heron.spi.common.Config)5 ResourceExceededException (com.twitter.heron.packing.ResourceExceededException)4 InstanceId (com.twitter.heron.spi.packing.InstanceId)4 HashMap (java.util.HashMap)4 ArrayList (java.util.ArrayList)3 PackingPlanBuilder (com.twitter.heron.packing.builder.PackingPlanBuilder)2 Before (org.junit.Before)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 RamRequirement (com.twitter.heron.packing.RamRequirement)1 BaseContainer (com.twitter.heron.scheduler.mesos.framework.BaseContainer)1 PackingException (com.twitter.heron.spi.packing.PackingException)1