Search in sources :

Example 1 with DEFAULT_MAX_PAGE_SIZE_IN_BYTES

use of com.facebook.presto.common.block.PageBuilderStatus.DEFAULT_MAX_PAGE_SIZE_IN_BYTES in project presto by prestodb.

the class TestExchangeClient method testInitialRequestLimit.

@Test
public void testInitialRequestLimit() {
    DataSize bufferCapacity = new DataSize(16, MEGABYTE);
    DataSize maxResponseSize = new DataSize(DEFAULT_MAX_PAGE_SIZE_IN_BYTES, BYTE);
    CountDownLatch countDownLatch = new CountDownLatch(1);
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize) {

        @Override
        public Response handle(Request request) {
            if (!awaitUninterruptibly(countDownLatch, 10, SECONDS)) {
                throw new UncheckedTimeoutException();
            }
            return super.handle(request);
        }
    };
    List<URI> locations = new ArrayList<>();
    int numLocations = 16;
    List<DataSize> expectedMaxSizes = new ArrayList<>();
    // add pages
    for (int i = 0; i < numLocations; i++) {
        URI location = URI.create("http://localhost:" + (8080 + i));
        locations.add(location);
        processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
        processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
        processor.addPage(location, createPage(DEFAULT_MAX_PAGE_SIZE_IN_BYTES));
        processor.setComplete(location);
        expectedMaxSizes.add(maxResponseSize);
    }
    try (ExchangeClient exchangeClient = createExchangeClient(processor, bufferCapacity, maxResponseSize)) {
        for (int i = 0; i < numLocations; i++) {
            exchangeClient.addLocation(locations.get(i), TaskId.valueOf("taskid.0.0." + i));
        }
        exchangeClient.noMoreLocations();
        assertFalse(exchangeClient.isClosed());
        long start = System.nanoTime();
        countDownLatch.countDown();
        // wait for a page to be fetched
        do {
            // there is no thread coordination here, so sleep is the best we can do
            assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
            sleepUninterruptibly(100, MILLISECONDS);
        } while (exchangeClient.getStatus().getBufferedPages() < 16);
        // Client should have sent 16 requests for a single page (0) and gotten them back
        // The memory limit should be hit immediately and then it doesn't fetch the third page from each
        assertEquals(exchangeClient.getStatus().getBufferedPages(), 16);
        assertTrue(exchangeClient.getStatus().getBufferedBytes() > 0);
        List<PageBufferClientStatus> pageBufferClientStatuses = exchangeClient.getStatus().getPageBufferClientStatuses();
        assertEquals(16, pageBufferClientStatuses.stream().filter(status -> status.getPagesReceived() == 1).mapToInt(PageBufferClientStatus::getPagesReceived).sum());
        assertEquals(processor.getRequestMaxSizes(), expectedMaxSizes);
        for (int i = 0; i < numLocations * 3; i++) {
            assertNotNull(getNextPage(exchangeClient));
        }
        do {
            // there is no thread coordination here, so sleep is the best we can do
            assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
            sleepUninterruptibly(100, MILLISECONDS);
        } while (processor.getRequestMaxSizes().size() < 64);
        for (int i = 0; i < 48; i++) {
            expectedMaxSizes.add(maxResponseSize);
        }
        assertEquals(processor.getRequestMaxSizes(), expectedMaxSizes);
    }
}
Also used : TestingPagesSerdeFactory.testingPagesSerde(com.facebook.presto.execution.buffer.TestingPagesSerdeFactory.testingPagesSerde) Page(com.facebook.presto.common.Page) SerializedPage(com.facebook.presto.spi.page.SerializedPage) Test(org.testng.annotations.Test) Maps.uniqueIndex(com.google.common.collect.Maps.uniqueIndex) BlockAssertions(com.facebook.presto.block.BlockAssertions) Duration(io.airlift.units.Duration) Assertions.assertLessThan(com.facebook.airlift.testing.Assertions.assertLessThan) Uninterruptibles.awaitUninterruptibly(com.google.common.util.concurrent.Uninterruptibles.awaitUninterruptibly) Executors.newScheduledThreadPool(java.util.concurrent.Executors.newScheduledThreadPool) TestingHttpClient(com.facebook.airlift.http.client.testing.TestingHttpClient) Response(com.facebook.airlift.http.client.Response) URI(java.net.URI) Assert.assertFalse(org.testng.Assert.assertFalse) DEFAULT_MAX_PAGE_SIZE_IN_BYTES(com.facebook.presto.common.block.PageBuilderStatus.DEFAULT_MAX_PAGE_SIZE_IN_BYTES) ImmutableMap(com.google.common.collect.ImmutableMap) BeforeClass(org.testng.annotations.BeforeClass) MILLISECONDS(java.util.concurrent.TimeUnit.MILLISECONDS) Assert.assertNotNull(org.testng.Assert.assertNotNull) Uninterruptibles.sleepUninterruptibly(com.google.common.util.concurrent.Uninterruptibles.sleepUninterruptibly) Executors(java.util.concurrent.Executors) MoreExecutors.directExecutor(com.google.common.util.concurrent.MoreExecutors.directExecutor) Threads.daemonThreadsNamed(com.facebook.airlift.concurrent.Threads.daemonThreadsNamed) CountDownLatch(java.util.concurrent.CountDownLatch) DataSize(io.airlift.units.DataSize) List(java.util.List) MoreFutures.tryGetFutureValue(com.facebook.airlift.concurrent.MoreFutures.tryGetFutureValue) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) Assert.assertNull(org.testng.Assert.assertNull) MEGABYTE(io.airlift.units.DataSize.Unit.MEGABYTE) Assert.assertEquals(org.testng.Assert.assertEquals) MINUTES(java.util.concurrent.TimeUnit.MINUTES) PrestoException(com.facebook.presto.spi.PrestoException) Function(java.util.function.Function) Supplier(java.util.function.Supplier) ArrayList(java.util.ArrayList) SimpleLocalMemoryContext(com.facebook.presto.memory.context.SimpleLocalMemoryContext) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) AggregatedMemoryContext.newSimpleAggregatedMemoryContext(com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext) ExecutorService(java.util.concurrent.ExecutorService) AfterClass(org.testng.annotations.AfterClass) TimeUnit(java.util.concurrent.TimeUnit) Futures(com.google.common.util.concurrent.Futures) Executors.newCachedThreadPool(java.util.concurrent.Executors.newCachedThreadPool) Request(com.facebook.airlift.http.client.Request) PagesSerde(com.facebook.presto.spi.page.PagesSerde) TaskId(com.facebook.presto.execution.TaskId) Assert.assertTrue(org.testng.Assert.assertTrue) BYTE(io.airlift.units.DataSize.Unit.BYTE) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Request(com.facebook.airlift.http.client.Request) ArrayList(java.util.ArrayList) UncheckedTimeoutException(com.google.common.util.concurrent.UncheckedTimeoutException) Duration(io.airlift.units.Duration) CountDownLatch(java.util.concurrent.CountDownLatch) URI(java.net.URI) DataSize(io.airlift.units.DataSize) Test(org.testng.annotations.Test)

