Search in sources :

Example 6 with BackpressureState

use of org.apache.storm.daemon.worker.BackPressureTracker.BackpressureState in project storm by apache.

the class WorkerState method transferLocalBatch.

// Receives msgs from remote workers and feeds them to local executors. If any receiving local executor is under Back Pressure,
// informs other workers about back pressure situation. Runs in the NettyWorker thread.
private void transferLocalBatch(ArrayList<AddressedTuple> tupleBatch) {
    for (int i = 0; i < tupleBatch.size(); i++) {
        AddressedTuple tuple = tupleBatch.get(i);
        JCQueue queue = taskToExecutorQueue.get(tuple.dest);
        // 1- try adding to main queue if its overflow is not empty
        if (queue.isEmptyOverflow()) {
            if (queue.tryPublish(tuple)) {
                continue;
            }
        }
        // 2- BP detected (i.e MainQ is full). So try adding to overflow
        int currOverflowCount = queue.getOverflowCount();
        // get BP state object so only have to lookup once
        BackpressureState bpState = bpTracker.getBackpressureState(tuple.dest);
        if (bpTracker.recordBackPressure(bpState)) {
            receiver.sendBackPressureStatus(bpTracker.getCurrStatus());
            bpTracker.setLastOverflowCount(bpState, currOverflowCount);
        } else {
            if (currOverflowCount - bpTracker.getLastOverflowCount(bpState) > RESEND_BACKPRESSURE_SIZE) {
                // resend BP status, in case prev notification was missed or reordered
                BackPressureStatus bpStatus = bpTracker.getCurrStatus();
                receiver.sendBackPressureStatus(bpStatus);
                bpTracker.setLastOverflowCount(bpState, currOverflowCount);
                LOG.debug("Re-sent BackPressure Status. OverflowCount = {}, BP Status ID = {}. ", currOverflowCount, bpStatus.id);
            }
        }
        if (!queue.tryPublishToOverflow(tuple)) {
            dropMessage(tuple, queue);
        }
    }
}
Also used : JCQueue(org.apache.storm.utils.JCQueue) BackpressureState(org.apache.storm.daemon.worker.BackPressureTracker.BackpressureState) BackPressureStatus(org.apache.storm.messaging.netty.BackPressureStatus) AddressedTuple(org.apache.storm.tuple.AddressedTuple)

Aggregations

BackpressureState (org.apache.storm.daemon.worker.BackPressureTracker.BackpressureState)6 JCQueue (org.apache.storm.utils.JCQueue)6 BackPressureStatus (org.apache.storm.messaging.netty.BackPressureStatus)5 StormMetricRegistry (org.apache.storm.metrics2.StormMetricRegistry)5 Test (org.junit.Test)5 AddressedTuple (org.apache.storm.tuple.AddressedTuple)1