Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-21326] Optimize the topology building in ExecutionGraph
- Loading branch information
1 parent
8a8a260
commit cb77b97
Showing
18 changed files
with
396 additions
and
350 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
143 changes: 143 additions & 0 deletions
143
...k-runtime/src/main/java/org/apache/flink/runtime/executiongraph/EdgeManagerBuildUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,143 @@ | ||
/* | ||
* 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.executiongraph; | ||
|
||
import org.apache.flink.runtime.jobgraph.DistributionPattern; | ||
import org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID; | ||
import org.apache.flink.runtime.scheduler.strategy.ConsumedPartitionGroup; | ||
import org.apache.flink.runtime.scheduler.strategy.ConsumerVertexGroup; | ||
import org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
/** Utilities for building {@link EdgeManager}. */ | ||
public class EdgeManagerBuildUtil { | ||
|
||
public static void connectVertexToResult( | ||
ExecutionJobVertex vertex, | ||
IntermediateResult ires, | ||
int inputNumber, | ||
DistributionPattern distributionPattern) { | ||
|
||
switch (distributionPattern) { | ||
case POINTWISE: | ||
connectPointwise(vertex.getTaskVertices(), ires, inputNumber); | ||
break; | ||
case ALL_TO_ALL: | ||
connectAllToAll(vertex.getTaskVertices(), ires, inputNumber); | ||
break; | ||
default: | ||
throw new RuntimeException("Unrecognized distribution pattern."); | ||
} | ||
} | ||
|
||
private static void connectAllToAll( | ||
ExecutionVertex[] taskVertices, IntermediateResult ires, int inputNumber) { | ||
|
||
ConsumedPartitionGroup consumedPartitions = | ||
new ConsumedPartitionGroup( | ||
Arrays.stream(ires.getPartitions()) | ||
.map(IntermediateResultPartition::getPartitionId) | ||
.collect(Collectors.toList())); | ||
for (ExecutionVertex ev : taskVertices) { | ||
ev.addConsumedPartitions(consumedPartitions, inputNumber); | ||
} | ||
|
||
ConsumerVertexGroup vertices = | ||
new ConsumerVertexGroup( | ||
Arrays.stream(taskVertices) | ||
.map(ExecutionVertex::getID) | ||
.collect(Collectors.toList())); | ||
for (IntermediateResultPartition partition : ires.getPartitions()) { | ||
partition.addConsumers(vertices); | ||
} | ||
} | ||
|
||
private static void connectPointwise( | ||
ExecutionVertex[] taskVertices, IntermediateResult ires, int inputNumber) { | ||
|
||
final int sourceCount = ires.getPartitions().length; | ||
final int targetCount = taskVertices.length; | ||
|
||
if (sourceCount == targetCount) { | ||
for (int i = 0; i < sourceCount; i++) { | ||
ExecutionVertex executionVertex = taskVertices[i]; | ||
IntermediateResultPartition partition = ires.getPartitions()[i]; | ||
|
||
ConsumerVertexGroup consumerVertexGroup = | ||
new ConsumerVertexGroup(executionVertex.getID()); | ||
partition.addConsumers(consumerVertexGroup); | ||
|
||
ConsumedPartitionGroup consumedPartitionGroup = | ||
new ConsumedPartitionGroup(partition.getPartitionId()); | ||
executionVertex.addConsumedPartitions(consumedPartitionGroup, inputNumber); | ||
} | ||
} else if (sourceCount > targetCount) { | ||
for (int index = 0; index < targetCount; index++) { | ||
|
||
ExecutionVertex executionVertex = taskVertices[index]; | ||
ConsumerVertexGroup consumerVertexGroup = | ||
new ConsumerVertexGroup(executionVertex.getID()); | ||
|
||
int start = index * sourceCount / targetCount; | ||
int end = (index + 1) * sourceCount / targetCount; | ||
|
||
List<IntermediateResultPartitionID> consumedPartitions = | ||
new ArrayList<>(end - start); | ||
|
||
for (int i = start; i < end; i++) { | ||
IntermediateResultPartition partition = ires.getPartitions()[i]; | ||
partition.addConsumers(consumerVertexGroup); | ||
|
||
consumedPartitions.add(partition.getPartitionId()); | ||
} | ||
|
||
ConsumedPartitionGroup consumedPartitionGroup = | ||
new ConsumedPartitionGroup(consumedPartitions); | ||
executionVertex.addConsumedPartitions(consumedPartitionGroup, inputNumber); | ||
} | ||
} else { | ||
for (int partitionNum = 0; partitionNum < sourceCount; partitionNum++) { | ||
|
||
IntermediateResultPartition partition = ires.getPartitions()[partitionNum]; | ||
ConsumedPartitionGroup consumerPartitionGroup = | ||
new ConsumedPartitionGroup(partition.getPartitionId()); | ||
|
||
float factor = ((float) targetCount) / sourceCount; | ||
int start = (int) (Math.ceil(partitionNum * factor)); | ||
int end = (int) (Math.ceil((partitionNum + 1) * factor)); | ||
|
||
List<ExecutionVertexID> consumers = new ArrayList<>(end - start); | ||
|
||
for (int i = start; i < end; i++) { | ||
ExecutionVertex executionVertex = taskVertices[i]; | ||
executionVertex.addConsumedPartitions(consumerPartitionGroup, inputNumber); | ||
|
||
consumers.add(executionVertex.getID()); | ||
} | ||
|
||
ConsumerVertexGroup consumerVertexGroup = new ConsumerVertexGroup(consumers); | ||
partition.addConsumers(consumerVertexGroup); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.