drcrallen commented on a change in pull request #6629: Add support parallel 
combine in brokers
URL: https://github.com/apache/incubator-druid/pull/6629#discussion_r240794271
 
 

 ##########
 File path: 
core/src/main/java/org/apache/druid/java/util/common/guava/ParallelMergeCombineSequence.java
 ##########
 @@ -0,0 +1,315 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF 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 org.apache.druid.java.util.common.guava;
+
+import com.google.common.collect.Ordering;
+import org.apache.druid.collections.ReferenceCountingResourceHolder;
+import org.apache.druid.java.util.common.ISE;
+import org.apache.druid.java.util.common.Pair;
+import org.apache.druid.java.util.common.guava.BaseSequence.IteratorMaker;
+import org.apache.druid.java.util.common.guava.nary.BinaryFn;
+import org.apache.druid.query.ParallelCombines;
+import org.apache.druid.query.PrioritizedRunnable;
+import org.apache.druid.query.ThreadResource;
+
+import javax.annotation.Nullable;
+import java.util.Iterator;
+import java.util.List;
+import java.util.NoSuchElementException;
+import java.util.concurrent.ArrayBlockingQueue;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.TimeoutException;
+import java.util.function.Supplier;
+import java.util.stream.IntStream;
+
+/**
+ * This sequence merges underlying {@link #baseSequences} and combines 
(aggregates) them in parallel.
+ * It creates a tree to merge and combine input streams in parallel, 
consisting of processing threads connected by
+ * blocking queues. In leaf nodes, the processing threads combines values from 
the {@link #baseSequences} and stores
+ * aggregates in its blocking queue. Intermediate threads reads values from 
the blocking queue of their children and
+ * stores computed aggregates its blocking queue. Finally, the caller thread 
of this class (usually it's an http thread
+ * in query processing) reads values from the queue of the root thread. 
Filling blocking queue and reading from it are
+ * done asynchronously.
+ */
+public class ParallelMergeCombineSequence<T> extends YieldingSequenceBase<T>
+{
+  private static final int MINIMUM_LEAF_COMBINE_DEGREE = 2;
 
 Review comment:
   it is possible this is too aggressive. For example, merging 16 in series vs 
merging 8x2, 4x2, 2x2 and a final may not be worth it compared to simply 
merging 16. In my own tests I found simply splitting to serial groups of 100, 
and doing a serial merge on the groups, worked pretty darn well. That's only 
two levels of merging.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to