Skip to content

Commit

Permalink
[hotfix][runtime] Directly pass ResourceCounter as the totalRequireme…
Browse files Browse the repository at this point in the history
…nts to the RequirementMatcher

As the ResourceCounter is immutable, we can directly pass it as a argument, this also give us chance to optimize the matching perfermance
  • Loading branch information
KarmaGYZ authored and xintongsong committed Feb 28, 2021
1 parent e6cf590 commit 1ba2962
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ private Optional<AllocatedSlot> matchOfferWithOutstandingRequirements(
final Optional<ResourceProfile> match =
requirementMatcher.match(
slotOffer.getResourceProfile(),
totalResourceRequirements.getResourcesWithCount(),
totalResourceRequirements,
fulfilledResourceRequirements::getResourceCount);

if (match.isPresent()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public void notifyAcquiredResource(ResourceProfile resourceProfile) {
private Optional<ResourceProfile> findMatchingRequirement(ResourceProfile resourceProfile) {
return requirementMatcher.match(
resourceProfile,
resourceRequirements.getResourcesWithCount(),
resourceRequirements,
resourceToRequirementMapping::getNumFulfillingResources);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
package org.apache.flink.runtime.slots;

import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
import org.apache.flink.runtime.util.ResourceCounter;

import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
Expand All @@ -32,9 +32,17 @@ public class DefaultRequirementMatcher implements RequirementMatcher {
@Override
public Optional<ResourceProfile> match(
ResourceProfile resourceProfile,
Collection<Map.Entry<ResourceProfile, Integer>> totalRequirements,
ResourceCounter totalRequirements,
Function<ResourceProfile, Integer> numAssignedResourcesLookup) {
for (Map.Entry<ResourceProfile, Integer> requirementCandidate : totalRequirements) {
// Short-cut for fine-grained resource management. If there is already exactly equal
// requirement, we can directly match with it.
if (totalRequirements.getResourceCount(resourceProfile)
> numAssignedResourcesLookup.apply(resourceProfile)) {
return Optional.of(resourceProfile);
}

for (Map.Entry<ResourceProfile, Integer> requirementCandidate :
totalRequirements.getResourcesWithCount()) {
ResourceProfile requirementProfile = requirementCandidate.getKey();

// beware the order when matching resources to requirements, because
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@
package org.apache.flink.runtime.slots;

import org.apache.flink.runtime.clusterframework.types.ResourceProfile;
import org.apache.flink.runtime.util.ResourceCounter;

import java.util.Collection;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;

Expand All @@ -38,6 +37,6 @@ public interface RequirementMatcher {
*/
Optional<ResourceProfile> match(
ResourceProfile resourceProfile,
Collection<Map.Entry<ResourceProfile, Integer>> totalRequirements,
ResourceCounter totalRequirements,
Function<ResourceProfile, Integer> numAssignedResourcesLookup);
}

0 comments on commit 1ba2962

Please sign in to comment.