Search in sources :

Example 96 with Resource

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

the class FSAppAttempt method fairShareStarvation.

/**
   * Helper method that computes the extent of fairshare starvation.
   * @return freshly computed fairshare starvation
   */
Resource fairShareStarvation() {
    long now = scheduler.getClock().getTime();
    Resource threshold = Resources.multiply(getFairShare(), fsQueue.getFairSharePreemptionThreshold());
    Resource fairDemand = Resources.componentwiseMin(threshold, demand);
    // Check if the queue is starved for fairshare
    boolean starved = isUsageBelowShare(getResourceUsage(), fairDemand);
    if (!starved) {
        lastTimeAtFairShare = now;
    }
    if (!starved || now - lastTimeAtFairShare < fsQueue.getFairSharePreemptionTimeout()) {
        fairshareStarvation = Resources.none();
    } else {
        // The app has been starved for longer than preemption-timeout.
        fairshareStarvation = Resources.subtractFromNonNegative(fairDemand, getResourceUsage());
    }
    return fairshareStarvation;
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource)

Example 97 with Resource

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

the class FifoScheduler method allocate.

@Override
public Allocation allocate(ApplicationAttemptId applicationAttemptId, List<ResourceRequest> ask, List<ContainerId> release, List<String> blacklistAdditions, List<String> blacklistRemovals, ContainerUpdates updateRequests) {
    FifoAppAttempt application = getApplicationAttempt(applicationAttemptId);
    if (application == null) {
        LOG.error("Calling allocate on removed " + "or non-existent application " + applicationAttemptId);
        return EMPTY_ALLOCATION;
    }
    // Sanity check
    normalizeRequests(ask);
    // Release containers
    releaseContainers(release, application);
    synchronized (application) {
        // when the allocate comes in
        if (application.isStopped()) {
            LOG.info("Calling allocate on a stopped " + "application " + applicationAttemptId);
            return EMPTY_ALLOCATION;
        }
        if (!ask.isEmpty()) {
            LOG.debug("allocate: pre-update" + " applicationId=" + applicationAttemptId + " application=" + application);
            application.showRequests();
            // Update application requests
            application.updateResourceRequests(ask);
            LOG.debug("allocate: post-update" + " applicationId=" + applicationAttemptId + " application=" + application);
            application.showRequests();
            LOG.debug("allocate:" + " applicationId=" + applicationAttemptId + " #ask=" + ask.size());
        }
        application.updateBlacklist(blacklistAdditions, blacklistRemovals);
        Resource headroom = application.getHeadroom();
        application.setApplicationHeadroomForMetrics(headroom);
        return new Allocation(application.pullNewlyAllocatedContainers(), headroom, null, null, null, application.pullUpdatedNMTokens());
    }
}
Also used : Allocation(org.apache.hadoop.yarn.server.resourcemanager.scheduler.Allocation) Resource(org.apache.hadoop.yarn.api.records.Resource)

Example 98 with Resource

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

the class DominantResourceFairnessPolicy method getHeadroom.

@Override
public Resource getHeadroom(Resource queueFairShare, Resource queueUsage, Resource maxAvailable) {
    long queueAvailableMemory = Math.max(queueFairShare.getMemorySize() - queueUsage.getMemorySize(), 0);
    int queueAvailableCPU = Math.max(queueFairShare.getVirtualCores() - queueUsage.getVirtualCores(), 0);
    Resource headroom = Resources.createResource(Math.min(maxAvailable.getMemorySize(), queueAvailableMemory), Math.min(maxAvailable.getVirtualCores(), queueAvailableCPU));
    return headroom;
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource)

Example 99 with Resource

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

the class FairScheduler method applyChildDefaults.

/**
   * After reloading the allocation config, the max resource settings for any
   * ad hoc queues will be missing. This method goes through the queue manager's
   * queue list and adds back the max resources settings for any ad hoc queues.
   * Note that the new max resource settings will be based on the new config.
   * The old settings are lost.
   */
