Search in sources :

Example 1 with RamRequirement

use of com.twitter.heron.packing.RamRequirement in project heron by twitter.

the class FirstFitDecreasingPacking method removeInstancesFromContainers.

/**
   * Removes instances from containers during scaling down
   *
   * @param packingPlanBuilder existing packing plan
   * @param componentsToScaleDown scale down factor for the components.
   */
private void removeInstancesFromContainers(PackingPlanBuilder packingPlanBuilder, Map<String, Integer> componentsToScaleDown) {
    ArrayList<RamRequirement> ramRequirements = getSortedRAMInstances(componentsToScaleDown.keySet());
    InstanceCountScorer instanceCountScorer = new InstanceCountScorer();
    ContainerIdScorer containerIdScorer = new ContainerIdScorer(false);
    for (RamRequirement ramRequirement : ramRequirements) {
        String componentName = ramRequirement.getComponentName();
        int numInstancesToRemove = -componentsToScaleDown.get(componentName);
        List<Scorer<Container>> scorers = new ArrayList<>();
        // all-same-component containers
        scorers.add(new HomogeneityScorer(componentName, true));
        // then fewest instances
        scorers.add(instanceCountScorer);
        // then most homogeneous
        scorers.add(new HomogeneityScorer(componentName, false));
        // then highest container id
        scorers.add(containerIdScorer);
        for (int j = 0; j < numInstancesToRemove; j++) {
            packingPlanBuilder.removeInstance(scorers, componentName);
        }
    }
}
Also used : RamRequirement(com.twitter.heron.packing.RamRequirement) ArrayList(java.util.ArrayList) InstanceCountScorer(com.twitter.heron.packing.builder.InstanceCountScorer) ContainerIdScorer(com.twitter.heron.packing.builder.ContainerIdScorer) Scorer(com.twitter.heron.packing.builder.Scorer) HomogeneityScorer(com.twitter.heron.packing.builder.HomogeneityScorer) HomogeneityScorer(com.twitter.heron.packing.builder.HomogeneityScorer) InstanceCountScorer(com.twitter.heron.packing.builder.InstanceCountScorer) ContainerIdScorer(com.twitter.heron.packing.builder.ContainerIdScorer)

Example 2 with RamRequirement

use of com.twitter.heron.packing.RamRequirement in project incubator-heron by apache.

the class FirstFitDecreasingPacking method getSortedRAMInstances.

/**
 * Sort the components in decreasing order based on their RAM requirements
 *
 * @return The sorted list of components and their RAM requirements
 */
private ArrayList<RamRequirement> getSortedRAMInstances(Set<String> componentNames) {
    ArrayList<RamRequirement> ramRequirements = new ArrayList<>();
    Map<String, ByteAmount> ramMap = TopologyUtils.getComponentRamMapConfig(topology);
    for (String componentName : componentNames) {
        Resource requiredResource = PackingUtils.getResourceRequirement(componentName, ramMap, this.defaultInstanceResources, this.maxContainerResources, this.paddingPercentage);
        ramRequirements.add(new RamRequirement(componentName, requiredResource.getRam()));
    }
    Collections.sort(ramRequirements, Collections.reverseOrder());
    return ramRequirements;
}
Also used : RamRequirement(com.twitter.heron.packing.RamRequirement) ByteAmount(com.twitter.heron.common.basics.ByteAmount) ArrayList(java.util.ArrayList) Resource(com.twitter.heron.spi.packing.Resource)

Example 3 with RamRequirement

use of com.twitter.heron.packing.RamRequirement in project incubator-heron by apache.

the class FirstFitDecreasingPacking method removeInstancesFromContainers.

/**
 * Removes instances from containers during scaling down
 *
 * @param packingPlanBuilder existing packing plan
 * @param componentsToScaleDown scale down factor for the components.
 */
