Java Code Examples for org.apache.hadoop.yarn.util.resource.Resources#divide()

The following examples show how to use org.apache.hadoop.yarn.util.resource.Resources#divide() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestWorkPreservingRMRestart.java    From hadoop with Apache License 2.0 6 votes vote down vote up
private void checkCSLeafQueue(MockRM rm,
    SchedulerApplication<SchedulerApplicationAttempt> app,
    Resource clusterResource, Resource queueResource, Resource usedResource,
    int numContainers) {
  LeafQueue leafQueue = (LeafQueue) app.getQueue();
  // assert queue used resources.
  assertEquals(usedResource, leafQueue.getUsedResources());
  assertEquals(numContainers, leafQueue.getNumContainers());

  ResourceCalculator calc =
      ((CapacityScheduler) rm.getResourceScheduler()).getResourceCalculator();
  float usedCapacity =
      Resources.divide(calc, clusterResource, usedResource, queueResource);
  // assert queue used capacity
  assertEquals(usedCapacity, leafQueue.getUsedCapacity(), 1e-8);
  float absoluteUsedCapacity =
      Resources.divide(calc, clusterResource, usedResource, clusterResource);
  // assert queue absolute capacity
  assertEquals(absoluteUsedCapacity, leafQueue.getAbsoluteUsedCapacity(),
    1e-8);
  // assert user consumed resources.
  assertEquals(usedResource, leafQueue.getUser(app.getUser())
    .getUsed());
}
 
Example 2
Source File: TestWorkPreservingRMRestart.java    From big-c with Apache License 2.0 6 votes vote down vote up
private void checkCSLeafQueue(MockRM rm,
    SchedulerApplication<SchedulerApplicationAttempt> app,
    Resource clusterResource, Resource queueResource, Resource usedResource,
    int numContainers) {
  LeafQueue leafQueue = (LeafQueue) app.getQueue();
  // assert queue used resources.
  assertEquals(usedResource, leafQueue.getUsedResources());
  assertEquals(numContainers, leafQueue.getNumContainers());

  ResourceCalculator calc =
      ((CapacityScheduler) rm.getResourceScheduler()).getResourceCalculator();
  float usedCapacity =
      Resources.divide(calc, clusterResource, usedResource, queueResource);
  // assert queue used capacity
  assertEquals(usedCapacity, leafQueue.getUsedCapacity(), 1e-8);
  float absoluteUsedCapacity =
      Resources.divide(calc, clusterResource, usedResource, clusterResource);
  // assert queue absolute capacity
  assertEquals(absoluteUsedCapacity, leafQueue.getAbsoluteUsedCapacity(),
    1e-8);
  // assert user consumed resources.
  assertEquals(usedResource, leafQueue.getUser(app.getUser())
    .getUsed());
}
 
Example 3
Source File: CapacitySchedulerPlanFollower.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Override
protected float calculateReservationToPlanRatio(
    Resource clusterResources, Resource planResources,
    Resource reservationResources) {
  return Resources.divide(cs.getResourceCalculator(),
      clusterResources, reservationResources, planResources);
}
 
Example 4
Source File: AbstractCSQueue.java    From hadoop with Apache License 2.0 5 votes vote down vote up
/**
 * Used capacity of label =
 *   (queue's used resources labeled by nodeLabel)
 *      / (   (all resources labeled by nodLabel)
 *          X (percent of labeled resources allocated to this queue)  )
 */
public synchronized float getUsedCapacity(String nodeLabel) {
  Resource availableToQueue =
      Resources.multiply(labelManager.getResourceByLabel(nodeLabel, cr),
          queueCapacities.getAbsoluteCapacity(nodeLabel));
  if (!Resources.greaterThan(resourceCalculator, cr,
       availableToQueue, Resources.none())) {
    return 0.0f;
  }
  return
      Resources.divide(resourceCalculator, cr,
          queueUsage.getUsed(nodeLabel), availableToQueue);
}
 
Example 5
Source File: AbstractCSQueue.java    From hadoop with Apache License 2.0 5 votes vote down vote up
public float getAbsoluteUsedCapacity(String nodeLabel) {
  Resource labeledResources = labelManager.getResourceByLabel(nodeLabel, cr);
  if (!Resources.greaterThan(resourceCalculator, cr,
      labeledResources, Resources.none())) {
    return 0.0f;
  }
  return Resources.divide(resourceCalculator, cr,
      queueUsage.getUsed(nodeLabel), labeledResources);
}
 
