Search in sources :

Example 91 with Resource

use of org.apache.hadoop.yarn.api.records.Resource in project hadoop by apache.

the class SchedulerApplicationAttempt method getRunningAggregateAppResourceUsage.

private AggregateAppResourceUsage getRunningAggregateAppResourceUsage() {
    long currentTimeMillis = System.currentTimeMillis();
    // recently.
    if ((currentTimeMillis - lastMemoryAggregateAllocationUpdateTime) > MEM_AGGREGATE_ALLOCATION_CACHE_MSECS) {
        long memorySeconds = 0;
        long vcoreSeconds = 0;
        for (RMContainer rmContainer : this.liveContainers.values()) {
            long usedMillis = currentTimeMillis - rmContainer.getCreationTime();
            Resource resource = rmContainer.getContainer().getResource();
            memorySeconds += resource.getMemorySize() * usedMillis / DateUtils.MILLIS_PER_SECOND;
            vcoreSeconds += resource.getVirtualCores() * usedMillis / DateUtils.MILLIS_PER_SECOND;
        }
        lastMemoryAggregateAllocationUpdateTime = currentTimeMillis;
        lastMemorySeconds = memorySeconds;
        lastVcoreSeconds = vcoreSeconds;
    }
    return new AggregateAppResourceUsage(lastMemorySeconds, lastVcoreSeconds);
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) AggregateAppResourceUsage(org.apache.hadoop.yarn.server.resourcemanager.rmapp.attempt.AggregateAppResourceUsage)

Example 92 with Resource

use of org.apache.hadoop.yarn.api.records.Resource in project hadoop by apache.

the class SchedulerApplicationAttempt method move.

public void move(Queue newQueue) {
    try {
        writeLock.lock();
        QueueMetrics oldMetrics = queue.getMetrics();
        QueueMetrics newMetrics = newQueue.getMetrics();
        String newQueueName = newQueue.getQueueName();
        String user = getUser();
        for (RMContainer liveContainer : liveContainers.values()) {
            Resource resource = liveContainer.getContainer().getResource();
            ((RMContainerImpl) liveContainer).setQueueName(newQueueName);
            oldMetrics.releaseResources(user, 1, resource);
            newMetrics.allocateResources(user, 1, resource, false);
        }
        for (Map<NodeId, RMContainer> map : reservedContainers.values()) {
            for (RMContainer reservedContainer : map.values()) {
                ((RMContainerImpl) reservedContainer).setQueueName(newQueueName);
                Resource resource = reservedContainer.getReservedResource();
                oldMetrics.unreserveResource(user, resource);
                newMetrics.reserveResource(user, resource);
            }
        }
        if (!isStopped) {
            appSchedulingInfo.move(newQueue);
        }
        this.queue = newQueue;
    } finally {
        writeLock.unlock();
    }
}
Also used : RMContainerImpl(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerImpl) Resource(org.apache.hadoop.yarn.api.records.Resource) NodeId(org.apache.hadoop.yarn.api.records.NodeId) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)

Example 93 with Resource

use of org.apache.hadoop.yarn.api.records.Resource in project hadoop by apache.

the class FiCaSchedulerApp method commonCheckContainerAllocation.

private boolean commonCheckContainerAllocation(Resource cluster, ContainerAllocationProposal<FiCaSchedulerApp, FiCaSchedulerNode> allocation, SchedulerContainer<FiCaSchedulerApp, FiCaSchedulerNode> schedulerContainer) {
    // Make sure node is not reserved by anyone else
    RMContainer reservedContainerOnNode = schedulerContainer.getSchedulerNode().getReservedContainer();
    if (reservedContainerOnNode != null) {
        RMContainer fromReservedContainer = allocation.getAllocateFromReservedContainer().getRmContainer();
        if (fromReservedContainer != reservedContainerOnNode) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("Try to allocate from a non-existed reserved container");
            }
            return false;
        }
    }
    // Do we have enough space on this node?
    Resource availableResource = Resources.clone(schedulerContainer.getSchedulerNode().getUnallocatedResource());
    // of this node
    if (allocation.getToRelease() != null && !allocation.getToRelease().isEmpty()) {
        for (SchedulerContainer<FiCaSchedulerApp, FiCaSchedulerNode> releaseContainer : allocation.getToRelease()) {
            // not affect available resource of node) on the same node
            if (releaseContainer.getRmContainer().getState() != RMContainerState.RESERVED && releaseContainer.getSchedulerNode() == schedulerContainer.getSchedulerNode()) {
                Resources.addTo(availableResource, releaseContainer.getRmContainer().getAllocatedResource());
            }
        }
    }
    if (!Resources.fitsIn(rc, cluster, allocation.getAllocatedOrReservedResource(), availableResource)) {
        if (LOG.isDebugEnabled()) {
            LOG.debug("Node doesn't have enough available resource, asked=" + allocation.getAllocatedOrReservedResource() + " available=" + availableResource);
        }
        return false;
    }
    return true;
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)

