Search in sources :

Example 6 with SimpleLocalMemoryContext

use of io.prestosql.memory.context.SimpleLocalMemoryContext in project hetu-core by openlookeng.

the class TestExchangeClient method testBufferLimit.

@Test
public void testBufferLimit() {
    DataSize maxResponseSize = new DataSize(1, Unit.BYTE);
    MockExchangeRequestProcessor processor = new MockExchangeRequestProcessor(maxResponseSize);
    URI location = URI.create("http://localhost:8080");
    String instanceId = "testing instance id";
    // add a pages
    processor.addPage(location, createPage(1));
    processor.addPage(location, createPage(2));
    processor.addPage(location, createPage(3));
    processor.setComplete(location);
    @SuppressWarnings("resource") ExchangeClient exchangeClient = new ExchangeClient(new DataSize(1, Unit.BYTE), maxResponseSize, 1, new Duration(1, TimeUnit.MINUTES), true, new TestingHttpClient(processor, newCachedThreadPool(daemonThreadsNamed("test-%s"))), scheduler, new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), pageBufferClientCallbackExecutor, new NoOpFailureDetector());
    exchangeClient.addLocation(new TaskLocation(location, instanceId));
    exchangeClient.noMoreLocations();
    assertEquals(exchangeClient.isClosed(), false);
    long start = System.nanoTime();
    // start fetching pages
    exchangeClient.scheduleRequestIfNecessary();
    // 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() == 0);
    // client should have sent a single request for a single page
    assertEquals(exchangeClient.getStatus().getBufferedPages(), 1);
    assertTrue(exchangeClient.getStatus().getBufferedBytes() > 0);
    assertStatus(exchangeClient.getStatus().getPageBufferClientStatuses().get(0), location, "queued", 1, 1, 1, "not scheduled");
    // remove the page and wait for the client to fetch another page
    assertPageEquals(exchangeClient.pollPage(null).getLeft(), createPage(1));
    do {
        assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
        sleepUninterruptibly(100, MILLISECONDS);
    } while (exchangeClient.getStatus().getBufferedPages() == 0);
    // client should have sent a single request for a single page
    assertStatus(exchangeClient.getStatus().getPageBufferClientStatuses().get(0), location, "queued", 2, 2, 2, "not scheduled");
    assertEquals(exchangeClient.getStatus().getBufferedPages(), 1);
    assertTrue(exchangeClient.getStatus().getBufferedBytes() > 0);
    // remove the page and wait for the client to fetch another page
    assertPageEquals(exchangeClient.pollPage(null).getLeft(), createPage(2));
    do {
        assertLessThan(Duration.nanosSince(start), new Duration(5, TimeUnit.SECONDS));
        sleepUninterruptibly(100, MILLISECONDS);
    } while (exchangeClient.getStatus().getBufferedPages() == 0);
    // client should have sent a single request for a single page
    assertStatus(exchangeClient.getStatus().getPageBufferClientStatuses().get(0), location, "queued", 3, 3, 3, "not scheduled");
    assertEquals(exchangeClient.getStatus().getBufferedPages(), 1);
    assertTrue(exchangeClient.getStatus().getBufferedBytes() > 0);
    // remove last page
    assertPageEquals(getNextPage(exchangeClient), createPage(3));
    // wait for client to decide there are no more pages
    assertNull(getNextPage(exchangeClient));
    assertEquals(exchangeClient.getStatus().getBufferedPages(), 0);
    assertTrue(exchangeClient.getStatus().getBufferedBytes() == 0);
    assertEquals(exchangeClient.isClosed(), true);
    assertStatus(exchangeClient.getStatus().getPageBufferClientStatuses().get(0), location, "closed", 3, 5, 5, "not scheduled");
}
Also used : NoOpFailureDetector(io.prestosql.failuredetector.NoOpFailureDetector) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) DataSize(io.airlift.units.DataSize) TestingHttpClient(io.airlift.http.client.testing.TestingHttpClient) Duration(io.airlift.units.Duration) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 7 with SimpleLocalMemoryContext

use of io.prestosql.memory.context.SimpleLocalMemoryContext in project hetu-core by openlookeng.

the class TestArbitraryOutputBuffer method createArbitraryBuffer.

private ArbitraryOutputBuffer createArbitraryBuffer(OutputBuffers buffers, DataSize dataSize) {
    ArbitraryOutputBuffer buffer = new ArbitraryOutputBuffer(new StateMachine<>("bufferState", stateNotificationExecutor, OPEN, TERMINAL_BUFFER_STATES), dataSize, () -> new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), stateNotificationExecutor);
    buffer.setOutputBuffers(buffers);
    return buffer;
}
Also used : SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext)

Example 8 with SimpleLocalMemoryContext

use of io.prestosql.memory.context.SimpleLocalMemoryContext in project hetu-core by openlookeng.

the class TestBroadcastOutputBuffer method createBroadcastBuffer.

