Search in sources :

Example 11 with ConcurrentFramePool

use of org.apache.asterix.common.memory.ConcurrentFramePool in project asterixdb by apache.

the class ConcurrentFramePoolUnitTest method testVarSizeMemoryManager.

@org.junit.Test
public void testVarSizeMemoryManager() {
    try {
        ActiveProperties afp = Mockito.mock(ActiveProperties.class);
        Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET);
        ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE);
        Random random = new Random();
        int i = 0;
        int req;
        while (true) {
            req = random.nextInt(MAX_SIZE) + 1;
            if (req == 1) {
                if (fmm.get() != null) {
                    i += 1;
                } else {
                    break;
                }
            } else if (fmm.get(req * DEFAULT_FRAME_SIZE) != null) {
                i += req;
            } else {
                break;
            }
        }
        Assert.assertEquals(i <= NUM_FRAMES, true);
        Assert.assertEquals(i + req > NUM_FRAMES, true);
        Assert.assertEquals(i + fmm.remaining(), NUM_FRAMES);
    } catch (Throwable th) {
        th.printStackTrace();
        Assert.fail(th.getMessage());
    }
    Assert.assertNull(cause);
}
Also used : ConcurrentFramePool(org.apache.asterix.common.memory.ConcurrentFramePool) Random(java.util.Random) ActiveProperties(org.apache.asterix.common.config.ActiveProperties)

Example 12 with ConcurrentFramePool

use of org.apache.asterix.common.memory.ConcurrentFramePool in project asterixdb by apache.

the class ConcurrentFramePoolUnitTest method testLargerThanBudgetRequests.

@org.junit.Test
public void testLargerThanBudgetRequests() {
    HyracksDataException hde = null;
    try {
        ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", DEFAULT_FRAME_SIZE * 16, DEFAULT_FRAME_SIZE);
        fmm.get(32 * DEFAULT_FRAME_SIZE);
    } catch (HyracksDataException e) {
        hde = e;
    } catch (Throwable th) {
        th.printStackTrace();
        Assert.fail(th.getMessage());
    }
    Assert.assertNotNull(hde);
    Assert.assertNull(cause);
}
Also used : ConcurrentFramePool(org.apache.asterix.common.memory.ConcurrentFramePool) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 13 with ConcurrentFramePool

use of org.apache.asterix.common.memory.ConcurrentFramePool in project asterixdb by apache.

the class ConcurrentFramePoolUnitTest method testConcurrentMemoryManager.

@org.junit.Test
public void testConcurrentMemoryManager() {
    try {
        ActiveProperties afp = Mockito.mock(ActiveProperties.class);
        Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET);
        ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE);
        FixedSizeAllocator[] runners = new FixedSizeAllocator[NUM_THREADS];
        Thread[] threads = new Thread[NUM_THREADS];
        Arrays.parallelSetAll(runners, (int i) -> new FixedSizeAllocator(fmm));
        for (int i = 0; i < threads.length; i++) {
            threads[i] = new Thread(runners[i]);
        }
        for (int i = 0; i < threads.length; i++) {
            threads[i].start();
        }
        for (int i = 0; i < threads.length; i++) {
            threads[i].join();
        }
        int i = 0;
        for (FixedSizeAllocator allocator : runners) {
            i += allocator.getAllocated();
        }
        Assert.assertEquals(NUM_FRAMES, i);
    } catch (Throwable th) {
        th.printStackTrace();
        Assert.fail(th.getMessage());
    }
    Assert.assertNull(cause);
}
Also used : ConcurrentFramePool(org.apache.asterix.common.memory.ConcurrentFramePool) ActiveProperties(org.apache.asterix.common.config.ActiveProperties)

Example 14 with ConcurrentFramePool

use of org.apache.asterix.common.memory.ConcurrentFramePool in project asterixdb by apache.

the class ConcurrentFramePoolUnitTest method testgetWhileSubscribersExist.

