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();
}
}
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;
}
}
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;
}
}
Aggregations