private BroadcastOutputBuffer createBroadcastBuffer(OutputBuffers outputBuffers, DataSize dataSize) {
    BroadcastOutputBuffer buffer = new BroadcastOutputBuffer(new StateMachine<>("bufferState", stateNotificationExecutor, OPEN, TERMINAL_BUFFER_STATES), dataSize, () -> new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), stateNotificationExecutor);
    buffer.setOutputBuffers(outputBuffers);
    return buffer;
}
Also used : SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext)

Example 9 with SimpleLocalMemoryContext

use of io.prestosql.memory.context.SimpleLocalMemoryContext in project hetu-core by openlookeng.

the class TestArbitraryOutputBuffer method createOutputBuffer.

private OutputBuffer createOutputBuffer(OutputBuffers.BufferType bufferType) {
    OutputBuffers buffers = createInitialEmptyOutputBuffers(bufferType).withBuffer(FIRST, BROADCAST_PARTITION_ID).withNoMoreBufferIds();
    OutputBuffer buffer;
    switch(bufferType) {
        case ARBITRARY:
            buffer = new ArbitraryOutputBuffer(new StateMachine<>("bufferState", stateNotificationExecutor, OPEN, TERMINAL_BUFFER_STATES), sizeOfPages(5), () -> new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), stateNotificationExecutor);
            buffer.setOutputBuffers(buffers);
            break;
        case BROADCAST:
            buffer = new BroadcastOutputBuffer(new StateMachine<>("bufferState", stateNotificationExecutor, OPEN, TERMINAL_BUFFER_STATES), sizeOfPages(5), () -> new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), stateNotificationExecutor);
            buffer.setOutputBuffers(buffers);
            break;
        case PARTITIONED:
            buffer = new PartitionedOutputBuffer(new StateMachine<>("bufferState", stateNotificationExecutor, OPEN, TERMINAL_BUFFER_STATES), buffers, sizeOfPages(5), () -> new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), "test"), stateNotificationExecutor);
            break;
        default:
            throw new RuntimeException("Unexpected bufferType: " + bufferType);
    }
    return buffer;
}
Also used : OutputBuffers.createInitialEmptyOutputBuffers(io.prestosql.execution.buffer.OutputBuffers.createInitialEmptyOutputBuffers) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) StateMachine(io.prestosql.execution.StateMachine)

Example 10 with SimpleLocalMemoryContext

use of io.prestosql.memory.context.SimpleLocalMemoryContext in project hetu-core by openlookeng.

the class PagePublisherQueryRunner method getQuery.

private Query getQuery(QueryId queryId, String slug) {
    // this is the first time the query has been accessed on this coordinator
    Session session;
    try {
        if (!queryManager.isQuerySlugValid(queryId, slug)) {
            throw badRequest(NOT_FOUND, "Query not found");
        }
        session = queryManager.getQuerySession(queryId);
    } catch (NoSuchElementException e) {
        throw badRequest(NOT_FOUND, "Query not found");
    }
    ExchangeClient exchangeClient = this.exchangeClientSupplier.get(new SimpleLocalMemoryContext(newSimpleAggregatedMemoryContext(), DataCenterStatementResource.class.getSimpleName()));
    return Query.create(session, slug, queryManager, exchangeClient, executor, timeoutExecutor, blockEncodingSerde);
}
Also used : ExchangeClient(io.prestosql.operator.ExchangeClient) SimpleLocalMemoryContext(io.prestosql.memory.context.SimpleLocalMemoryContext) NoSuchElementException(java.util.NoSuchElementException) Session(io.prestosql.Session)

Aggregations

SimpleLocalMemoryContext (io.prestosql.memory.context.SimpleLocalMemoryContext)13 DataSize (io.airlift.units.DataSize)8 Duration (io.airlift.units.Duration)7 TestingHttpClient (io.airlift.http.client.testing.TestingHttpClient)6 NoOpFailureDetector (io.prestosql.failuredetector.NoOpFailureDetector)6 Test (org.testng.annotations.Test)6 URI (java.net.URI)5 Session (io.prestosql.Session)3 ExchangeClient (io.prestosql.operator.ExchangeClient)3 QueryId (io.prestosql.spi.QueryId)3 OutputBuffers.createInitialEmptyOutputBuffers (io.prestosql.execution.buffer.OutputBuffers.createInitialEmptyOutputBuffers)2 MarkerPage (io.prestosql.spi.snapshot.MarkerPage)2 NoSuchElementException (java.util.NoSuchElementException)2 Strings.isNullOrEmpty (com.google.common.base.Strings.isNullOrEmpty)1 Ordering (com.google.common.collect.Ordering)1 X_FORWARDED_PROTO (com.google.common.net.HttpHeaders.X_FORWARDED_PROTO)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 MoreExecutors.directExecutor (com.google.common.util.concurrent.MoreExecutors.directExecutor)1 BoundedExecutor (io.airlift.concurrent.BoundedExecutor)1