Search in sources :

Example 1 with TupleImpl

use of org.apache.heron.common.utils.tuple.TupleImpl in project heron by twitter.

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());
}
Also used : ByteString(com.google.protobuf.ByteString) ArrayList(java.util.ArrayList) Duration(java.time.Duration) TupleImpl(org.apache.heron.common.utils.tuple.TupleImpl)

Example 2 with TupleImpl

use of org.apache.heron.common.utils.tuple.TupleImpl in project heron by twitter.

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() && !waitingForCheckpointSaved) {
        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 startTime = 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, System.nanoTime(), false, sourceTaskId);
                long deserializedTime = System.nanoTime();
                // Delegate to the use defined bolt
                bolt.execute(t);
                // record the latency of execution
                long executeLatency = Duration.ofNanos(System.nanoTime()).minusNanos(deserializedTime).toNanos();
                // Invoke user-defined execute task hook
                topologyContext.invokeHookBoltExecute(t, Duration.ofNanos(executeLatency));
                // Update metrics
                boltMetrics.deserializeDataTuple(stream.getId(), stream.getComponentName(), deserializedTime - startTime);
                boltMetrics.executeTuple(stream.getId(), stream.getComponentName(), executeLatency);
            }
            // To avoid spending too much time
            long currentTime = System.nanoTime();
            if (currentTime - startOfCycle - instanceExecuteBatchTime.toNanos() > 0) {
                break;
            }
        }
    }
}
Also used : Message(com.google.protobuf.Message) TopologyContextImpl(org.apache.heron.common.utils.topology.TopologyContextImpl) ArrayList(java.util.ArrayList) Duration(java.time.Duration) HeronTuples(org.apache.heron.proto.system.HeronTuples) TopologyAPI(org.apache.heron.api.generated.TopologyAPI) TupleImpl(org.apache.heron.common.utils.tuple.TupleImpl)

Example 3 with TupleImpl

use of org.apache.heron.common.utils.tuple.TupleImpl in project heron by twitter.

the class BoltOutputCollectorImpl method admitBoltTuple.

// ///////////////////////////////////////////////////////
// Following private methods are internal implementations
// ///////////////////////////////////////////////////////
private List<Integer> admitBoltTuple(String streamId, Collection<Tuple> anchors, List<Object> tuple, Integer emitDirectTaskId) {
    if (getPhysicalPlanHelper().isTerminatedComponent()) {
        // No need to handle this tuple
        return null;
    }
    // Start construct the data tuple
    HeronTuples.HeronDataTuple.Builder bldr = initTupleBuilder(streamId, tuple, emitDirectTaskId);
    // Set the anchors for a tuple
    if (anchors != null) {
        // This message is rooted
        Set<HeronTuples.RootId> mergedRoots = new HashSet<>();
        for (Tuple tpl : anchors) {
            if (tpl instanceof TupleImpl) {
                TupleImpl t = (TupleImpl) tpl;
                mergedRoots.addAll(t.getRoots());
            }
        }
        for (HeronTuples.RootId rt : mergedRoots) {
            bldr.addRoots(rt);
        }
    }
    sendTuple(bldr, streamId, tuple);
    // TODO:- remove this after changing the API
    return null;
}
Also used : TupleImpl(org.apache.heron.common.utils.tuple.TupleImpl) Tuple(org.apache.heron.api.tuple.Tuple) HeronTuples(org.apache.heron.proto.system.HeronTuples) HashSet(java.util.HashSet)

Example 4 with TupleImpl

use of org.apache.heron.common.utils.tuple.TupleImpl in project heron by twitter.

the class BoltOutputCollectorImpl method admitAckTuple.

private void admitAckTuple(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.addAckTuple(bldr, tupleSizeInBytes);
            latency = Duration.ofNanos(System.nanoTime()).minusNanos(tuplImpl.getCreationTime());
        }
    }
    // Invoke user-defined boltAck task hook
    getPhysicalPlanHelper().getTopologyContext().invokeHookBoltAck(tuple, latency);
    boltMetrics.ackedTuple(tuple.getSourceStreamId(), tuple.getSourceComponent(), latency.toNanos());
}
Also used : Duration(java.time.Duration) TupleImpl(org.apache.heron.common.utils.tuple.TupleImpl) HeronTuples(org.apache.heron.proto.system.HeronTuples)

Example 5 with TupleImpl

use of org.apache.heron.common.utils.tuple.TupleImpl in project heron by twitter.

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());
}
Also used : Duration(java.time.Duration) TupleImpl(org.apache.heron.common.utils.tuple.TupleImpl) HeronTuples(org.apache.heron.proto.system.HeronTuples)

Aggregations

TupleImpl (org.apache.heron.common.utils.tuple.TupleImpl)5 Duration (java.time.Duration)4 HeronTuples (org.apache.heron.proto.system.HeronTuples)4 ArrayList (java.util.ArrayList)2 ByteString (com.google.protobuf.ByteString)1 Message (com.google.protobuf.Message)1 HashSet (java.util.HashSet)1 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)1 Tuple (org.apache.heron.api.tuple.Tuple)1 TopologyContextImpl (org.apache.heron.common.utils.topology.TopologyContextImpl)1