Search in sources :

Example 1 with ResourceRequirement

use of org.apache.heron.packing.builder.ResourceRequirement 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) {
    List<ResourceRequirement> resourceRequirements = getSortedInstances(componentsToScaleDown.keySet());
    InstanceCountScorer instanceCountScorer = new InstanceCountScorer();
    ContainerIdScorer containerIdScorer = new ContainerIdScorer(false);
    for (ResourceRequirement resourceRequirement : resourceRequirements) {
        String componentName = resourceRequirement.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 : ArrayList(java.util.ArrayList) Scorer(org.apache.heron.packing.builder.Scorer) InstanceCountScorer(org.apache.heron.packing.builder.InstanceCountScorer) ContainerIdScorer(org.apache.heron.packing.builder.ContainerIdScorer) HomogeneityScorer(org.apache.heron.packing.builder.HomogeneityScorer) ResourceRequirement(org.apache.heron.packing.builder.ResourceRequirement) HomogeneityScorer(org.apache.heron.packing.builder.HomogeneityScorer) MinRamConstraint(org.apache.heron.packing.constraints.MinRamConstraint) ResourceConstraint(org.apache.heron.packing.constraints.ResourceConstraint) InstanceDensityConstraint(org.apache.heron.packing.constraints.InstanceDensityConstraint) MinCpuConstraint(org.apache.heron.packing.constraints.MinCpuConstraint) InstanceCountScorer(org.apache.heron.packing.builder.InstanceCountScorer) ContainerIdScorer(org.apache.heron.packing.builder.ContainerIdScorer)

Example 2 with ResourceRequirement

use of org.apache.heron.packing.builder.ResourceRequirement in project heron by twitter.

the class FirstFitDecreasingPacking method getSortedInstances.

/**
 * Sort the components in decreasing order based on their RAM requirements
 *
 * @return The sorted list of components and their RAM requirements
 */
private List<ResourceRequirement> getSortedInstances(Set<String> componentNames) {
    List<ResourceRequirement> resourceRequirements = new ArrayList<>();
    for (String componentName : componentNames) {
        Resource requiredResource = this.componentResourceMap.getOrDefault(componentName, defaultInstanceResources);
        resourceRequirements.add(new ResourceRequirement(componentName, requiredResource.getRam(), requiredResource.getCpu()));
    }
    Collections.sort(resourceRequirements, sortingStrategy.reversed());
    return resourceRequirements;
}
Also used : ArrayList(java.util.ArrayList) Resource(org.apache.heron.spi.packing.Resource) ResourceRequirement(org.apache.heron.packing.builder.ResourceRequirement)

Example 3 with ResourceRequirement

use of org.apache.heron.packing.builder.ResourceRequirement 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 ConstraintViolationException {
    List<ResourceRequirement> resourceRequirements = getSortedInstances(parallelismMap.keySet());
    for (ResourceRequirement resourceRequirement : resourceRequirements) {
        String componentName = resourceRequirement.getComponentName();
        int numInstance = parallelismMap.get(componentName);
        for (int j = 0; j < numInstance; j++) {
            placeFFDInstance(planBuilder, componentName);
        }
    }
}
Also used : ResourceRequirement(org.apache.heron.packing.builder.ResourceRequirement) MinRamConstraint(org.apache.heron.packing.constraints.MinRamConstraint) ResourceConstraint(org.apache.heron.packing.constraints.ResourceConstraint) InstanceDensityConstraint(org.apache.heron.packing.constraints.InstanceDensityConstraint) MinCpuConstraint(org.apache.heron.packing.constraints.MinCpuConstraint)

Example 4 with ResourceRequirement

use of org.apache.heron.packing.builder.ResourceRequirement in project heron by twitter.

the class RoundRobinPacking method getSortedRAMComponents.

/**
 * Sort the components in decreasing order based on their RAM requirements
 *
 * @return The sorted list of components and their RAM requirements
 */
private ArrayList<ResourceRequirement> getSortedRAMComponents(Set<String> componentNames) {
    ArrayList<ResourceRequirement> resourceRequirements = new ArrayList<>();
    Map<String, ByteAmount> ramMap = TopologyUtils.getComponentRamMapConfig(topology);
    for (String componentName : componentNames) {
        resourceRequirements.add(new ResourceRequirement(componentName, ramMap.getOrDefault(componentName, ByteAmount.ZERO)));
    }
    Collections.sort(resourceRequirements, SortingStrategy.RAM_FIRST.reversed());
    return resourceRequirements;
}
Also used : ByteAmount(org.apache.heron.common.basics.ByteAmount) ArrayList(java.util.ArrayList) ResourceRequirement(org.apache.heron.packing.builder.ResourceRequirement)

Aggregations

ResourceRequirement (org.apache.heron.packing.builder.ResourceRequirement)4 ArrayList (java.util.ArrayList)3 InstanceDensityConstraint (org.apache.heron.packing.constraints.InstanceDensityConstraint)2 MinCpuConstraint (org.apache.heron.packing.constraints.MinCpuConstraint)2 MinRamConstraint (org.apache.heron.packing.constraints.MinRamConstraint)2 ResourceConstraint (org.apache.heron.packing.constraints.ResourceConstraint)2 ByteAmount (org.apache.heron.common.basics.ByteAmount)1 ContainerIdScorer (org.apache.heron.packing.builder.ContainerIdScorer)1 HomogeneityScorer (org.apache.heron.packing.builder.HomogeneityScorer)1 InstanceCountScorer (org.apache.heron.packing.builder.InstanceCountScorer)1 Scorer (org.apache.heron.packing.builder.Scorer)1 Resource (org.apache.heron.spi.packing.Resource)1