Example 94 with Resource

use of org.apache.hadoop.yarn.api.records.Resource in project hadoop by apache.

the class FiCaSchedulerApp method internalUnreserve.

private boolean internalUnreserve(FiCaSchedulerNode node, SchedulerRequestKey schedulerKey) {
    Map<NodeId, RMContainer> reservedContainers = this.reservedContainers.get(schedulerKey);
    if (reservedContainers != null) {
        RMContainer reservedContainer = reservedContainers.remove(node.getNodeID());
        // as a consequence reservedcontainer might be null, adding NP-checks
        if (reservedContainer != null && reservedContainer.getContainer() != null && reservedContainer.getContainer().getResource() != null) {
            if (reservedContainers.isEmpty()) {
                this.reservedContainers.remove(schedulerKey);
            }
            // Reset the re-reservation count
            resetReReservations(schedulerKey);
            Resource resource = reservedContainer.getReservedResource();
            this.attemptResourceUsage.decReserved(node.getPartition(), resource);
            LOG.info("Application " + getApplicationId() + " unreserved " + " on node " + node + ", currently has " + reservedContainers.size() + " at priority " + schedulerKey.getPriority() + "; currentReservation " + this.attemptResourceUsage.getReserved() + " on node-label=" + node.getPartition());
            return true;
        }
    }
    return false;
}
Also used : NodeId(org.apache.hadoop.yarn.api.records.NodeId) Resource(org.apache.hadoop.yarn.api.records.Resource) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)

Example 95 with Resource

use of org.apache.hadoop.yarn.api.records.Resource in project hadoop by apache.

the class FiCaSchedulerApp method getAllocation.

/**
   * This method produces an Allocation that includes the current view
   * of the resources that will be allocated to and preempted from this
   * application.
   *
   * @param resourceCalculator resourceCalculator
   * @param clusterResource clusterResource
   * @param minimumAllocation minimumAllocation
   * @return an allocation
   */
public Allocation getAllocation(ResourceCalculator resourceCalculator, Resource clusterResource, Resource minimumAllocation) {
    try {
        writeLock.lock();
        Set<ContainerId> currentContPreemption = Collections.unmodifiableSet(new HashSet<ContainerId>(containersToPreempt));
        containersToPreempt.clear();
        Resource tot = Resource.newInstance(0, 0);
        for (ContainerId c : currentContPreemption) {
            Resources.addTo(tot, liveContainers.get(c).getContainer().getResource());
        }
        int numCont = (int) Math.ceil(Resources.divide(rc, clusterResource, tot, minimumAllocation));
        ResourceRequest rr = ResourceRequest.newBuilder().priority(Priority.UNDEFINED).resourceName(ResourceRequest.ANY).capability(minimumAllocation).numContainers(numCont).build();
        List<Container> newlyAllocatedContainers = pullNewlyAllocatedContainers();
        List<Container> newlyIncreasedContainers = pullNewlyIncreasedContainers();
        List<Container> newlyDecreasedContainers = pullNewlyDecreasedContainers();
        List<Container> newlyPromotedContainers = pullNewlyPromotedContainers();
        List<Container> newlyDemotedContainers = pullNewlyDemotedContainers();
        List<NMToken> updatedNMTokens = pullUpdatedNMTokens();
        Resource headroom = getHeadroom();
        setApplicationHeadroomForMetrics(headroom);
        return new Allocation(newlyAllocatedContainers, headroom, null, currentContPreemption, Collections.singletonList(rr), updatedNMTokens, newlyIncreasedContainers, newlyDecreasedContainers, newlyPromotedContainers, newlyDemotedContainers);
    } finally {
        writeLock.unlock();
    }
}
Also used : SchedulerContainer(org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.SchedulerContainer) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) Container(org.apache.hadoop.yarn.api.records.Container) NMToken(org.apache.hadoop.yarn.api.records.NMToken) Allocation(org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation) ContainerId(org.apache.hadoop.yarn.api.records.ContainerId) Resource(org.apache.hadoop.yarn.api.records.Resource) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest)

Aggregations

Resource (org.apache.hadoop.yarn.api.records.Resource)500 Test (org.junit.Test)190 NodeId (org.apache.hadoop.yarn.api.records.NodeId)89 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)82 Priority (org.apache.hadoop.yarn.api.records.Priority)80 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)67 HashMap (java.util.HashMap)62 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)57 RMContainer (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)55 FiCaSchedulerApp (org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerApp)53 ArrayList (java.util.ArrayList)49 ResourceLimits (org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceLimits)48 FiCaSchedulerNode (org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.fica.FiCaSchedulerNode)45 YarnConfiguration (org.apache.hadoop.yarn.conf.YarnConfiguration)43 Container (org.apache.hadoop.yarn.api.records.Container)42 ResourceRequest (org.apache.hadoop.yarn.api.records.ResourceRequest)42 Configuration (org.apache.hadoop.conf.Configuration)34 IOException (java.io.IOException)33 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)33 Map (java.util.Map)29