-
Notifications
You must be signed in to change notification settings - Fork 3.8k
interval chunk query runner now processes individual chunk in a threadpool #1150
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
processing/src/main/java/io/druid/query/AsyncQueryRunner.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you 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.druid.query; | ||
|
|
||
| import java.util.Map; | ||
| import java.util.concurrent.ExecutionException; | ||
| import java.util.concurrent.ExecutorService; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.concurrent.TimeoutException; | ||
|
|
||
| import com.google.common.base.Supplier; | ||
| import com.google.common.base.Throwables; | ||
| import com.google.common.util.concurrent.ListenableFuture; | ||
| import com.google.common.util.concurrent.ListeningExecutorService; | ||
| import com.google.common.util.concurrent.MoreExecutors; | ||
| import com.metamx.common.guava.LazySequence; | ||
| import com.metamx.common.guava.Sequence; | ||
|
|
||
| public class AsyncQueryRunner<T> implements QueryRunner<T> | ||
| { | ||
|
|
||
| private final QueryRunner<T> baseRunner; | ||
| private final ListeningExecutorService executor; | ||
| private final QueryWatcher queryWatcher; | ||
|
|
||
| public AsyncQueryRunner(QueryRunner<T> baseRunner, ExecutorService executor, QueryWatcher queryWatcher) { | ||
| this.baseRunner = baseRunner; | ||
| this.executor = MoreExecutors.listeningDecorator(executor); | ||
| this.queryWatcher = queryWatcher; | ||
| } | ||
|
|
||
| @Override | ||
| public Sequence<T> run(final Query<T> query, final Map<String, Object> responseContext) | ||
| { | ||
| final int priority = query.getContextPriority(0); | ||
| final ListenableFuture<Sequence<T>> future = executor.submit(new AbstractPrioritizedCallable<Sequence<T>>(priority) | ||
| { | ||
| @Override | ||
| public Sequence<T> call() throws Exception | ||
| { | ||
| //Note: this is assumed that baseRunner does most of the work eagerly on call to the | ||
| //run() method and resulting sequence accumulate/yield is fast. | ||
| return baseRunner.run(query, responseContext); | ||
| } | ||
| }); | ||
| queryWatcher.registerQuery(query, future); | ||
|
|
||
| return new LazySequence<>(new Supplier<Sequence<T>>() | ||
| { | ||
| @Override | ||
| public Sequence<T> get() | ||
| { | ||
| try { | ||
| Number timeout = query.getContextValue(QueryContextKeys.TIMEOUT); | ||
| if (timeout == null) { | ||
| return future.get(); | ||
| } else { | ||
| return future.get(timeout.longValue(), TimeUnit.MILLISECONDS); | ||
| } | ||
| } catch (ExecutionException | InterruptedException | TimeoutException ex) { | ||
| throw Throwables.propagate(ex); | ||
| } | ||
| } | ||
| }); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 49 additions & 0 deletions
49
processing/src/main/java/io/druid/query/IntervalChunkingQueryRunnerDecorator.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,49 @@ | ||
| /* | ||
| * Licensed to Metamarkets Group Inc. (Metamarkets) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. Metamarkets licenses this file | ||
| * to you 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.druid.query; | ||
|
|
||
| import io.druid.guice.annotations.Processing; | ||
|
|
||
| import java.util.concurrent.ExecutorService; | ||
|
|
||
| import com.google.inject.Inject; | ||
| import com.metamx.emitter.service.ServiceEmitter; | ||
|
|
||
| public class IntervalChunkingQueryRunnerDecorator | ||
| { | ||
| private final ExecutorService executor; | ||
| private final QueryWatcher queryWatcher; | ||
| private final ServiceEmitter emitter; | ||
|
|
||
| @Inject | ||
| public IntervalChunkingQueryRunnerDecorator(@Processing ExecutorService executor, QueryWatcher queryWatcher, | ||
| ServiceEmitter emitter) | ||
| { | ||
| this.executor = executor; | ||
| this.queryWatcher = queryWatcher; | ||
| this.emitter = emitter; | ||
| } | ||
|
|
||
| public <T> QueryRunner<T> decorate(QueryRunner<T> delegate, QueryToolChest<T, ? extends Query<T>> toolChest) | ||
| { | ||
| return new IntervalChunkingQueryRunner<T>(delegate, (QueryToolChest<T, Query<T>>)toolChest, | ||
| executor, queryWatcher, emitter); | ||
| } | ||
| } |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you double check the broker docs for druid.processing.numThreads? I think they will need to be updated as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we document how the
chunkPeriodcontext parameter interacts with the existingdruid.query.chunkPeriodanddruid.query.<queryType>.chunkPeriodconfiguration parameter?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually it replaces
druid.query.chunkPeriod, druid.query.<queryType>.chunkPeriod
they are not valid after this pull request. in my experience we found the chunking behavior really needs to be tuned per query [ sometimes based on size of its interval] .
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, can we remove the old configs from docs and code as well, instead of keeping unused config around.