wanglijie95 commented on a change in pull request #18376:
URL: https://github.com/apache/flink/pull/18376#discussion_r790425616



##########
File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/SsgNetworkMemoryCalculationUtils.java
##########
@@ -148,6 +161,78 @@ private static TaskInputsOutputsDescriptor 
buildTaskInputsOutputsDescriptor(
         return ret;
     }
 
+    private static Map<IntermediateDataSetID, Integer> 
getMaxInputChannelNumsForDynamicGraph(
+            ExecutionJobVertex ejv) {
+
+        Map<IntermediateDataSetID, Integer> ret = new HashMap<>();
+        for (IntermediateResult consumedResult : ejv.getInputs()) {
+            ret.put(consumedResult.getId(), 
getMaxInputChannelNumForResult(ejv, consumedResult));
+        }
+
+        return ret;
+    }
+
+    private static Map<IntermediateDataSetID, Integer> 
getMaxSubpartitionNumsForDynamicGraph(
+            ExecutionJobVertex ejv) {
+
+        Map<IntermediateDataSetID, Integer> ret = new HashMap<>();
+
+        for (IntermediateResult intermediateResult : 
ejv.getProducedDataSets()) {
+            final int maxNum =
+                    Arrays.stream(intermediateResult.getPartitions())
+                            
.map(IntermediateResultPartition::getNumberOfSubpartitions)
+                            .reduce(0, Integer::max);
+            ret.put(intermediateResult.getId(), maxNum);
+        }
+
+        return ret;
+    }
+
+    @VisibleForTesting
+    static int getMaxInputChannelNumForResult(
+            ExecutionJobVertex ejv, IntermediateResult consumedResult) {
+        DistributionPattern distributionPattern = 
consumedResult.getConsumingDistributionPattern();
+
+        if (distributionPattern == DistributionPattern.ALL_TO_ALL) {
+            int numChannelsToConsumePerPartition =
+                    
getMaxNumOfChannelsForConsuming(consumedResult.getPartitions()[0]);
+            int numConsumedPartitions = 
consumedResult.getNumberOfAssignedPartitions();
+            return numChannelsToConsumePerPartition * numConsumedPartitions;
+
+        } else if (distributionPattern == DistributionPattern.POINTWISE) {
+            int numPartitions = consumedResult.getNumberOfAssignedPartitions();
+            int numConsumers = ejv.getParallelism();
+            // when using dynamic graph, all partitions have the same number 
of subpartitions

Review comment:
       > e.g. if later someone tried to optimized 
`IntermediateResultPartition#computeNumberOfSubpartitions()` to avoid creating 
extra subpartitions if the parallelism of the downstream vertex is known 
already, this assumption may break. However, he/she may not be aware of the 
changes here the assumption here may stay unchanged.
   
   You are right. I will change it to use 
`TaskDeploymentDescriptorFactory#computeConsumedSubpartitionRange` to compute 
subpartition range for each consumer, and then calculate the max number of 
channels according to the subpartition range.




-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to