Skip to content

Commit

Permalink
Make default target result size configurable in ExecutingStatementRes…
Browse files Browse the repository at this point in the history
…ource
  • Loading branch information
tooptoop4 committed Mar 5, 2020
1 parent 2a6106d commit a0bfef8
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ protected void setup(Binder binder)
jsonCodecBinder(binder).bindJsonCodec(SelectedRole.class);
configBinder(binder).bindConfig(DispatcherConfig.class);
jaxrsBinder(binder).bind(QueuedStatementResource.class);
configBinder(binder).bindConfig(ExecutingStatementResourceConfig.class);
jaxrsBinder(binder).bind(ExecutingStatementResource.class);
binder.bind(StatementHttpExecutionMBean.class).in(Scopes.SINGLETON);
newExporter(binder).export(StatementHttpExecutionMBean.class).withGeneratedName();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.prestosql.server;

import io.airlift.configuration.Config;
import io.airlift.configuration.ConfigDescription;
import io.airlift.units.DataSize;

import static io.airlift.units.DataSize.Unit.MEGABYTE;

public class ExecutingStatementResourceConfig
{
private DataSize serverTargetResultSize = DataSize.of(1, MEGABYTE);

public DataSize getServerTargetResultSize()
{
return serverTargetResultSize;
}

@Config("query.target-result-size")
@ConfigDescription("Chunk size for query results in JSON responses sent to client")
public ExecutingStatementResourceConfig setServerTargetResultSize(DataSize targetResultSize)
{
this.serverTargetResultSize = targetResultSize;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import io.prestosql.memory.context.SimpleLocalMemoryContext;
import io.prestosql.operator.ExchangeClient;
import io.prestosql.operator.ExchangeClientSupplier;
import io.prestosql.server.ExecutingStatementResourceConfig;
import io.prestosql.server.ForStatementResource;
import io.prestosql.spi.QueryId;
import io.prestosql.spi.block.BlockEncodingSerde;
Expand Down Expand Up @@ -89,9 +90,10 @@ public class ExecutingStatementResource
private static final Duration MAX_WAIT_TIME = new Duration(1, SECONDS);
private static final Ordering<Comparable<Duration>> WAIT_ORDERING = Ordering.natural().nullsLast();

private static final DataSize DEFAULT_TARGET_RESULT_SIZE = DataSize.of(1, MEGABYTE);
private static final DataSize MAX_TARGET_RESULT_SIZE = DataSize.of(128, MEGABYTE);

private final DataSize serverTargetResultSize;

private final QueryManager queryManager;
private final ExchangeClientSupplier exchangeClientSupplier;
private final BlockEncodingSerde blockEncodingSerde;
Expand All @@ -107,13 +109,15 @@ public ExecutingStatementResource(
ExchangeClientSupplier exchangeClientSupplier,
BlockEncodingSerde blockEncodingSerde,
@ForStatementResource BoundedExecutor responseExecutor,
@ForStatementResource ScheduledExecutorService timeoutExecutor)
@ForStatementResource ScheduledExecutorService timeoutExecutor,
ExecutingStatementResourceConfig executingStatementResourceConfig)
{
this.queryManager = requireNonNull(queryManager, "queryManager is null");
this.exchangeClientSupplier = requireNonNull(exchangeClientSupplier, "exchangeClientSupplier is null");
this.blockEncodingSerde = requireNonNull(blockEncodingSerde, "blockEncodingSerde is null");
this.responseExecutor = requireNonNull(responseExecutor, "responseExecutor is null");
this.timeoutExecutor = requireNonNull(timeoutExecutor, "timeoutExecutor is null");
this.serverTargetResultSize = executingStatementResourceConfig.getServerTargetResultSize();

queryPurger.scheduleWithFixedDelay(
() -> {
Expand Down Expand Up @@ -214,7 +218,7 @@ private void asyncQueryResults(
{
Duration wait = WAIT_ORDERING.min(MAX_WAIT_TIME, maxWait);
if (targetResultSize == null) {
targetResultSize = DEFAULT_TARGET_RESULT_SIZE;
targetResultSize = Ordering.natural().min(serverTargetResultSize, MAX_TARGET_RESULT_SIZE);
}
else {
targetResultSize = Ordering.natural().min(targetResultSize, MAX_TARGET_RESULT_SIZE);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.prestosql.server;

import com.google.common.collect.ImmutableMap;
import io.airlift.units.DataSize;
import org.testng.annotations.Test;

import java.util.Map;

import static io.airlift.configuration.testing.ConfigAssertions.assertFullMapping;
import static io.airlift.configuration.testing.ConfigAssertions.assertRecordedDefaults;
import static io.airlift.configuration.testing.ConfigAssertions.recordDefaults;
import static io.airlift.units.DataSize.Unit.MEGABYTE;

public class TestExecutingStatementResourceConfig
{
@Test
public void testDefaults()
{
assertRecordedDefaults(recordDefaults(ExecutingStatementResourceConfig.class)
.setServerTargetResultSize(DataSize.of(1, MEGABYTE)));
}

@Test
public void testExplicitPropertyMappings()
{
Map<String, String> properties = new ImmutableMap.Builder<String, String>()
.put("query.target-result-size", "4MB")
.build();

ExecutingStatementResourceConfig expected = new ExecutingStatementResourceConfig()
.setServerTargetResultSize(DataSize.of(4, MEGABYTE));

assertFullMapping(properties, expected);
}
}

0 comments on commit a0bfef8

Please sign in to comment.