use of com.twitter.heron.common.utils.tuple.TupleImpl in project incubator-heron by apache.
the class BoltOutputCollectorImpl method admitFailTuple.
private void admitFailTuple(Tuple tuple) {
Duration latency = Duration.ZERO;
if (ackEnabled) {
if (tuple instanceof TupleImpl) {
TupleImpl tuplImpl = (TupleImpl) tuple;
HeronTuples.AckTuple.Builder bldr = HeronTuples.AckTuple.newBuilder();
bldr.setAckedtuple(tuplImpl.getTupleKey());
long tupleSizeInBytes = 0;
for (HeronTuples.RootId rt : tuplImpl.getRoots()) {
bldr.addRoots(rt);
tupleSizeInBytes += rt.getSerializedSize();
}
outputter.addFailTuple(bldr, tupleSizeInBytes);
latency = Duration.ofNanos(System.nanoTime()).minusNanos(tuplImpl.getCreationTime());
}
}
// Invoke user-defined boltFail task hook
getPhysicalPlanHelper().getTopologyContext().invokeHookBoltFail(tuple, latency);
boltMetrics.failedTuple(tuple.getSourceStreamId(), tuple.getSourceComponent(), latency.toNanos());
}
use of com.twitter.heron.common.utils.tuple.TupleImpl in project incubator-heron by apache.
the class BoltInstance method readTuplesAndExecute.
@Override
public void readTuplesAndExecute(Communicator<Message> inQueue) {
TopologyContextImpl topologyContext = helper.getTopologyContext();
Duration instanceExecuteBatchTime = systemConfig.getInstanceExecuteBatchTime();
long startOfCycle = System.nanoTime();
// Read data from in Queues
while (!inQueue.isEmpty()) {
Message msg = inQueue.poll();
if (msg instanceof CheckpointManager.InitiateStatefulCheckpoint) {
String checkpointId = ((CheckpointManager.InitiateStatefulCheckpoint) msg).getCheckpointId();
persistState(checkpointId);
}
if (msg instanceof HeronTuples.HeronTupleSet) {
HeronTuples.HeronTupleSet tuples = (HeronTuples.HeronTupleSet) msg;
// Handle the tuples
if (tuples.hasControl()) {
throw new RuntimeException("Bolt cannot get acks/fails from other components");
}
// Get meta data of tuples
TopologyAPI.StreamId stream = tuples.getData().getStream();
int nValues = topologyContext.getComponentOutputFields(stream.getComponentName(), stream.getId()).size();
int sourceTaskId = tuples.getSrcTaskId();
for (HeronTuples.HeronDataTuple dataTuple : tuples.getData().getTuplesList()) {
long startExecuteTuple = System.nanoTime();
// Create the value list and fill the value
List<Object> values = new ArrayList<>(nValues);
for (int i = 0; i < nValues; i++) {
values.add(serializer.deserialize(dataTuple.getValues(i).toByteArray()));
}
// Decode the tuple
TupleImpl t = new TupleImpl(topologyContext, stream, dataTuple.getKey(), dataTuple.getRootsList(), values, startExecuteTuple, false, sourceTaskId);
// Delegate to the use defined bolt
bolt.execute(t);
// record the end of a tuple execution
long endExecuteTuple = System.nanoTime();
long executeLatency = endExecuteTuple - startExecuteTuple;
// Invoke user-defined execute task hook
topologyContext.invokeHookBoltExecute(t, Duration.ofNanos(executeLatency));
// Update metrics
boltMetrics.executeTuple(stream.getId(), stream.getComponentName(), executeLatency);
}
// To avoid spending too much time
long currentTime = System.nanoTime();
if (currentTime - startOfCycle - instanceExecuteBatchTime.toNanos() > 0) {
break;
}
}
}
}
use of com.twitter.heron.common.utils.tuple.TupleImpl in project incubator-heron by apache.
the class BoltInstance method handleDataTuple.
private void handleDataTuple(HeronTuples.HeronDataTuple dataTuple, TopologyAPI.StreamId stream, int srcTaskId) {
long startTime = System.nanoTime();
List<Object> values = new ArrayList<>();
for (ByteString b : dataTuple.getValuesList()) {
values.add(serializer.deserialize(b.toByteArray()));
}
// Decode the tuple
TupleImpl t = new TupleImpl(helper.getTopologyContext(), stream, dataTuple.getKey(), dataTuple.getRootsList(), values, srcTaskId);
long deserializedTime = System.nanoTime();
// Delegate to the use defined bolt
bolt.execute(t);
Duration executeLatency = Duration.ofNanos(System.nanoTime()).minusNanos(deserializedTime);
// Invoke user-defined execute task hook
helper.getTopologyContext().invokeHookBoltExecute(t, executeLatency);
boltMetrics.deserializeDataTuple(stream.getId(), stream.getComponentName(), deserializedTime - startTime);
// Update metrics
boltMetrics.executeTuple(stream.getId(), stream.getComponentName(), executeLatency.toNanos());
}
Aggregations