Search in sources :

Example 6 with BackPressureStatus

use of org.apache.storm.messaging.netty.BackPressureStatus in project storm by apache.

the class BackPressureTrackerTest method testSetBackpressure.

@Test
public void testSetBackpressure() {
    int taskIdNoBackPressure = 1;
    JCQueue noBackPressureQueue = mock(JCQueue.class);
    int taskIdBackPressure = 2;
    JCQueue backPressureQueue = mock(JCQueue.class);
    BackPressureTracker tracker = new BackPressureTracker(WORKER_ID, ImmutableMap.of(taskIdNoBackPressure, noBackPressureQueue, taskIdBackPressure, backPressureQueue), new StormMetricRegistry(), ImmutableMap.of(taskIdNoBackPressure, "NoBackPressureComponent", taskIdBackPressure, "BackPressureComponent"));
    BackpressureState state = tracker.getBackpressureState(taskIdBackPressure);
    boolean backpressureChanged = tracker.recordBackPressure(state);
    BackPressureStatus status = tracker.getCurrStatus();
    assertThat(backpressureChanged, is(true));
    assertThat(status.workerId, is(WORKER_ID));
    assertThat(status.nonBpTasks, contains(taskIdNoBackPressure));
    assertThat(status.bpTasks, contains(taskIdBackPressure));
}
Also used : JCQueue(org.apache.storm.utils.JCQueue) BackpressureState(org.apache.storm.daemon.worker.BackPressureTracker.BackpressureState) BackPressureStatus(org.apache.storm.messaging.netty.BackPressureStatus) StormMetricRegistry(org.apache.storm.metrics2.StormMetricRegistry) Test(org.junit.Test)

Example 7 with BackPressureStatus

use of org.apache.storm.messaging.netty.BackPressureStatus 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

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