-
Notifications
You must be signed in to change notification settings - Fork 4.6k
[Dataflow Streaming] [Multi Key] Introduce KeyGroupWorkQueue and integrate with BoundedQueueExecutor #38767
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
base: master
Are you sure you want to change the base?
[Dataflow Streaming] [Multi Key] Introduce KeyGroupWorkQueue and integrate with BoundedQueueExecutor #38767
Changes from all commits
ad68a3c
5fc07cc
b0f8235
7f7d972
4749b08
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,10 +29,13 @@ | |
| import javax.annotation.concurrent.GuardedBy; | ||
| import org.apache.beam.runners.dataflow.worker.streaming.BoundedQueueExecutorWorkHandle; | ||
| import org.apache.beam.runners.dataflow.worker.streaming.ExecutableWork; | ||
| import org.apache.beam.runners.dataflow.worker.streaming.Work; | ||
| import org.apache.beam.runners.dataflow.worker.streaming.Work.KeyGroup; | ||
| import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.annotations.VisibleForTesting; | ||
| import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.base.Preconditions; | ||
| import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.util.concurrent.Monitor; | ||
| import org.apache.beam.vendor.guava.v32_1_2_jre.com.google.common.util.concurrent.Monitor.Guard; | ||
| import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
|
||
| /** An executor for executing work on windmill items. */ | ||
| @SuppressWarnings({ | ||
|
|
@@ -78,14 +81,19 @@ private static class Budget { | |
| @GuardedBy("this") | ||
| private long totalTimeMaxActiveThreadsUsed; | ||
|
|
||
| // If set the keyGroupWorkQueue is used by the underlying executor. | ||
| private final @Nullable KeyGroupWorkQueue keyGroupWorkQueue; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. add comment,
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done. |
||
|
|
||
| public BoundedQueueExecutor( | ||
| int initialMaximumPoolSize, | ||
| long keepAliveTime, | ||
| TimeUnit unit, | ||
| int maximumElementsOutstanding, | ||
| long maximumBytesOutstanding, | ||
| ThreadFactory threadFactory, | ||
| boolean useFairMonitor) { | ||
| boolean useFairMonitor, | ||
| boolean useKeyGroupWorkQueue) { | ||
| this.keyGroupWorkQueue = useKeyGroupWorkQueue ? new KeyGroupWorkQueue(useFairMonitor) : null; | ||
| this.maximumPoolSize = initialMaximumPoolSize; | ||
| monitor = new Monitor(useFairMonitor); | ||
| executor = | ||
|
|
@@ -94,7 +102,7 @@ public BoundedQueueExecutor( | |
| initialMaximumPoolSize, | ||
| keepAliveTime, | ||
| unit, | ||
| new LinkedBlockingQueue<>(), | ||
| keyGroupWorkQueue != null ? keyGroupWorkQueue : new LinkedBlockingQueue<>(), | ||
| threadFactory) { | ||
| @Override | ||
| protected void beforeExecute(Thread t, Runnable r) { | ||
|
|
@@ -313,7 +321,7 @@ public synchronized void close() { | |
| } | ||
| } | ||
|
|
||
| private static final class QueuedWork implements Runnable { | ||
| static final class QueuedWork implements Runnable { | ||
|
|
||
| private final ExecutableWork work; | ||
| private final BoundedQueueExecutorWorkHandleImpl handle; | ||
|
|
@@ -378,6 +386,22 @@ BoundedQueueExecutorWorkHandleImpl createBudgetHandle(int elements, long bytes) | |
| return new BoundedQueueExecutorWorkHandleImpl(elements, bytes); | ||
| } | ||
|
|
||
| public @Nullable ExecutableWork pollWork( | ||
| String computationId, Work.KeyGroup keyGroup, BoundedQueueExecutorWorkHandle handle) { | ||
|
scwhittle marked this conversation as resolved.
|
||
| checkArgument(handle instanceof BoundedQueueExecutorWorkHandleImpl); | ||
| checkArgument(computationId != null && keyGroup != null && !keyGroup.equals(KeyGroup.DEFAULT)); | ||
| BoundedQueueExecutorWorkHandleImpl internalHandle = (BoundedQueueExecutorWorkHandleImpl) handle; | ||
| if (keyGroupWorkQueue == null) { | ||
| return null; | ||
| } | ||
| QueuedWork queuedWork = keyGroupWorkQueue.pollWork(computationId, keyGroup); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nullable |
||
| if (queuedWork == null) { | ||
| return null; | ||
| } | ||
| internalHandle.merge(queuedWork.getHandle()); | ||
| return queuedWork.getWork(); | ||
| } | ||
|
|
||
| private void decrementCounters(int elements, long bytes) { | ||
| // All threads queue decrements and one thread grabs the monitor and updates | ||
| // counters. We do this to reduce contention on monitor which is locked by | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.