Example 6
Source File: CSQueueUtils.java    From hadoop with Apache License 2.0 5 votes vote down vote up
@Lock(CSQueue.class)
public static void updateQueueStatistics(
    final ResourceCalculator calculator,
    final CSQueue childQueue, final CSQueue parentQueue, 
    final Resource clusterResource, final Resource minimumAllocation) {
  Resource queueLimit = Resources.none();
  Resource usedResources = childQueue.getUsedResources();
  
  float absoluteUsedCapacity = 0.0f;
  float usedCapacity = 0.0f;

  if (Resources.greaterThan(
      calculator, clusterResource, clusterResource, Resources.none())) {
    queueLimit = 
        Resources.multiply(clusterResource, childQueue.getAbsoluteCapacity());
    absoluteUsedCapacity = 
        Resources.divide(calculator, clusterResource, 
            usedResources, clusterResource);
    usedCapacity = 
        Resources.equals(queueLimit, Resources.none()) ? 0 :
        Resources.divide(calculator, clusterResource, 
            usedResources, queueLimit);
  }

  childQueue.setUsedCapacity(usedCapacity);
  childQueue.setAbsoluteUsedCapacity(absoluteUsedCapacity);
  
  Resource available = Resources.subtract(queueLimit, usedResources);
  childQueue.getMetrics().setAvailableResourcesToQueue(
      Resources.max(
          calculator, 
          clusterResource, 
          available, 
          Resources.none()
          )
      );
 }
 
Example 7
Source File: ProportionalCapacityPreemptionPolicy.java    From hadoop with Apache License 2.0 5 votes vote down vote up
private double getIdealPctOfGuaranteed(TempQueue q) {
  double pctOver = Integer.MAX_VALUE;
  if (q != null && Resources.greaterThan(
      rc, clusterRes, q.guaranteed, Resources.none())) {
    pctOver =
        Resources.divide(rc, clusterRes, q.idealAssigned, q.guaranteed);
  }
  return (pctOver);
}
 
Example 8
Source File: CapacitySchedulerPlanFollower.java    From big-c with Apache License 2.0 5 votes vote down vote up
@Override
protected float calculateReservationToPlanRatio(
    Resource clusterResources, Resource planResources,
    Resource reservationResources) {
  return Resources.divide(cs.getResourceCalculator(),
      clusterResources, reservationResources, planResources);
}
 
Example 9
Source File: ProportionalCapacityPreemptionPolicy.java    From big-c with Apache License 2.0 5 votes vote down vote up
private double getIdealPctOfGuaranteed(TempQueue q) {
  double pctOver = Integer.MAX_VALUE;
  if (q != null && Resources.greaterThan(
      rc, clusterRes, q.guaranteed, Resources.none())) {
    pctOver =
        Resources.divide(rc, clusterRes, q.idealAssigned, q.guaranteed);
  }
  return (pctOver);
}
 
Example 10
Source File: FairSchedulerPlanFollower.java    From hadoop with Apache License 2.0 4 votes vote down vote up
@Override
protected float calculateReservationToPlanRatio(Resource clusterResources,
    Resource planResources, Resource capToAssign) {
  return Resources.divide(fs.getResourceCalculator(),
      clusterResources, capToAssign, planResources);
}
 
Example 11
Source File: FairSchedulerPlanFollower.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Override
protected float calculateReservationToPlanRatio(Resource clusterResources,
    Resource planResources, Resource capToAssign) {
  return Resources.divide(fs.getResourceCalculator(),
      clusterResources, capToAssign, planResources);
}
 
Example 12
Source File: CSQueueUtils.java    From big-c with Apache License 2.0 4 votes vote down vote up
@Lock(CSQueue.class)
public static void updateQueueStatistics(
    final ResourceCalculator calculator,
    final CSQueue childQueue, final CSQueue parentQueue, 
    final Resource clusterResource, final Resource minimumAllocation) {
  Resource queueLimit = Resources.none();
  Resource usedResources = childQueue.getUsedResources();
  
  float absoluteUsedCapacity = 0.0f;
  float usedCapacity = 0.0f;

  if (Resources.greaterThan(
      calculator, clusterResource, clusterResource, Resources.none())) {
    queueLimit = 
        Resources.multiply(clusterResource, childQueue.getAbsoluteCapacity());
    
    //absoluteUsedCapacity = 
    //    Resources.divide(calculator, clusterResource, 
    //        usedResources, clusterResource);
    
    absoluteUsedCapacity = (float) ((usedResources.getVirtualCores()*1.0)/(clusterResource.getVirtualCores()*1.0));
  
    usedCapacity = 
        Resources.equals(queueLimit, Resources.none()) ? 0 :
        Resources.divide(calculator, clusterResource, 
            usedResources, queueLimit);
  }

  childQueue.setUsedCapacity(usedCapacity);
  childQueue.setAbsoluteUsedCapacity(absoluteUsedCapacity);
  
  Resource available = Resources.subtract(queueLimit, usedResources);
  childQueue.getMetrics().setAvailableResourcesToQueue(
      Resources.max(
          calculator, 
          clusterResource, 
          available, 
          Resources.none()
          )
      );
 }