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);
}
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);
}
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);
}
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();
}
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;
}
}
}
Aggregations