Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-30471][network] Optimize the enriching network memory process in SsgNetworkMemoryCalculationUtils #21612

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -93,28 +93,27 @@ public static void enrichNetworkMemory(
private static TaskInputsOutputsDescriptor buildTaskInputsOutputsDescriptor(
ExecutionJobVertex ejv, Function<JobVertexID, ExecutionJobVertex> ejvs) {

Map<IntermediateDataSetID, Integer> maxInputChannelNums;
Map<IntermediateDataSetID, Integer> maxSubpartitionNums;
Map<IntermediateDataSetID, Integer> maxInputChannelNums = new HashMap<>();
TanYuxin-tyx marked this conversation as resolved.
Show resolved Hide resolved
Map<IntermediateDataSetID, Integer> maxSubpartitionNums = new HashMap<>();
Map<IntermediateDataSetID, ResultPartitionType> partitionTypes = new HashMap<>();

if (ejv.getGraph().isDynamic()) {
maxInputChannelNums = getMaxInputChannelNumsForDynamicGraph(ejv);
maxSubpartitionNums = getMaxSubpartitionNumsForDynamicGraph(ejv);
getMaxInputChannelInfoForDynamicGraph(ejv, maxInputChannelNums);
getMaxSubpartitionInfoForDynamicGraph(ejv, maxSubpartitionNums, partitionTypes);
} else {
maxInputChannelNums = getMaxInputChannelNums(ejv);
maxSubpartitionNums = getMaxSubpartitionNums(ejv, ejvs);
getMaxInputChannelInfo(ejv, maxInputChannelNums);
getMaxSubpartitionInfo(ejv, maxSubpartitionNums, partitionTypes, ejvs);
}

JobVertex jv = ejv.getJobVertex();
Map<IntermediateDataSetID, ResultPartitionType> partitionTypes = getPartitionTypes(jv);

return TaskInputsOutputsDescriptor.from(
jv.getNumberOfInputs(), maxInputChannelNums, maxSubpartitionNums, partitionTypes);
}

private static Map<IntermediateDataSetID, Integer> getMaxInputChannelNums(
ExecutionJobVertex ejv) {
private static void getMaxInputChannelInfo(
ExecutionJobVertex ejv, Map<IntermediateDataSetID, Integer> maxInputChannelNums) {

Map<IntermediateDataSetID, Integer> ret = new HashMap<>();
List<JobEdge> inputEdges = ejv.getJobVertex().getInputs();

for (int i = 0; i < inputEdges.size(); i++) {
Expand All @@ -129,16 +128,15 @@ private static Map<IntermediateDataSetID, Integer> getMaxInputChannelNums(
ejv.getParallelism(),
consumedResult.getNumberOfAssignedPartitions(),
inputEdge.getDistributionPattern());
ret.merge(consumedResult.getId(), maxNum, Integer::sum);
maxInputChannelNums.merge(consumedResult.getId(), maxNum, Integer::sum);
}

return ret;
}

private static Map<IntermediateDataSetID, Integer> getMaxSubpartitionNums(
ExecutionJobVertex ejv, Function<JobVertexID, ExecutionJobVertex> ejvs) {

Map<IntermediateDataSetID, Integer> ret = new HashMap<>();
private static void getMaxSubpartitionInfo(
ExecutionJobVertex ejv,
Map<IntermediateDataSetID, Integer> maxSubpartitionNums,
Map<IntermediateDataSetID, ResultPartitionType> partitionTypes,
Function<JobVertexID, ExecutionJobVertex> ejvs) {
List<IntermediateDataSet> producedDataSets = ejv.getJobVertex().getProducedDataSets();

checkState(!ejv.getGraph().isDynamic(), "Only support non-dynamic graph.");
Expand All @@ -157,23 +155,14 @@ private static Map<IntermediateDataSetID, Integer> getMaxSubpartitionNums(
consumerJobVertex.getParallelism(),
outputEdge.getDistributionPattern());
}
ret.put(producedDataSet.getId(), maxNum);
maxSubpartitionNums.put(producedDataSet.getId(), maxNum);
partitionTypes.putIfAbsent(producedDataSet.getId(), producedDataSet.getResultType());
}

return ret;
}

private static Map<IntermediateDataSetID, ResultPartitionType> getPartitionTypes(JobVertex jv) {
Map<IntermediateDataSetID, ResultPartitionType> ret = new HashMap<>();
jv.getProducedDataSets().forEach(ds -> ret.putIfAbsent(ds.getId(), ds.getResultType()));
return ret;
}

@VisibleForTesting
static Map<IntermediateDataSetID, Integer> getMaxInputChannelNumsForDynamicGraph(
ExecutionJobVertex ejv) {

Map<IntermediateDataSetID, Integer> ret = new HashMap<>();
static void getMaxInputChannelInfoForDynamicGraph(
ExecutionJobVertex ejv, Map<IntermediateDataSetID, Integer> maxInputChannelNums) {

for (ExecutionVertex vertex : ejv.getTaskVertices()) {
Map<IntermediateDataSetID, Integer> tmp = new HashMap<>();
Expand All @@ -194,27 +183,25 @@ static Map<IntermediateDataSetID, Integer> getMaxInputChannelNumsForDynamicGraph
}

for (Map.Entry<IntermediateDataSetID, Integer> entry : tmp.entrySet()) {
ret.merge(entry.getKey(), entry.getValue(), Integer::max);
maxInputChannelNums.merge(entry.getKey(), entry.getValue(), Integer::max);
}
}

return ret;
}

private static Map<IntermediateDataSetID, Integer> getMaxSubpartitionNumsForDynamicGraph(
ExecutionJobVertex ejv) {

Map<IntermediateDataSetID, Integer> ret = new HashMap<>();
private static void getMaxSubpartitionInfoForDynamicGraph(
ExecutionJobVertex ejv,
Map<IntermediateDataSetID, Integer> maxSubpartitionNums,
Map<IntermediateDataSetID, ResultPartitionType> partitionTypes) {

for (IntermediateResult intermediateResult : ejv.getProducedDataSets()) {
final int maxNum =
Arrays.stream(intermediateResult.getPartitions())
.map(IntermediateResultPartition::getNumberOfSubpartitions)
.reduce(0, Integer::max);
ret.put(intermediateResult.getId(), maxNum);
maxSubpartitionNums.put(intermediateResult.getId(), maxNum);
partitionTypes.putIfAbsent(
intermediateResult.getId(), intermediateResult.getResultType());
}

return ret;
}

/** Private default constructor to avoid being instantiated. */
Expand Down
Expand Up @@ -48,6 +48,7 @@
import org.junit.Test;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -231,8 +232,9 @@ private void testGetMaxInputChannelNumForResult(
consumer.setParallelism(decidedConsumerParallelism);
eg.initializeJobVertex(consumer, 0L);

Map<IntermediateDataSetID, Integer> maxInputChannelNums =
SsgNetworkMemoryCalculationUtils.getMaxInputChannelNumsForDynamicGraph(consumer);
Map<IntermediateDataSetID, Integer> maxInputChannelNums = new HashMap<>();
SsgNetworkMemoryCalculationUtils.getMaxInputChannelInfoForDynamicGraph(
consumer, maxInputChannelNums);

assertThat(maxInputChannelNums.size(), is(1));
assertThat(maxInputChannelNums.get(result.getId()), is(expectedNumChannels));
Expand Down