private void applyChildDefaults() {
    Collection<FSQueue> queues = queueMgr.getQueues();
    Set<String> configuredLeafQueues = allocConf.getConfiguredQueues().get(FSQueueType.LEAF);
    Set<String> configuredParentQueues = allocConf.getConfiguredQueues().get(FSQueueType.PARENT);
    for (FSQueue queue : queues) {
        // If the queue is ad hoc and not root, apply the child defaults
        if ((queue.getParent() != null) && !configuredLeafQueues.contains(queue.getName()) && !configuredParentQueues.contains(queue.getName())) {
            Resource max = queue.getParent().getMaxChildQueueResource();
            if (max != null) {
                queue.setMaxShare(max);
            }
        }
    }
}
Also used : Resource(org.apache.hadoop.yarn.api.records.Resource)

Example 100 with Resource

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

the class FairScheduler method allocate.

@Override
public Allocation allocate(ApplicationAttemptId appAttemptId, List<ResourceRequest> ask, List<ContainerId> release, List<String> blacklistAdditions, List<String> blacklistRemovals, ContainerUpdates updateRequests) {
    // Make sure this application exists
    FSAppAttempt application = getSchedulerApp(appAttemptId);
    if (application == null) {
        LOG.info("Calling allocate on removed " + "or non existent application " + appAttemptId);
        return EMPTY_ALLOCATION;
    }
    // Handle promotions and demotions
    handleContainerUpdates(application, updateRequests);
    // Sanity check
    normalizeRequests(ask);
    // Record container allocation start time
    application.recordContainerRequestTime(getClock().getTime());
    // Release containers
    releaseContainers(release, application);
    ReentrantReadWriteLock.WriteLock lock = application.getWriteLock();
    lock.lock();
    try {
        if (!ask.isEmpty()) {
            if (LOG.isDebugEnabled()) {
                LOG.debug("allocate: pre-update" + " applicationAttemptId=" + appAttemptId + " application=" + application.getApplicationId());
            }
            application.showRequests();
            // Update application requests
            application.updateResourceRequests(ask);
            application.showRequests();
        }
    } finally {
        lock.unlock();
    }
    Set<ContainerId> preemptionContainerIds = application.getPreemptionContainerIds();
    if (LOG.isDebugEnabled()) {
        LOG.debug("allocate: post-update" + " applicationAttemptId=" + appAttemptId + " #ask=" + ask.size() + " reservation= " + application.getCurrentReservation());
        LOG.debug("Preempting " + preemptionContainerIds.size() + " container(s)");
    }
    application.updateBlacklist(blacklistAdditions, blacklistRemovals);
    List<Container> newlyAllocatedContainers = application.pullNewlyAllocatedContainers();
    // Record container allocation time
    if (!(newlyAllocatedContainers.isEmpty())) {
        application.recordContainerAllocationTime(getClock().getTime());
    }
    Resource headroom = application.getHeadroom();
    application.setApplicationHeadroomForMetrics(headroom);
    return new Allocation(newlyAllocatedContainers, headroom, preemptionContainerIds, null, null, application.pullUpdatedNMTokens(), null, null, application.pullNewlyPromotedContainers(), application.pullNewlyDemotedContainers());
}
Also used : RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) Container(org.apache.hadoop.yarn.api.records.Container) 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) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock)

Aggregations

Resource (org.apache.hadoop.yarn.api.records.Resource)498 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)79 ContainerId (org.apache.hadoop.yarn.api.records.ContainerId)67 HashMap (java.util.HashMap)62 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)56 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 ResourceRequest (org.apache.hadoop.yarn.api.records.ResourceRequest)42 Container (org.apache.hadoop.yarn.api.records.Container)41 Configuration (org.apache.hadoop.conf.Configuration)34 LocalResource (org.apache.hadoop.yarn.api.records.LocalResource)32 IOException (java.io.IOException)31 Map (java.util.Map)29