Search in sources :

Example 1 with NodeType

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType in project hadoop by apache.

the class RegularContainerAllocator method assignContainersOnNode.

private ContainerAllocation assignContainersOnNode(Resource clusterResource, FiCaSchedulerNode node, SchedulerRequestKey schedulerKey, RMContainer reservedContainer, SchedulingMode schedulingMode, ResourceLimits currentResoureLimits) {
    Priority priority = schedulerKey.getPriority();
    ContainerAllocation allocation;
    NodeType requestLocalityType = null;
    // Data-local
    PendingAsk nodeLocalAsk = application.getPendingAsk(schedulerKey, node.getNodeName());
    if (nodeLocalAsk.getCount() > 0) {
        requestLocalityType = NodeType.NODE_LOCAL;
        allocation = assignNodeLocalContainers(clusterResource, nodeLocalAsk, node, schedulerKey, reservedContainer, schedulingMode, currentResoureLimits);
        if (Resources.greaterThan(rc, clusterResource, allocation.getResourceToBeAllocated(), Resources.none())) {
            allocation.requestLocalityType = requestLocalityType;
            return allocation;
        }
    }
    // Rack-local
    PendingAsk rackLocalAsk = application.getPendingAsk(schedulerKey, node.getRackName());
    if (rackLocalAsk.getCount() > 0) {
        if (!appInfo.canDelayTo(schedulerKey, node.getRackName())) {
            ActivitiesLogger.APP.recordSkippedAppActivityWithoutAllocation(activitiesManager, node, application, priority, ActivityDiagnosticConstant.SKIP_PRIORITY_BECAUSE_OF_RELAX_LOCALITY);
            return ContainerAllocation.PRIORITY_SKIPPED;
        }
        requestLocalityType = requestLocalityType == null ? NodeType.RACK_LOCAL : requestLocalityType;
        allocation = assignRackLocalContainers(clusterResource, rackLocalAsk, node, schedulerKey, reservedContainer, schedulingMode, currentResoureLimits);
        if (Resources.greaterThan(rc, clusterResource, allocation.getResourceToBeAllocated(), Resources.none())) {
            allocation.requestLocalityType = requestLocalityType;
            return allocation;
        }
    }
    // Off-switch
    PendingAsk offSwitchAsk = application.getPendingAsk(schedulerKey, ResourceRequest.ANY);
    if (offSwitchAsk.getCount() > 0) {
        if (!appInfo.canDelayTo(schedulerKey, ResourceRequest.ANY)) {
            ActivitiesLogger.APP.recordSkippedAppActivityWithoutAllocation(activitiesManager, node, application, priority, ActivityDiagnosticConstant.SKIP_PRIORITY_BECAUSE_OF_RELAX_LOCALITY);
            return ContainerAllocation.PRIORITY_SKIPPED;
        }
        requestLocalityType = requestLocalityType == null ? NodeType.OFF_SWITCH : requestLocalityType;
        allocation = assignOffSwitchContainers(clusterResource, offSwitchAsk, node, schedulerKey, reservedContainer, schedulingMode, currentResoureLimits);
        // off-switch request now, we will skip this app w.r.t priorities 
        if (allocation.state == AllocationState.LOCALITY_SKIPPED) {
            allocation.state = AllocationState.APP_SKIPPED;
        }
        allocation.requestLocalityType = requestLocalityType;
        return allocation;
    }
    ActivitiesLogger.APP.recordSkippedAppActivityWithoutAllocation(activitiesManager, node, application, priority, ActivityDiagnosticConstant.PRIORITY_SKIPPED);
    return ContainerAllocation.PRIORITY_SKIPPED;
}
Also used : Priority(org.apache.hadoop.yarn.api.records.Priority) NodeType(org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType) PendingAsk(org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.PendingAsk)

Example 2 with NodeType

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType in project hadoop by apache.

the class FSAppAttempt method allocate.

