gianm commented on code in PR #12848:
URL: https://github.com/apache/druid/pull/12848#discussion_r936242610


##########
processing/src/main/java/org/apache/druid/frame/processor/FrameProcessorExecutor.java:
##########
@@ -0,0 +1,602 @@
+/*
+ * 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.frame.processor;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.SettableFuture;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
+import it.unimi.dsi.fastutil.ints.IntSet;
+import org.apache.druid.frame.channel.ReadableFrameChannel;
+import org.apache.druid.frame.channel.WritableFrameChannel;
+import org.apache.druid.java.util.common.Either;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.guava.Sequence;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.common.logger.Logger;
+
+import javax.annotation.Nullable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.function.BiFunction;
+import java.util.stream.Collectors;
+
+/**
+ * Manages execution of {@link FrameProcessor} in an {@link ExecutorService}.
+ *
+ * If you want single threaded execution, use {@code Execs.singleThreaded()}. 
It is not a good idea to use this with a
+ * same-thread executor like {@code Execs.directExecutor()}, because it will 
lead to deep call stacks.
+ */
+public class FrameProcessorExecutor

Review Comment:
   > The thought is that, in a busy node, there may be many concurrent 
fragments (queries) running, and the ideal is that a single runtime manages all 
of them to ensure fair scheduling across routines, rather than each clump of 
routines doing its own scheduling.
   
   Yeah this is exactly the idea. This class (the FrameProcessorExecutor) is 
that runtime. There would be one per JVM, shared across all concurrent work 
being done in that JVM. In that regard it's similar to the QueryProcessingPool 
that exists on Historicals.
   
   > If so, then a) is there some library that exists that does this already? 
And, b) can this be generalized so it works not just with frame processors, but 
with all manner of "go-routine-like" objects?
   
   As to (a) I did find some libraries doing similar things for Java, but I 
didn't see one that looked like it was widely adopted. The other Java-based 
data systems, to the degree that they use an approach like this, seem to each 
be doing their own thing.
   
   As to (b), yes, we could generalize: channels could be able to send and 
receive things other than frames. That would actually work just fine. Nothing 
about them is really specific to frames. I just didn't have a use case in mind 
that required such generalization.



##########
processing/src/main/java/org/apache/druid/frame/processor/FrameProcessorExecutor.java:
##########
@@ -0,0 +1,602 @@
+/*
+ * 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.frame.processor;
+
+import com.google.common.annotations.VisibleForTesting;
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Multimaps;
+import com.google.common.collect.SetMultimap;
+import com.google.common.collect.Sets;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.SettableFuture;
+import com.google.errorprone.annotations.concurrent.GuardedBy;
+import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
+import it.unimi.dsi.fastutil.ints.IntSet;
+import org.apache.druid.frame.channel.ReadableFrameChannel;
+import org.apache.druid.frame.channel.WritableFrameChannel;
+import org.apache.druid.java.util.common.Either;
+import org.apache.druid.java.util.common.StringUtils;
+import org.apache.druid.java.util.common.concurrent.Execs;
+import org.apache.druid.java.util.common.guava.Sequence;
+import org.apache.druid.java.util.common.io.Closer;
+import org.apache.druid.java.util.common.logger.Logger;
+
+import javax.annotation.Nullable;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.IdentityHashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.Optional;
+import java.util.Set;
+import java.util.concurrent.ExecutorService;
+import java.util.function.BiFunction;
+import java.util.stream.Collectors;
+
+/**
+ * Manages execution of {@link FrameProcessor} in an {@link ExecutorService}.
+ *
+ * If you want single threaded execution, use {@code Execs.singleThreaded()}. 
It is not a good idea to use this with a
+ * same-thread executor like {@code Execs.directExecutor()}, because it will 
lead to deep call stacks.
+ */
+public class FrameProcessorExecutor

Review Comment:
   > The thought is that, in a busy node, there may be many concurrent 
fragments (queries) running, and the ideal is that a single runtime manages all 
of them to ensure fair scheduling across routines, rather than each clump of 
routines doing its own scheduling.
   
   Yeah this is exactly the idea. This class (the FrameProcessorExecutor) is 
that runtime. There would be one per JVM, shared across all concurrent work 
being done in that JVM. In that regard it's similar to the QueryProcessingPool 
that exists on Historicals.
   
   > If so, then a) is there some library that exists that does this already? 
And, b) can this be generalized so it works not just with frame processors, but 
with all manner of "go-routine-like" objects?
   
   As to (a) I did find some libraries doing similar things for Java, but I 
didn't see one that looked like it was widely adopted. The other Java-based 
data systems, to the degree that they use an approach like this, seem to each 
be doing their own thing.
   
   As to (b), yes, we could generalize: channels could be able to send and 
receive things other than frames. That would work just fine. Nothing about them 
is really specific to frames. I just didn't have a use case in mind that 
required such generalization.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to