wanglijie95 commented on a change in pull request #17952: URL: https://github.com/apache/flink/pull/17952#discussion_r762767146
########## File path: flink-runtime/src/main/java/org/apache/flink/runtime/scheduler/adaptivebatch/DefaultVertexParallelismDecider.java ########## @@ -0,0 +1,132 @@ +/* + * 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.flink.runtime.scheduler.adaptivebatch; + +import org.apache.flink.configuration.Configuration; +import org.apache.flink.configuration.JobManagerOptions; +import org.apache.flink.configuration.MemorySize; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +/** Default implementation of {@link VertexParallelismDecider}. */ +public class DefaultVertexParallelismDecider implements VertexParallelismDecider { + + private static final Logger LOG = + LoggerFactory.getLogger(DefaultVertexParallelismDecider.class); + + private final int maxParallelism; + private final int minParallelism; + private final long dataVolumePerTask; + private final int defaultSourceParallelism; + + public DefaultVertexParallelismDecider( + int maxParallelism, + int minParallelism, + MemorySize dataVolumePerTask, + int defaultSourceParallelism) { + + this.maxParallelism = maxParallelism; + this.minParallelism = minParallelism; + this.dataVolumePerTask = dataVolumePerTask.getBytes(); + this.defaultSourceParallelism = defaultSourceParallelism; + } + + @Override + public int decideParallelismForVertex(List<BlockingResultInfo> consumedResults) { + + if (consumedResults.isEmpty()) { + // source job vertex + return defaultSourceParallelism; + } else { + return calculateParallelism(consumedResults); + } + } + + private int calculateParallelism(List<BlockingResultInfo> consumedResults) { + + long broadcastBytes = + consumedResults.stream() + .filter(BlockingResultInfo::isBroadcast) + .mapToLong( + consumedResult -> + consumedResult.getBlockingPartitionSizes().stream() + .reduce(0L, Long::sum)) + .sum(); + + long nonBroadcastBytes = + consumedResults.stream() + .filter(consumedResult -> !consumedResult.isBroadcast()) + .mapToLong( + consumedResult -> + consumedResult.getBlockingPartitionSizes().stream() + .reduce(0L, Long::sum)) + .sum(); + + if (broadcastBytes > dataVolumePerTask + || (broadcastBytes == dataVolumePerTask && nonBroadcastBytes > 0)) { + LOG.warn( + "The minimum size of one task to process is larger than " + + "the size of data volume which is configured by " + + "'" + + JobManagerOptions.ADAPTIVE_BATCH_SCHEDULER_DATA_VOLUME_PER_TASK.key() + + "'. " + + "Parallelism will be set to {}.", + maxParallelism); + + return maxParallelism; Review comment: I think this is worth discussing. When the `broadcastBytes` is close to the `dataVolumePerTask `, even if the `nonBroadcastBytes` is very small, it may cause a large parallelism, which is unnecessary and will bring great network overhead. To solve this problem, one possible approach is to reserve a minimum ratio for the amount of non-broadcast data processed by one task. For example, it is specified that the proportion of non-broadcast data processed by one task is at least 50%, once the amount of broadcast data exceeds 50%, the parallelism should be `nonBroadcastBytes / (dataVolumePerTask * 0.5)`. In this way, when `nonBroadcastBytes` is rarely or even 0, the parallelism will be determined as `minParallelism`. -- 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