public RMContainer allocate(NodeType type, FSSchedulerNode node, SchedulerRequestKey schedulerKey, PendingAsk pendingAsk, Container reservedContainer) {
    RMContainer rmContainer;
    Container container;
    try {
        writeLock.lock();
        // Update allowed locality level
        NodeType allowed = allowedLocalityLevel.get(schedulerKey);
        if (allowed != null) {
            if (allowed.equals(NodeType.OFF_SWITCH) && (type.equals(NodeType.NODE_LOCAL) || type.equals(NodeType.RACK_LOCAL))) {
                this.resetAllowedLocalityLevel(schedulerKey, type);
            } else if (allowed.equals(NodeType.RACK_LOCAL) && type.equals(NodeType.NODE_LOCAL)) {
                this.resetAllowedLocalityLevel(schedulerKey, type);
            }
        }
        // request without locking the scheduler, hence we need to check
        if (getOutstandingAsksCount(schedulerKey) <= 0) {
            return null;
        }
        container = reservedContainer;
        if (container == null) {
            container = createContainer(node, pendingAsk.getPerAllocationResource(), schedulerKey);
        }
        // Create RMContainer
        rmContainer = new RMContainerImpl(container, schedulerKey, getApplicationAttemptId(), node.getNodeID(), appSchedulingInfo.getUser(), rmContext);
        ((RMContainerImpl) rmContainer).setQueueName(this.getQueueName());
        // Add it to allContainers list.
        addToNewlyAllocatedContainers(node, rmContainer);
        liveContainers.put(container.getId(), rmContainer);
        // Update consumption and track allocations
        List<ResourceRequest> resourceRequestList = appSchedulingInfo.allocate(type, node, schedulerKey, container);
        this.attemptResourceUsage.incUsed(container.getResource());
        // Update resource requests related to "request" and store in RMContainer
        ((RMContainerImpl) rmContainer).setResourceRequests(resourceRequestList);
        // Inform the container
        rmContainer.handle(new RMContainerEvent(container.getId(), RMContainerEventType.START));
        if (LOG.isDebugEnabled()) {
            LOG.debug("allocate: applicationAttemptId=" + container.getId().getApplicationAttemptId() + " container=" + container.getId() + " host=" + container.getNodeId().getHost() + " type=" + type);
        }
        RMAuditLogger.logSuccess(getUser(), AuditConstants.ALLOC_CONTAINER, "SchedulerApp", getApplicationId(), container.getId(), container.getResource());
    } finally {
        writeLock.unlock();
    }
    return rmContainer;
}
Also used : RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer) Container(org.apache.hadoop.yarn.api.records.Container) RMContainerImpl(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerImpl) RMContainerEvent(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerEvent) NodeType(org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest) RMContainer(org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)

Example 3 with NodeType

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType in project hadoop by apache.

the class FSAppAttempt method getAllowedLocalityLevelByTime.

/**
   * Return the level at which we are allowed to schedule containers.
   * Given the thresholds indicating how much time passed before relaxing
   * scheduling constraints.
   * @param schedulerKey SchedulerRequestKey
   * @param nodeLocalityDelayMs nodeLocalityThreshold
   * @param rackLocalityDelayMs nodeLocalityDelayMs
   * @param currentTimeMs currentTimeMs
   * @return NodeType
   */
NodeType getAllowedLocalityLevelByTime(SchedulerRequestKey schedulerKey, long nodeLocalityDelayMs, long rackLocalityDelayMs, long currentTimeMs) {
    // if not being used, can schedule anywhere
    if (nodeLocalityDelayMs < 0 || rackLocalityDelayMs < 0) {
        return NodeType.OFF_SWITCH;
    }
    try {
        writeLock.lock();
        // default level is NODE_LOCAL
        if (!allowedLocalityLevel.containsKey(schedulerKey)) {
            // add the initial time of priority to prevent comparing with FsApp
            // startTime and allowedLocalityLevel degrade
            lastScheduledContainer.put(schedulerKey, currentTimeMs);
            if (LOG.isDebugEnabled()) {
                LOG.debug("Init the lastScheduledContainer time, priority: " + schedulerKey.getPriority() + ", time: " + currentTimeMs);
            }
            allowedLocalityLevel.put(schedulerKey, NodeType.NODE_LOCAL);
            return NodeType.NODE_LOCAL;
        }
        NodeType allowed = allowedLocalityLevel.get(schedulerKey);
        // if level is already most liberal, we're done
        if (allowed.equals(NodeType.OFF_SWITCH)) {
            return NodeType.OFF_SWITCH;
        }
        // check waiting time
        long waitTime = currentTimeMs;
        if (lastScheduledContainer.containsKey(schedulerKey)) {
            waitTime -= lastScheduledContainer.get(schedulerKey);
        } else {
            waitTime -= getStartTime();
        }
        long thresholdTime = allowed.equals(NodeType.NODE_LOCAL) ? nodeLocalityDelayMs : rackLocalityDelayMs;
        if (waitTime > thresholdTime) {
            if (allowed.equals(NodeType.NODE_LOCAL)) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Waiting time: " + waitTime + " ms, nodeLocalityDelay time: " + nodeLocalityDelayMs + " ms" + ", change allowedLocality from NODE_LOCAL to RACK_LOCAL" + ", priority: " + schedulerKey.getPriority() + ", app attempt id: " + this.attemptId);
                }
                allowedLocalityLevel.put(schedulerKey, NodeType.RACK_LOCAL);
                resetSchedulingOpportunities(schedulerKey, currentTimeMs);
            } else if (allowed.equals(NodeType.RACK_LOCAL)) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Waiting time: " + waitTime + " ms, nodeLocalityDelay time: " + nodeLocalityDelayMs + " ms" + ", change allowedLocality from RACK_LOCAL to OFF_SWITCH" + ", priority: " + schedulerKey.getPriority() + ", app attempt id: " + this.attemptId);
                }
                allowedLocalityLevel.put(schedulerKey, NodeType.OFF_SWITCH);
                resetSchedulingOpportunities(schedulerKey, currentTimeMs);
            }
        }
        return allowedLocalityLevel.get(schedulerKey);
    } finally {
        writeLock.unlock();
    }
}
Also used : NodeType(org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType)

