zhuzhurk commented on a change in pull request #17952: URL: https://github.com/apache/flink/pull/17952#discussion_r763747748
########## 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: Yes I agree that when the `broadcastBytes` is too close to `dataVolumePerTask`, it is still a problem. In my understanding, broadcast dataset is usually relatively small against the other co-processed dataset. Therefore, I think we can introduce a cap ratio of how much the `broadcastBytes` will affect computing the parallelism. By default, the cap ratio can be `0.5` because we usually expect the broadcast dataset to be smaller. The value can be hard coded in the first version. We can make it configurable later if we see users requesting for 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]