Aggregations

MoreFutures.tryGetFutureValue (com.facebook.airlift.concurrent.MoreFutures.tryGetFutureValue)1 Threads.daemonThreadsNamed (com.facebook.airlift.concurrent.Threads.daemonThreadsNamed)1 Request (com.facebook.airlift.http.client.Request)1 Response (com.facebook.airlift.http.client.Response)1 TestingHttpClient (com.facebook.airlift.http.client.testing.TestingHttpClient)1 Assertions.assertLessThan (com.facebook.airlift.testing.Assertions.assertLessThan)1 BlockAssertions (com.facebook.presto.block.BlockAssertions)1 Page (com.facebook.presto.common.Page)1 DEFAULT_MAX_PAGE_SIZE_IN_BYTES (com.facebook.presto.common.block.PageBuilderStatus.DEFAULT_MAX_PAGE_SIZE_IN_BYTES)1 TaskId (com.facebook.presto.execution.TaskId)1 TestingPagesSerdeFactory.testingPagesSerde (com.facebook.presto.execution.buffer.TestingPagesSerdeFactory.testingPagesSerde)1 AggregatedMemoryContext.newSimpleAggregatedMemoryContext (com.facebook.presto.memory.context.AggregatedMemoryContext.newSimpleAggregatedMemoryContext)1 SimpleLocalMemoryContext (com.facebook.presto.memory.context.SimpleLocalMemoryContext)1 PrestoException (com.facebook.presto.spi.PrestoException)1 PagesSerde (com.facebook.presto.spi.page.PagesSerde)1 SerializedPage (com.facebook.presto.spi.page.SerializedPage)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Maps.uniqueIndex (com.google.common.collect.Maps.uniqueIndex)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1