Example 4 with NodeType

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType in project hadoop by apache.

the class FSAppAttempt method getAllowedLocalityLevel.

/**
   * Return the level at which we are allowed to schedule containers, given the
   * current size of the cluster and thresholds indicating how many nodes to
   * fail at (as a fraction of cluster size) before relaxing scheduling
   * constraints.
   * @param schedulerKey SchedulerRequestKey
   * @param numNodes Num Nodes
   * @param nodeLocalityThreshold nodeLocalityThreshold
   * @param rackLocalityThreshold rackLocalityThreshold
   * @return NodeType
   */
NodeType getAllowedLocalityLevel(SchedulerRequestKey schedulerKey, int numNodes, double nodeLocalityThreshold, double rackLocalityThreshold) {
    // upper limit on threshold
    if (nodeLocalityThreshold > 1.0) {
        nodeLocalityThreshold = 1.0;
    }
    if (rackLocalityThreshold > 1.0) {
        rackLocalityThreshold = 1.0;
    }
    // If delay scheduling is not being used, can schedule anywhere
    if (nodeLocalityThreshold < 0.0 || rackLocalityThreshold < 0.0) {
        return NodeType.OFF_SWITCH;
    }
    try {
        writeLock.lock();
        // Default level is NODE_LOCAL
        if (!allowedLocalityLevel.containsKey(schedulerKey)) {
            allowedLocalityLevel.put(schedulerKey, NodeType.NODE_LOCAL);
            return NodeType.NODE_LOCAL;
        }
        NodeType allowed = allowedLocalityLevel.get(schedulerKey);
        // If level is already most liberal, we're done
        if (allowed.equals(NodeType.OFF_SWITCH)) {
            return NodeType.OFF_SWITCH;
        }
        double threshold = allowed.equals(NodeType.NODE_LOCAL) ? nodeLocalityThreshold : rackLocalityThreshold;
        // Relax locality constraints once we've surpassed threshold.
        int schedulingOpportunities = getSchedulingOpportunities(schedulerKey);
        double thresholdNum = numNodes * threshold;
        if (schedulingOpportunities > thresholdNum) {
            if (allowed.equals(NodeType.NODE_LOCAL)) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("SchedulingOpportunities: " + schedulingOpportunities + ", nodeLocalityThreshold: " + thresholdNum + ", change allowedLocality from NODE_LOCAL to RACK_LOCAL" + ", priority: " + schedulerKey.getPriority() + ", app attempt id: " + this.attemptId);
                }
                allowedLocalityLevel.put(schedulerKey, NodeType.RACK_LOCAL);
                resetSchedulingOpportunities(schedulerKey);
            } else if (allowed.equals(NodeType.RACK_LOCAL)) {
                if (LOG.isTraceEnabled()) {
                    LOG.trace("SchedulingOpportunities: " + schedulingOpportunities + ", rackLocalityThreshold: " + thresholdNum + ", change allowedLocality from RACK_LOCAL to OFF_SWITCH" + ", priority: " + schedulerKey.getPriority() + ", app attempt id: " + this.attemptId);
                }
                allowedLocalityLevel.put(schedulerKey, NodeType.OFF_SWITCH);
                resetSchedulingOpportunities(schedulerKey);
            }
        }
        return allowedLocalityLevel.get(schedulerKey);
    } finally {
        writeLock.unlock();
    }
}
Also used : NodeType(org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType)

Example 5 with NodeType

use of org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType in project hadoop by apache.

the class FSAppAttempt method resetAllowedLocalityLevel.

/**
   * Should be called when the scheduler assigns a container at a higher
   * degree of locality than the current threshold. Reset the allowed locality
   * level to a higher degree of locality.
   * @param schedulerKey Scheduler Key
   * @param level NodeType
   */
void resetAllowedLocalityLevel(SchedulerRequestKey schedulerKey, NodeType level) {
    NodeType old;
    try {
        writeLock.lock();
        old = allowedLocalityLevel.put(schedulerKey, level);
    } finally {
        writeLock.unlock();
    }
    LOG.info("Raising locality level from " + old + " to " + level + " at " + " priority " + schedulerKey.getPriority());
}
Also used : NodeType(org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType)

Aggregations

NodeType (org.apache.hadoop.yarn.server.resourcemanager.scheduler.NodeType)6 PendingAsk (org.apache.hadoop.yarn.server.resourcemanager.scheduler.common.PendingAsk)2 Container (org.apache.hadoop.yarn.api.records.Container)1 Priority (org.apache.hadoop.yarn.api.records.Priority)1 ResourceRequest (org.apache.hadoop.yarn.api.records.ResourceRequest)1 RMContainer (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainer)1 RMContainerEvent (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerEvent)1 RMContainerImpl (org.apache.hadoop.yarn.server.resourcemanager.rmcontainer.RMContainerImpl)1 SchedulerRequestKey (org.apache.hadoop.yarn.server.scheduler.SchedulerRequestKey)1