Search in sources :

Example 11 with JCQueue

use of org.apache.storm.utils.JCQueue in project storm by apache.

the class BackPressureTrackerTest method testRefreshBackpressureWithEmptyOverflow.

@Test
public void testRefreshBackpressureWithEmptyOverflow() {
    int taskId = 1;
    JCQueue queue = mock(JCQueue.class);
    when(queue.isEmptyOverflow()).thenReturn(true);
    BackPressureTracker tracker = new BackPressureTracker(WORKER_ID, ImmutableMap.of(taskId, queue), new StormMetricRegistry(), ImmutableMap.of(taskId, "component-1"));
    BackpressureState state = tracker.getBackpressureState(taskId);
    tracker.recordBackPressure(state);
    boolean backpressureChanged = tracker.refreshBpTaskList();
    BackPressureStatus status = tracker.getCurrStatus();
    assertThat(backpressureChanged, is(true));
    assertThat(status.workerId, is(WORKER_ID));
    assertThat(status.nonBpTasks, contains(taskId));
}
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 12 with JCQueue

use of org.apache.storm.utils.JCQueue in project storm by apache.

the class BackPressureTrackerTest method testRefreshBackPressureWithNonEmptyOverflow.

@Test
public void testRefreshBackPressureWithNonEmptyOverflow() {
    int taskId = 1;
    JCQueue queue = mock(JCQueue.class);
    when(queue.isEmptyOverflow()).thenReturn(false);
    BackPressureTracker tracker = new BackPressureTracker(WORKER_ID, ImmutableMap.of(taskId, queue), new StormMetricRegistry(), ImmutableMap.of(taskId, "component-1"));
    BackpressureState state = tracker.getBackpressureState(taskId);
    tracker.recordBackPressure(state);
    boolean backpressureChanged = tracker.refreshBpTaskList();
    BackPressureStatus status = tracker.getCurrStatus();
    assertThat(backpressureChanged, is(false));
    assertThat(status.workerId, is(WORKER_ID));
    assertThat(status.bpTasks, contains(taskId));
}
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 13 with JCQueue

use of org.apache.storm.utils.JCQueue 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 14 with JCQueue

use of org.apache.storm.utils.JCQueue in project storm by apache.

the class JCQueuePerfTest method oneProducer2Consumers.

private static void oneProducer2Consumers(int prodBatchSz) {
    WaitStrategyPark ws = new WaitStrategyPark(100);
    StormMetricRegistry registry = new StormMetricRegistry();
    JCQueue q1 = new JCQueue("q1", "q1", 1024, 0, prodBatchSz, ws, "test", "test", Collections.singletonList(1000), 1000, registry);
    JCQueue q2 = new JCQueue("q2", "q2", 1024, 0, prodBatchSz, ws, "test", "test", Collections.singletonList(1000), 1000, registry);
    final Producer2 prod1 = new Producer2(q1, q2);
    final Consumer cons1 = new Consumer(q1);
    final Consumer cons2 = new Consumer(q2);
    runAllThds(prod1, cons1, cons2);
}
Also used : JCQueue(org.apache.storm.utils.JCQueue) WaitStrategyPark(org.apache.storm.policy.WaitStrategyPark) StormMetricRegistry(org.apache.storm.metrics2.StormMetricRegistry)

Example 15 with JCQueue

use of org.apache.storm.utils.JCQueue 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

JCQueue (org.apache.storm.utils.JCQueue)16 StormMetricRegistry (org.apache.storm.metrics2.StormMetricRegistry)13 WaitStrategyPark (org.apache.storm.policy.WaitStrategyPark)7 BackpressureState (org.apache.storm.daemon.worker.BackPressureTracker.BackpressureState)6 BackPressureStatus (org.apache.storm.messaging.netty.BackPressureStatus)6 Test (org.junit.Test)6 HashMap (java.util.HashMap)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 WorkerState (org.apache.storm.daemon.worker.WorkerState)1 WorkerTransfer (org.apache.storm.daemon.worker.WorkerTransfer)1 StormTopology (org.apache.storm.generated.StormTopology)1 IWaitStrategy (org.apache.storm.policy.IWaitStrategy)1 GeneralTopologyContext (org.apache.storm.task.GeneralTopologyContext)1 WorkerTopologyContext (org.apache.storm.task.WorkerTopologyContext)1 AddressedTuple (org.apache.storm.tuple.AddressedTuple)1 Before (org.junit.Before)1