@org.junit.Test
public void testgetWhileSubscribersExist() {
    try {
        ActiveProperties afp = Mockito.mock(ActiveProperties.class);
        Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET);
        ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE);
        int i = 0;
        ByteBuffer buffer = ByteBuffer.allocate(DEFAULT_FRAME_SIZE);
        LinkedBlockingDeque<ByteBuffer> buffers = new LinkedBlockingDeque<>();
        FrameAction frameAction = new FrameAction();
        frameAction.setFrame(buffer);
        while (!fmm.subscribe(frameAction)) {
            buffers.put(frameAction.retrieve());
            i++;
        }
        // One subscriber.
        // Check that all frames have been consumed
        Assert.assertEquals(i, NUM_FRAMES);
        // Release a frame (That will be handed out to the subscriber)
        fmm.release(buffers.take());
        // Check that all frames have been consumed (since the released frame have been handed to the consumer)
        Assert.assertEquals(fmm.remaining(), 0);
        buffers.put(frameAction.retrieve());
        // Create another subscriber that takes frames of double the size
        ByteBuffer bufferTimes2 = ByteBuffer.allocate(DEFAULT_FRAME_SIZE * 2);
        LinkedBlockingDeque<ByteBuffer> buffersTimes2 = new LinkedBlockingDeque<>();
        FrameAction frameActionTimes2 = new FrameAction();
        frameActionTimes2.setFrame(bufferTimes2);
        Assert.assertEquals(true, fmm.subscribe(frameActionTimes2));
        // release a small one
        fmm.release(buffers.take());
        Assert.assertEquals(fmm.remaining(), 1);
        // Check that a small get fails
        Assert.assertEquals(null, fmm.get());
        // release another small one
        fmm.release(buffers.take());
        // Check that no small frames exists in the pool since subscriber request was satisfied
        Assert.assertEquals(fmm.remaining(), 0);
        buffersTimes2.add(frameActionTimes2.retrieve());
        fmm.release(buffers);
        fmm.release(bufferTimes2);
        Assert.assertEquals(fmm.remaining(), NUM_FRAMES);
    } catch (Throwable th) {
        th.printStackTrace();
        Assert.fail(th.getMessage());
    } finally {
        Assert.assertNull(cause);
    }
}
Also used : ConcurrentFramePool(org.apache.asterix.common.memory.ConcurrentFramePool) LinkedBlockingDeque(java.util.concurrent.LinkedBlockingDeque) ActiveProperties(org.apache.asterix.common.config.ActiveProperties) FrameAction(org.apache.asterix.common.memory.FrameAction) ByteBuffer(java.nio.ByteBuffer)

Example 15 with ConcurrentFramePool

use of org.apache.asterix.common.memory.ConcurrentFramePool in project asterixdb by apache.

the class ConcurrentFramePoolUnitTest method testMemoryManager.

@org.junit.Test
public void testMemoryManager() {
    ActiveProperties afp = Mockito.mock(ActiveProperties.class);
    Mockito.when(afp.getMemoryComponentGlobalBudget()).thenReturn(FEED_MEM_BUDGET);
    ConcurrentFramePool fmm = new ConcurrentFramePool("TestNode", afp.getMemoryComponentGlobalBudget(), DEFAULT_FRAME_SIZE);
    int i = 0;
    while (fmm.get() != null) {
        i++;
    }
    Assert.assertEquals(i, NUM_FRAMES);
    Assert.assertNull(cause);
}
Also used : ConcurrentFramePool(org.apache.asterix.common.memory.ConcurrentFramePool) ActiveProperties(org.apache.asterix.common.config.ActiveProperties)

Aggregations

ConcurrentFramePool (org.apache.asterix.common.memory.ConcurrentFramePool)24 FeedRuntimeInputHandler (org.apache.asterix.external.feed.dataflow.FeedRuntimeInputHandler)12 FeedPolicyAccessor (org.apache.asterix.external.feed.policy.FeedPolicyAccessor)12 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)12 Test (org.junit.Test)12 ByteBuffer (java.nio.ByteBuffer)10 ActiveProperties (org.apache.asterix.common.config.ActiveProperties)10 TestControlledFrameWriter (org.apache.hyracks.api.test.TestControlledFrameWriter)8 Random (java.util.Random)7 VSizeFrame (org.apache.hyracks.api.comm.VSizeFrame)7 TestFrameWriter (org.apache.hyracks.api.test.TestFrameWriter)4 FrameAction (org.apache.asterix.common.memory.FrameAction)3 ArrayDeque (java.util.ArrayDeque)2 LinkedBlockingDeque (java.util.concurrent.LinkedBlockingDeque)2 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)2