Search in sources :

Example 1 with ConcurrentFramePool

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

the class ConcurrentFramePoolUnitTest method testConcurrentAcquireReleaseMemoryManager.

@org.junit.Test
public void testConcurrentAcquireReleaseMemoryManager() {
    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);
        FixedSizeGoodAllocator[] runners = new FixedSizeGoodAllocator[NUM_THREADS];
        Thread[] threads = new Thread[NUM_THREADS];
        Arrays.parallelSetAll(runners, (int i) -> new FixedSizeGoodAllocator(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 (FixedSizeGoodAllocator 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 2 with ConcurrentFramePool

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

the class ConcurrentFramePoolUnitTest method testFixedSizeSubscribtion.

@org.junit.Test
public void testFixedSizeSubscribtion() {
    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(0, fmm.remaining());
    } 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 3 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 4 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 5 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)

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