Caideyipi commented on code in PR #16163:
URL: https://github.com/apache/iotdb/pull/16163#discussion_r2271981271


##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/consensus/PipeConsensusSubtaskExecutor.java:
##########
@@ -19,18 +19,25 @@
 package org.apache.iotdb.db.pipe.consensus;
 
 import org.apache.iotdb.commons.concurrent.ThreadName;
-import org.apache.iotdb.commons.pipe.config.PipeConfig;
+import org.apache.iotdb.db.conf.IoTDBDescriptor;
 import org.apache.iotdb.db.pipe.agent.task.execution.PipeSinkSubtaskExecutor;
-
-import java.util.concurrent.atomic.AtomicInteger;
+import org.apache.iotdb.db.storageengine.dataregion.DataRegion;
 
 public class PipeConsensusSubtaskExecutor extends PipeSinkSubtaskExecutor {
-
-  private static final AtomicInteger id = new AtomicInteger(0);
-
   public PipeConsensusSubtaskExecutor() {
     super(
-        PipeConfig.getInstance().getPipeSubtaskExecutorMaxThreadNum(),
-        ThreadName.PIPE_CONSENSUS_EXECUTOR_POOL + "-" + id.getAndIncrement());
+        // The number of data regions for a datanode is limited by 
offHeapMemory. At the same time,
+        // in order to ensure multi-core performance, the number of data 
regions usually does not
+        // exceed the number of cores. To prevent the thread from exploding, 
we take the min of
+        // both.
+        (int)
+            Math.min(
+                Runtime.getRuntime().availableProcessors(),
+                IoTDBDescriptor.getInstance()
+                        .getMemoryConfig()
+                        .getOffHeapMemoryManager()
+                        .getTotalMemorySizeInBytes()
+                    / DataRegion.getAcquireDirectBufferMemCost()),

Review Comment:
   May this be directly configurable?



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/builder/PipeDataNodeTaskBuilder.java:
##########
@@ -118,9 +118,7 @@ public PipeDataNodeTask build() {
               pipeStaticMeta.getCreationTime(),
               connectorParameters,
               regionId,
-              pipeType.equals(PipeType.USER)
-                  ? 
PipeSubtaskExecutorManager.getInstance().getConnectorExecutorSupplier()
-                  : 
PipeSubtaskExecutorManager.getInstance().getConsensusExecutorSupplier());
+              
PipeSubtaskExecutorManager.getInstance().getConnectorExecutorSupplier());

Review Comment:
   Why not write your codes here?



##########
iotdb-core/datanode/src/main/java/org/apache/iotdb/db/pipe/agent/task/stage/PipeTaskSinkStage.java:
##########
@@ -59,7 +61,11 @@ protected void registerSubtask() {
     this.connectorSubtaskId =
         PipeSinkSubtaskManager.instance()
             .register(
-                executor,
+                // IoTV2 uses global singleton executor pool.
+                pipeName.startsWith(PipeStaticMeta.CONSENSUS_PIPE_PREFIX)
+                    ? (PipeSinkSubtaskExecutor)
+                        
IoTV2GlobalComponentContainer.getInstance().getConsensusExecutor()
+                    : executor.get(),

Review Comment:
   Do not get here... A normal sink has an increasing ID, thus you shall only 
get when you really need it



-- 
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]

Reply via email to