Search in sources :

Example 26 with ByteAmount

use of org.apache.heron.common.basics.ByteAmount in project heron by twitter.

the class Resource method subtractAbsolute.

/**
 * Subtracts a given resource from the current resource. The results is never negative.
 */
public Resource subtractAbsolute(Resource other) {
    double cpuDifference = this.getCpu() - other.getCpu();
    double extraCpu = Math.max(0, cpuDifference);
    ByteAmount ramDifference = this.getRam().minus(other.getRam());
    ByteAmount extraRam = ByteAmount.ZERO.max(ramDifference);
    ByteAmount diskDifference = this.getDisk().minus(other.getDisk());
    ByteAmount extraDisk = ByteAmount.ZERO.max(diskDifference);
    return new Resource(extraCpu, extraRam, extraDisk);
}
Also used : ByteAmount(org.apache.heron.common.basics.ByteAmount)

Example 27 with ByteAmount

use of org.apache.heron.common.basics.ByteAmount in project heron by twitter.

the class Resource method plus.

/**
 * Adds a given resource from the current resource.
 */
public Resource plus(Resource other) {
    double totalCpu = this.getCpu() + other.getCpu();
    ByteAmount totalRam = this.getRam().plus(other.getRam());
    ByteAmount totalDisk = this.getDisk().plus(other.getDisk());
    return new Resource(totalCpu, totalRam, totalDisk);
}
Also used : ByteAmount(org.apache.heron.common.basics.ByteAmount)

Example 28 with ByteAmount

use of org.apache.heron.common.basics.ByteAmount in project heron by twitter.

the class HeronMasterDriverTest method requestContainerForWorkerSubmitsValidRequest.

@Test
public void requestContainerForWorkerSubmitsValidRequest() {
    ByteAmount memory = ByteAmount.fromMegabytes(786);
    EvaluatorRequest request = spyDriver.createEvaluatorRequest(5, memory);
    doReturn(request).when(spyDriver).createEvaluatorRequest(5, memory);
    HeronMasterDriver.HeronWorker worker = new HeronMasterDriver.HeronWorker(3, 5, memory);
    spyDriver.requestContainerForWorker(3, worker);
    verify(mockRequestor, times(1)).submit(request);
}
Also used : ByteAmount(org.apache.heron.common.basics.ByteAmount) EvaluatorRequest(org.apache.reef.driver.evaluator.EvaluatorRequest) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 29 with ByteAmount

use of org.apache.heron.common.basics.ByteAmount in project heron by twitter.

the class PackingPlan method getComponentRamDistribution.

/**
 * Get the formatted String describing component RAM distribution from PackingPlan,
 * used by executor
 *
 * @return String describing component RAM distribution
 */
public String getComponentRamDistribution() {
    // Generate a map with the minimal RAM size for each component
    Map<String, ByteAmount> ramMap = new HashMap<>();
    for (ContainerPlan containerPlan : this.getContainers()) {
        for (InstancePlan instancePlan : containerPlan.getInstances()) {
            ByteAmount newRam = instancePlan.getResource().getRam();
            ByteAmount currentRam = ramMap.get(instancePlan.getComponentName());
            if (currentRam == null || currentRam.asBytes() > newRam.asBytes()) {
                ramMap.put(instancePlan.getComponentName(), newRam);
            }
        }
    }
    // Convert it into a formatted String
    StringBuilder ramMapBuilder = new StringBuilder();
    for (String component : ramMap.keySet()) {
        ramMapBuilder.append(String.format("%s:%d,", component, ramMap.get(component).asBytes()));
    }
    // Remove the duplicated "," at the end
    ramMapBuilder.deleteCharAt(ramMapBuilder.length() - 1);
    return ramMapBuilder.toString();
}
Also used : ByteAmount(org.apache.heron.common.basics.ByteAmount) HashMap(java.util.HashMap)

Example 30 with ByteAmount

use of org.apache.heron.common.basics.ByteAmount in project heron by twitter.

the class SpoutInstance method produceTuple.

protected void produceTuple() {
    int maxSpoutPending = TypeUtils.getInteger(config.get(Config.TOPOLOGY_MAX_SPOUT_PENDING));
    long totalTuplesEmitted = collector.getTotalTuplesEmitted();
    long totalBytesEmitted = collector.getTotalBytesEmitted();
    Duration instanceEmitBatchTime = systemConfig.getInstanceEmitBatchTime();
    ByteAmount instanceEmitBatchSize = systemConfig.getInstanceEmitBatchSize();
    long startOfCycle = System.nanoTime();
    // We would reuse the System.nanoTime()
    long currentTime = startOfCycle;
    while (!ackEnabled || (maxSpoutPending > collector.numInFlight())) {
        // Delegate to the use defined spout
        spout.nextTuple();
        // Swap
        long startTime = currentTime;
        currentTime = System.nanoTime();
        long latency = currentTime - startTime;
        spoutMetrics.nextTuple(latency);
        long newTotalTuplesEmitted = collector.getTotalTuplesEmitted();
        long newTotalBytesEmitted = collector.getTotalBytesEmitted();
        if (newTotalTuplesEmitted == totalTuplesEmitted) {
            // No tuples to emit....
            break;
        }
        totalTuplesEmitted = newTotalTuplesEmitted;
        // To avoid spending too much time
        if (currentTime - startOfCycle - instanceEmitBatchTime.toNanos() > 0) {
            break;
        }
        if (!ByteAmount.fromBytes(newTotalBytesEmitted - totalBytesEmitted).lessThan(instanceEmitBatchSize)) {
            break;
        }
    }
}
Also used : ByteAmount(org.apache.heron.common.basics.ByteAmount) Duration(java.time.Duration)

Aggregations

ByteAmount (org.apache.heron.common.basics.ByteAmount)63 Test (org.junit.Test)41 HashMap (java.util.HashMap)17 Resource (org.apache.heron.spi.packing.Resource)17 PackingPlan (org.apache.heron.spi.packing.PackingPlan)14 HashSet (java.util.HashSet)11 TreeMap (java.util.TreeMap)6 Config (org.apache.heron.api.Config)6 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 EvaluatorRequest (org.apache.reef.driver.evaluator.EvaluatorRequest)2 BufferPoolMXBean (java.lang.management.BufferPoolMXBean)1 Duration (java.time.Duration)1 Map (java.util.Map)1 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)1 ResourceRequirement (org.apache.heron.packing.builder.ResourceRequirement)1 BaseContainer (org.apache.heron.scheduler.mesos.framework.BaseContainer)1 InstanceId (org.apache.heron.spi.packing.InstanceId)1 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)1