zhuzhurk commented on a change in pull request #10462: [FLINK-15031][runtime] 
Calculate required shuffle memory before allocating slots if resources are 
specified
URL: https://github.com/apache/flink/pull/10462#discussion_r355121570
 
 

 ##########
 File path: 
flink-runtime/src/main/java/org/apache/flink/runtime/shuffle/NettyShuffleMaster.java
 ##########
 @@ -68,4 +77,19 @@ private static PartitionConnectionInfo createConnectionInfo(
                        
NetworkPartitionConnectionInfo.fromProducerDescriptor(producerDescriptor, 
connectionIndex) :
                        LocalExecutionPartitionConnectionInfo.INSTANCE;
        }
+
+       @Override
+       public MemorySize getShuffleMemoryForTask(final 
TaskInputsOutputsDescriptor taskInputsOutputsDescriptor) {
+               // each input channel will retain N exclusive network buffers, 
N = buffersPerInputChannel
+               final int inputBuffers = networkBuffersPerInputChannel * 
taskInputsOutputsDescriptor.getTotalNumberOfInputChannels();
+
+               // each result partition will retain 
(numberOfResultSubpartitions + 1) network buffers for its local buffer pool,
+               // according to ResultPartitionFactory#createBufferPoolFactory
+               int resultBuffers = 0;
+               for (int numberOfResultPartitions : 
taskInputsOutputsDescriptor.getNumbersOfResultSubpartitions().values()) {
+                       resultBuffers += numberOfResultPartitions + 1;
+               }
+
+               return new MemorySize((long) networkBufferSize * (inputBuffers 
+ resultBuffers));
+       }
 
 Review comment:
   Good suggestion. Especially that the buffers required for input channels is 
highly coupled with NetworkBufferPool logics and we cannot easily extract it to 
be a shared method.
   Adding such a test will be good to ensure this contract would not be 
violated accidentally.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to