Search in sources :

Example 1 with ExpressionProfiler

use of com.facebook.presto.sql.gen.ExpressionProfiler in project presto by prestodb.

the class TestPageProcessor method testExpressionProfiler.

@Test
public void testExpressionProfiler() {
    MetadataManager metadata = createTestMetadataManager();
    CallExpression add10Expression = call(ADD.name(), metadata.getFunctionAndTypeManager().resolveOperator(ADD, fromTypes(BIGINT, BIGINT)), BIGINT, field(0, BIGINT), constant(10L, BIGINT));
    TestingTicker testingTicker = new TestingTicker();
    PageFunctionCompiler functionCompiler = new PageFunctionCompiler(metadata, 0);
    Supplier<PageProjection> projectionSupplier = functionCompiler.compileProjection(SESSION.getSqlFunctionProperties(), add10Expression, Optional.empty());
    PageProjection projection = projectionSupplier.get();
    Page page = new Page(createLongSequenceBlock(1, 11));
    ExpressionProfiler profiler = new ExpressionProfiler(testingTicker, SPLIT_RUN_QUANTA);
    for (int i = 0; i < 100; i++) {
        profiler.start();
        Work<List<Block>> work = projection.project(SESSION.getSqlFunctionProperties(), new DriverYieldSignal(), page, SelectedPositions.positionsRange(0, page.getPositionCount()));
        if (i < 10) {
            // increment the ticker with a large value to mark the expression as expensive
            testingTicker.increment(10, SECONDS);
            profiler.stop(page.getPositionCount());
            assertTrue(profiler.isExpressionExpensive());
        } else {
            testingTicker.increment(0, NANOSECONDS);
            profiler.stop(page.getPositionCount());
            assertFalse(profiler.isExpressionExpensive());
        }
        work.process();
    }
}
Also used : MetadataManager(com.facebook.presto.metadata.MetadataManager) MetadataManager.createTestMetadataManager(com.facebook.presto.metadata.MetadataManager.createTestMetadataManager) TestingTicker(com.facebook.airlift.testing.TestingTicker) PageFunctionCompiler(com.facebook.presto.sql.gen.PageFunctionCompiler) DriverYieldSignal(com.facebook.presto.operator.DriverYieldSignal) Page(com.facebook.presto.common.Page) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) SelectedPositions.positionsList(com.facebook.presto.operator.project.SelectedPositions.positionsList) CallExpression(com.facebook.presto.spi.relation.CallExpression) ExpressionProfiler(com.facebook.presto.sql.gen.ExpressionProfiler) Test(org.testng.annotations.Test)

Example 2 with ExpressionProfiler

use of com.facebook.presto.sql.gen.ExpressionProfiler in project presto by prestodb.

the class TestPageProcessor method testIncreasingBatchSize.

@Test
public void testIncreasingBatchSize() {
    int rows = 1024;
    // We deliberately do not set the ticker, so that the expression is always cheap and the batch size gets doubled until other limits are hit
    TestingTicker testingTicker = new TestingTicker();
    ExpressionProfiler profiler = new ExpressionProfiler(testingTicker, SPLIT_RUN_QUANTA);
    PageProcessor pageProcessor = new PageProcessor(Optional.empty(), ImmutableList.of(createInputPageProjectionWithOutputs(0, BIGINT, 0)), OptionalInt.of(1), profiler);
    Slice[] slices = new Slice[rows];
    Arrays.fill(slices, Slices.allocate(rows));
    Page inputPage = new Page(createSlicesBlock(slices));
    Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, inputPage);
    long previousPositionCount = 1;
    long totalPositionCount = 0;
    while (totalPositionCount < rows) {
        Optional<Page> page = output.next();
        assertTrue(page.isPresent());
        long positionCount = page.get().getPositionCount();
        totalPositionCount += positionCount;
        // skip the first read && skip the last read, which can be a partial page
        if (positionCount > 1 && totalPositionCount != rows) {
            assertEquals(positionCount, previousPositionCount * 2);
        }
        previousPositionCount = positionCount;
    }
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) Optional(java.util.Optional) Slice(io.airlift.slice.Slice) Page(com.facebook.presto.common.Page) ExpressionProfiler(com.facebook.presto.sql.gen.ExpressionProfiler) Test(org.testng.annotations.Test)

Example 3 with ExpressionProfiler

use of com.facebook.presto.sql.gen.ExpressionProfiler in project presto by prestodb.

the class TestPageProcessor method testDecreasingBatchSize.

@Test
public void testDecreasingBatchSize() {
    int rows = 1024;
    // We set the expensive expression threshold to 0, so the expression is always considered expensive and the batch size gets halved until it becomes 1
    TestingTicker testingTicker = new TestingTicker();
    ExpressionProfiler profiler = new ExpressionProfiler(testingTicker, new Duration(0, MILLISECONDS));
    PageProcessor pageProcessor = new PageProcessor(Optional.empty(), ImmutableList.of(createInputPageProjectionWithOutputs(0, BIGINT, 0)), OptionalInt.of(512), profiler);
    Slice[] slices = new Slice[rows];
    Arrays.fill(slices, Slices.allocate(rows));
    Page inputPage = new Page(createSlicesBlock(slices));
    Iterator<Optional<Page>> output = processAndAssertRetainedPageSize(pageProcessor, inputPage);
    long previousPositionCount = 1;
    long totalPositionCount = 0;
    while (totalPositionCount < rows) {
        Optional<Page> page = output.next();
        assertTrue(page.isPresent());
        long positionCount = page.get().getPositionCount();
        totalPositionCount += positionCount;
        // the batch size doesn't get smaller than 1
        if (positionCount > 1 && previousPositionCount != 1) {
            assertEquals(positionCount, previousPositionCount / 2);
        }
        previousPositionCount = positionCount;
    }
}
Also used : TestingTicker(com.facebook.airlift.testing.TestingTicker) Optional(java.util.Optional) Slice(io.airlift.slice.Slice) Duration(io.airlift.units.Duration) Page(com.facebook.presto.common.Page) ExpressionProfiler(com.facebook.presto.sql.gen.ExpressionProfiler) Test(org.testng.annotations.Test)

Aggregations

TestingTicker (com.facebook.airlift.testing.TestingTicker)3 Page (com.facebook.presto.common.Page)3 ExpressionProfiler (com.facebook.presto.sql.gen.ExpressionProfiler)3 Test (org.testng.annotations.Test)3 Slice (io.airlift.slice.Slice)2 Optional (java.util.Optional)2 MetadataManager (com.facebook.presto.metadata.MetadataManager)1 MetadataManager.createTestMetadataManager (com.facebook.presto.metadata.MetadataManager.createTestMetadataManager)1 DriverYieldSignal (com.facebook.presto.operator.DriverYieldSignal)1 SelectedPositions.positionsList (com.facebook.presto.operator.project.SelectedPositions.positionsList)1 CallExpression (com.facebook.presto.spi.relation.CallExpression)1 PageFunctionCompiler (com.facebook.presto.sql.gen.PageFunctionCompiler)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Duration (io.airlift.units.Duration)1 List (java.util.List)1