-
Notifications
You must be signed in to change notification settings - Fork 13.8k
[FLINK-31476] AdaptiveScheduler respects minimum parallelism #22883
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c24ce04
[FLINK-31476] AdaptiveScheduler respects minimum parallelism
zentol 94aea94
clarify calculation / fix edge-case / add tests
zentol cb4cdf1
do not cancel job when mi is raised above current parallelism
zentol f3b5733
formatting / javadocs
zentol 289d9fd
Update flink-runtime/src/main/java/org/apache/flink/runtime/scheduler…
zentol 78af5e4
eagerly collect ssg metainfo
zentol 20b129a
extend test
zentol a238734
remove extra code for maxUP computation
zentol File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -42,6 +42,8 @@ | |
| import java.util.Optional; | ||
| import java.util.Set; | ||
| import java.util.UUID; | ||
| import java.util.function.BiFunction; | ||
| import java.util.function.Function; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| /** {@link SlotAllocator} implementation that supports slot sharing. */ | ||
|
|
@@ -72,37 +74,35 @@ public static SlotSharingSlotAllocator createSlotSharingSlotAllocator( | |
| public ResourceCounter calculateRequiredSlots( | ||
| Iterable<JobInformation.VertexInformation> vertices) { | ||
| int numTotalRequiredSlots = 0; | ||
| for (Integer requiredSlots : getMaxParallelismForSlotSharingGroups(vertices).values()) { | ||
| numTotalRequiredSlots += requiredSlots; | ||
| for (SlotSharingGroupMetaInfo slotSharingGroupMetaInfo : | ||
| SlotSharingGroupMetaInfo.from(vertices).values()) { | ||
| numTotalRequiredSlots += slotSharingGroupMetaInfo.getMaxUpperBound(); | ||
| } | ||
| return ResourceCounter.withResource(ResourceProfile.UNKNOWN, numTotalRequiredSlots); | ||
| } | ||
|
|
||
| private static Map<SlotSharingGroupId, Integer> getMaxParallelismForSlotSharingGroups( | ||
| Iterable<JobInformation.VertexInformation> vertices) { | ||
| final Map<SlotSharingGroupId, Integer> maxParallelismForSlotSharingGroups = new HashMap<>(); | ||
| for (JobInformation.VertexInformation vertex : vertices) { | ||
| maxParallelismForSlotSharingGroups.compute( | ||
| vertex.getSlotSharingGroup().getSlotSharingGroupId(), | ||
| (slotSharingGroupId, currentMaxParallelism) -> | ||
| currentMaxParallelism == null | ||
| ? vertex.getParallelism() | ||
| : Math.max(currentMaxParallelism, vertex.getParallelism())); | ||
| } | ||
| return maxParallelismForSlotSharingGroups; | ||
| } | ||
|
|
||
| @Override | ||
| public Optional<VertexParallelism> determineParallelism( | ||
| JobInformation jobInformation, Collection<? extends SlotInfo> freeSlots) { | ||
|
|
||
| // => less slots than slot-sharing groups | ||
| if (jobInformation.getSlotSharingGroups().size() > freeSlots.size()) { | ||
| final Map<SlotSharingGroupId, SlotSharingGroupMetaInfo> slotSharingGroupMetaInfo = | ||
| SlotSharingGroupMetaInfo.from(jobInformation.getVertices()); | ||
|
|
||
| final int minimumRequiredSlots = | ||
| slotSharingGroupMetaInfo.values().stream() | ||
| .map(SlotSharingGroupMetaInfo::getMinLowerBound) | ||
| .reduce(0, Integer::sum); | ||
|
|
||
| if (minimumRequiredSlots > freeSlots.size()) { | ||
| return Optional.empty(); | ||
| } | ||
|
|
||
| final Map<SlotSharingGroupId, Integer> slotSharingGroupParallelism = | ||
| determineSlotsPerSharingGroup(jobInformation, freeSlots.size()); | ||
| determineSlotsPerSharingGroup( | ||
| jobInformation, | ||
| freeSlots.size(), | ||
| minimumRequiredSlots, | ||
| slotSharingGroupMetaInfo); | ||
|
|
||
| final Map<JobVertexID, Integer> allVertexParallelism = new HashMap<>(); | ||
|
|
||
|
|
@@ -150,34 +150,58 @@ public Optional<JobSchedulingPlan> determineParallelismAndCalculateAssignment( | |
| * distributed over the remaining groups. | ||
| */ | ||
| private static Map<SlotSharingGroupId, Integer> determineSlotsPerSharingGroup( | ||
| JobInformation jobInformation, int freeSlots) { | ||
| JobInformation jobInformation, | ||
| int freeSlots, | ||
| int minRequiredSlots, | ||
| Map<SlotSharingGroupId, SlotSharingGroupMetaInfo> slotSharingGroupMetaInfo) { | ||
|
|
||
| int numUnassignedSlots = freeSlots; | ||
| int numUnassignedSlotSharingGroups = jobInformation.getSlotSharingGroups().size(); | ||
| int numMinSlotsRequiredByRemainingGroups = minRequiredSlots; | ||
|
|
||
| final Map<SlotSharingGroupId, Integer> slotSharingGroupParallelism = new HashMap<>(); | ||
|
|
||
| for (Map.Entry<SlotSharingGroupId, Integer> slotSharingGroup : | ||
| sortSlotSharingGroupsByDesiredParallelism(jobInformation)) { | ||
| for (SlotSharingGroupId slotSharingGroup : | ||
| sortSlotSharingGroupsByHighestParallelismRange(slotSharingGroupMetaInfo)) { | ||
| final int minParallelism = | ||
| slotSharingGroupMetaInfo.get(slotSharingGroup).getMinLowerBound(); | ||
|
|
||
| // if we reached this point we know we have more slots than we need to fulfill the | ||
| // minimum requirements for each slot sharing group. | ||
| // this means that a certain number of slots are already implicitly reserved (to fulfill | ||
| // the minimum requirement of other groups); so we only need to distribute the remaining | ||
| // "optional" slots while only accounting for the requirements beyond the minimum | ||
|
|
||
| // the number of slots this group can use beyond the minimum | ||
| final int maxOptionalSlots = | ||
| slotSharingGroupMetaInfo.get(slotSharingGroup).getMaxUpperBound() | ||
| - minParallelism; | ||
| // the number of slots that are not implicitly reserved for minimum requirements | ||
| final int freeOptionalSlots = numUnassignedSlots - numMinSlotsRequiredByRemainingGroups; | ||
| // the number of slots this group is allowed to use beyond the minimum requirements | ||
| final int optionalSlotShare = freeOptionalSlots / numUnassignedSlotSharingGroups; | ||
|
|
||
| final int groupParallelism = | ||
| Math.min( | ||
| slotSharingGroup.getValue(), | ||
| numUnassignedSlots / numUnassignedSlotSharingGroups); | ||
| minParallelism + Math.min(maxOptionalSlots, optionalSlotShare); | ||
|
|
||
| slotSharingGroupParallelism.put(slotSharingGroup.getKey(), groupParallelism); | ||
| slotSharingGroupParallelism.put(slotSharingGroup, groupParallelism); | ||
|
|
||
| numMinSlotsRequiredByRemainingGroups -= minParallelism; | ||
| numUnassignedSlots -= groupParallelism; | ||
| numUnassignedSlotSharingGroups--; | ||
| } | ||
|
|
||
| return slotSharingGroupParallelism; | ||
| } | ||
|
|
||
| private static List<Map.Entry<SlotSharingGroupId, Integer>> | ||
| sortSlotSharingGroupsByDesiredParallelism(JobInformation jobInformation) { | ||
| private static List<SlotSharingGroupId> sortSlotSharingGroupsByHighestParallelismRange( | ||
| Map<SlotSharingGroupId, SlotSharingGroupMetaInfo> slotSharingGroupMetaInfo) { | ||
|
|
||
| return getMaxParallelismForSlotSharingGroups(jobInformation.getVertices()).entrySet() | ||
| .stream() | ||
| .sorted(Comparator.comparingInt(Map.Entry::getValue)) | ||
| return slotSharingGroupMetaInfo.entrySet().stream() | ||
| .sorted( | ||
| Comparator.comparingInt( | ||
| entry -> entry.getValue().getMaxLowerUpperBoundRange())) | ||
| .map(Map.Entry::getKey) | ||
| .collect(Collectors.toList()); | ||
| } | ||
|
|
||
|
|
@@ -274,4 +298,68 @@ public Collection<ExecutionVertexID> getContainedExecutionVertices() { | |
| return containedExecutionVertices; | ||
| } | ||
| } | ||
|
|
||
| private static class SlotSharingGroupMetaInfo { | ||
|
|
||
| private final int minLowerBound; | ||
| private final int maxUpperBound; | ||
| private final int maxLowerUpperBoundRange; | ||
|
|
||
| private SlotSharingGroupMetaInfo( | ||
| int minLowerBound, int maxUpperBound, int maxLowerUpperBoundRange) { | ||
| this.minLowerBound = minLowerBound; | ||
| this.maxUpperBound = maxUpperBound; | ||
| this.maxLowerUpperBoundRange = maxLowerUpperBoundRange; | ||
| } | ||
|
|
||
| public int getMinLowerBound() { | ||
| return minLowerBound; | ||
| } | ||
|
|
||
| public int getMaxUpperBound() { | ||
| return maxUpperBound; | ||
| } | ||
|
|
||
| public int getMaxLowerUpperBoundRange() { | ||
| return maxLowerUpperBoundRange; | ||
| } | ||
|
|
||
| public static Map<SlotSharingGroupId, SlotSharingGroupMetaInfo> from( | ||
| Iterable<JobInformation.VertexInformation> vertices) { | ||
|
|
||
| return getPerSlotSharingGroups( | ||
| vertices, | ||
| vertexInformation -> | ||
| new SlotSharingGroupMetaInfo( | ||
| vertexInformation.getMinParallelism(), | ||
| vertexInformation.getParallelism(), | ||
| vertexInformation.getParallelism() | ||
| - vertexInformation.getMinParallelism()), | ||
| (metaInfo1, metaInfo2) -> | ||
| new SlotSharingGroupMetaInfo( | ||
| Math.min(metaInfo1.getMinLowerBound(), metaInfo2.minLowerBound), | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hi Schepler! May you explain here why it's not Math.max(metaInfo1.getMinLowerBound(), metaInfo2.minLowerBound) but min here? |
||
| Math.max( | ||
| metaInfo1.getMaxUpperBound(), | ||
| metaInfo2.getMaxUpperBound()), | ||
| Math.max( | ||
| metaInfo1.getMaxLowerUpperBoundRange(), | ||
| metaInfo2.getMaxLowerUpperBoundRange()))); | ||
| } | ||
|
|
||
| private static <T> Map<SlotSharingGroupId, T> getPerSlotSharingGroups( | ||
| Iterable<JobInformation.VertexInformation> vertices, | ||
| Function<JobInformation.VertexInformation, T> mapper, | ||
| BiFunction<T, T, T> reducer) { | ||
| final Map<SlotSharingGroupId, T> extractedPerSlotSharingGroups = new HashMap<>(); | ||
| for (JobInformation.VertexInformation vertex : vertices) { | ||
| extractedPerSlotSharingGroups.compute( | ||
| vertex.getSlotSharingGroup().getSlotSharingGroupId(), | ||
| (slotSharingGroupId, currentData) -> | ||
| currentData == null | ||
| ? mapper.apply(vertex) | ||
| : reducer.apply(currentData, mapper.apply(vertex))); | ||
| } | ||
| return extractedPerSlotSharingGroups; | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.