Search in sources :

Example 6 with SlotInfo

use of org.apache.flink.runtime.jobmaster.SlotInfo in project flink by apache.

the class SlotSharingSlotAllocator method determineParallelism.

@Override
public Optional<VertexParallelismWithSlotSharing> determineParallelism(JobInformation jobInformation, Collection<? extends SlotInfo> freeSlots) {
    // TODO: This can waste slots if the max parallelism for slot sharing groups is not equal
    final int slotsPerSlotSharingGroup = freeSlots.size() / jobInformation.getSlotSharingGroups().size();
    if (slotsPerSlotSharingGroup == 0) {
        // => less slots than slot-sharing groups
        return Optional.empty();
    }
    final Iterator<? extends SlotInfo> slotIterator = freeSlots.iterator();
    final Collection<ExecutionSlotSharingGroupAndSlot> assignments = new ArrayList<>();
    final Map<JobVertexID, Integer> allVertexParallelism = new HashMap<>();
    for (SlotSharingGroup slotSharingGroup : jobInformation.getSlotSharingGroups()) {
        final List<JobInformation.VertexInformation> containedJobVertices = slotSharingGroup.getJobVertexIds().stream().map(jobInformation::getVertexInformation).collect(Collectors.toList());
        final Map<JobVertexID, Integer> vertexParallelism = determineParallelism(containedJobVertices, slotsPerSlotSharingGroup);
        final Iterable<ExecutionSlotSharingGroup> sharedSlotToVertexAssignment = createExecutionSlotSharingGroups(vertexParallelism);
        for (ExecutionSlotSharingGroup executionSlotSharingGroup : sharedSlotToVertexAssignment) {
            final SlotInfo slotInfo = slotIterator.next();
            assignments.add(new ExecutionSlotSharingGroupAndSlot(executionSlotSharingGroup, slotInfo));
        }
        allVertexParallelism.putAll(vertexParallelism);
    }
    return Optional.of(new VertexParallelismWithSlotSharing(allVertexParallelism, assignments));
}
Also used : HashMap(java.util.HashMap) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) ArrayList(java.util.ArrayList) SlotSharingGroup(org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup) SlotInfo(org.apache.flink.runtime.jobmaster.SlotInfo)

Example 7 with SlotInfo

use of org.apache.flink.runtime.jobmaster.SlotInfo in project flink by apache.

the class AdaptiveScheduler method hasDesiredResources.

// ----------------------------------------------------------------
@Override
public boolean hasDesiredResources(ResourceCounter desiredResources) {
    final Collection<? extends SlotInfo> allSlots = declarativeSlotPool.getFreeSlotsInformation();
    ResourceCounter outstandingResources = desiredResources;
    final Iterator<? extends SlotInfo> slotIterator = allSlots.iterator();
    while (!outstandingResources.isEmpty() && slotIterator.hasNext()) {
        final SlotInfo slotInfo = slotIterator.next();
        final ResourceProfile resourceProfile = slotInfo.getResourceProfile();
        if (outstandingResources.containsResource(resourceProfile)) {
            outstandingResources = outstandingResources.subtract(resourceProfile, 1);
        } else {
            outstandingResources = outstandingResources.subtract(ResourceProfile.UNKNOWN, 1);
        }
    }
    return outstandingResources.isEmpty();
}
Also used : ResourceProfile(org.apache.flink.runtime.clusterframework.types.ResourceProfile) ResourceCounter(org.apache.flink.runtime.util.ResourceCounter) SlotInfo(org.apache.flink.runtime.jobmaster.SlotInfo)

Example 8 with SlotInfo

use of org.apache.flink.runtime.jobmaster.SlotInfo in project flink by apache.

the class DefaultAllocatedSlotPoolTest method assertSlotPoolContainsSlots.

private void assertSlotPoolContainsSlots(DefaultAllocatedSlotPool slotPool, Collection<AllocatedSlot> slots) {
    assertThat(slotPool.getAllSlotsInformation(), hasSize(slots.size()));
    final Map<AllocationID, AllocatedSlot> slotsPerAllocationId = slots.stream().collect(Collectors.toMap(AllocatedSlot::getAllocationId, Function.identity()));
    for (SlotInfo slotInfo : slotPool.getAllSlotsInformation()) {
        assertTrue(slotsPerAllocationId.containsKey(slotInfo.getAllocationId()));
        final AllocatedSlot allocatedSlot = slotsPerAllocationId.get(slotInfo.getAllocationId());
        assertThat(slotInfo, matchesPhysicalSlot(allocatedSlot));
    }
}
Also used : AllocationID(org.apache.flink.runtime.clusterframework.types.AllocationID) SlotInfo(org.apache.flink.runtime.jobmaster.SlotInfo)

Aggregations

SlotInfo (org.apache.flink.runtime.jobmaster.SlotInfo)8 Test (org.junit.Test)4 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 AllocatedSlotInfo (org.apache.flink.runtime.jobmaster.AllocatedSlotInfo)2 AllocatedSlotReport (org.apache.flink.runtime.jobmaster.AllocatedSlotReport)2 LocalTaskManagerLocation (org.apache.flink.runtime.taskmanager.LocalTaskManagerLocation)2 Map (java.util.Map)1 AllocationID (org.apache.flink.runtime.clusterframework.types.AllocationID)1 ResourceProfile (org.apache.flink.runtime.clusterframework.types.ResourceProfile)1 SimpleSlotContext (org.apache.flink.runtime.instance.SimpleSlotContext)1 JobVertexID (org.apache.flink.runtime.jobgraph.JobVertexID)1 SlotSharingGroup (org.apache.flink.runtime.jobmanager.scheduler.SlotSharingGroup)1 LogicalSlot (org.apache.flink.runtime.jobmaster.LogicalSlot)1 LocationPreferenceSlotSelectionStrategy (org.apache.flink.runtime.jobmaster.slotpool.LocationPreferenceSlotSelectionStrategy)1 SlotSelectionStrategy (org.apache.flink.runtime.jobmaster.slotpool.SlotSelectionStrategy)1 ExecutionVertexID (org.apache.flink.runtime.scheduler.strategy.ExecutionVertexID)1 SlotOffer (org.apache.flink.runtime.taskexecutor.slot.SlotOffer)1 ResourceCounter (org.apache.flink.runtime.util.ResourceCounter)1