private void removeInstancesFromContainers(PackingPlanBuilder packingPlanBuilder, Map<String, Integer> componentsToScaleDown) {
    ArrayList<RamRequirement> ramRequirements = getSortedRAMInstances(componentsToScaleDown.keySet());
    InstanceCountScorer instanceCountScorer = new InstanceCountScorer();
    ContainerIdScorer containerIdScorer = new ContainerIdScorer(false);
    for (RamRequirement ramRequirement : ramRequirements) {
        String componentName = ramRequirement.getComponentName();
        int numInstancesToRemove = -componentsToScaleDown.get(componentName);
        List<Scorer<Container>> scorers = new ArrayList<>();
        // all-same-component containers
        scorers.add(new HomogeneityScorer(componentName, true));
        // then fewest instances
        scorers.add(instanceCountScorer);
        // then most homogeneous
        scorers.add(new HomogeneityScorer(componentName, false));
        // then highest container id
        scorers.add(containerIdScorer);
        for (int j = 0; j < numInstancesToRemove; j++) {
            packingPlanBuilder.removeInstance(scorers, componentName);
        }
    }
}
Also used : RamRequirement(com.twitter.heron.packing.RamRequirement) ArrayList(java.util.ArrayList) InstanceCountScorer(com.twitter.heron.packing.builder.InstanceCountScorer) ContainerIdScorer(com.twitter.heron.packing.builder.ContainerIdScorer) Scorer(com.twitter.heron.packing.builder.Scorer) HomogeneityScorer(com.twitter.heron.packing.builder.HomogeneityScorer) HomogeneityScorer(com.twitter.heron.packing.builder.HomogeneityScorer) InstanceCountScorer(com.twitter.heron.packing.builder.InstanceCountScorer) ContainerIdScorer(com.twitter.heron.packing.builder.ContainerIdScorer)

Example 4 with RamRequirement

use of com.twitter.heron.packing.RamRequirement in project heron by twitter.

the class FirstFitDecreasingPacking method getSortedRAMInstances.

/**
   * Sort the components in decreasing order based on their RAM requirements
   *
   * @return The sorted list of components and their RAM requirements
   */
private ArrayList<RamRequirement> getSortedRAMInstances(Set<String> componentNames) {
    ArrayList<RamRequirement> ramRequirements = new ArrayList<>();
    Map<String, ByteAmount> ramMap = TopologyUtils.getComponentRamMapConfig(topology);
    for (String componentName : componentNames) {
        Resource requiredResource = PackingUtils.getResourceRequirement(componentName, ramMap, this.defaultInstanceResources, this.maxContainerResources, this.paddingPercentage);
        ramRequirements.add(new RamRequirement(componentName, requiredResource.getRam()));
    }
    Collections.sort(ramRequirements, Collections.reverseOrder());
    return ramRequirements;
}
Also used : RamRequirement(com.twitter.heron.packing.RamRequirement) ByteAmount(com.twitter.heron.common.basics.ByteAmount) ArrayList(java.util.ArrayList) Resource(com.twitter.heron.spi.packing.Resource)

Example 5 with RamRequirement

use of com.twitter.heron.packing.RamRequirement in project heron by twitter.

the class FirstFitDecreasingPacking method assignInstancesToContainers.

/**
   * Assigns instances to containers
   *
   * @param planBuilder existing packing plan
   * @param parallelismMap component parallelism
   */
private void assignInstancesToContainers(PackingPlanBuilder planBuilder, Map<String, Integer> parallelismMap) throws ResourceExceededException {
    ArrayList<RamRequirement> ramRequirements = getSortedRAMInstances(parallelismMap.keySet());
    for (RamRequirement ramRequirement : ramRequirements) {
        String componentName = ramRequirement.getComponentName();
        int numInstance = parallelismMap.get(componentName);
        for (int j = 0; j < numInstance; j++) {
            placeFFDInstance(planBuilder, componentName);
        }
    }
}
Also used : RamRequirement(com.twitter.heron.packing.RamRequirement)

Aggregations

RamRequirement (com.twitter.heron.packing.RamRequirement)6 ArrayList (java.util.ArrayList)4 ByteAmount (com.twitter.heron.common.basics.ByteAmount)2 ContainerIdScorer (com.twitter.heron.packing.builder.ContainerIdScorer)2 HomogeneityScorer (com.twitter.heron.packing.builder.HomogeneityScorer)2 InstanceCountScorer (com.twitter.heron.packing.builder.InstanceCountScorer)2 Scorer (com.twitter.heron.packing.builder.Scorer)2 Resource (com.twitter.heron.spi.packing.Resource)2