Search in sources :

Example 26 with ResourceCalculator

use of org.apache.hadoop.yarn.util.resource.ResourceCalculator in project hadoop by apache.

the class TestSchedulerUtils method testNormalizeRequest.

@Test(timeout = 30000)
public void testNormalizeRequest() {
    ResourceCalculator resourceCalculator = new DefaultResourceCalculator();
    final int minMemory = 1024;
    final int maxMemory = 8192;
    Resource minResource = Resources.createResource(minMemory, 0);
    Resource maxResource = Resources.createResource(maxMemory, 0);
    ResourceRequest ask = new ResourceRequestPBImpl();
    // case negative memory
    ask.setCapability(Resources.createResource(-1024));
    SchedulerUtils.normalizeRequest(ask, resourceCalculator, minResource, maxResource);
    assertEquals(minMemory, ask.getCapability().getMemorySize());
    // case zero memory
    ask.setCapability(Resources.createResource(0));
    SchedulerUtils.normalizeRequest(ask, resourceCalculator, minResource, maxResource);
    assertEquals(minMemory, ask.getCapability().getMemorySize());
    // case memory is a multiple of minMemory
    ask.setCapability(Resources.createResource(2 * minMemory));
    SchedulerUtils.normalizeRequest(ask, resourceCalculator, minResource, maxResource);
    assertEquals(2 * minMemory, ask.getCapability().getMemorySize());
    // case memory is not a multiple of minMemory
    ask.setCapability(Resources.createResource(minMemory + 10));
    SchedulerUtils.normalizeRequest(ask, resourceCalculator, minResource, maxResource);
    assertEquals(2 * minMemory, ask.getCapability().getMemorySize());
    // case memory is equal to max allowed
    ask.setCapability(Resources.createResource(maxMemory));
    SchedulerUtils.normalizeRequest(ask, resourceCalculator, minResource, maxResource);
    assertEquals(maxMemory, ask.getCapability().getMemorySize());
    // case memory is just less than max
    ask.setCapability(Resources.createResource(maxMemory - 10));
    SchedulerUtils.normalizeRequest(ask, resourceCalculator, minResource, maxResource);
    assertEquals(maxMemory, ask.getCapability().getMemorySize());
    // max is not a multiple of min
    maxResource = Resources.createResource(maxMemory - 10, 0);
    ask.setCapability(Resources.createResource(maxMemory - 100));
    // multiple of minMemory > maxMemory, then reduce to maxMemory
    SchedulerUtils.normalizeRequest(ask, resourceCalculator, minResource, maxResource);
    assertEquals(maxResource.getMemorySize(), ask.getCapability().getMemorySize());
    // ask is more than max
    maxResource = Resources.createResource(maxMemory, 0);
    ask.setCapability(Resources.createResource(maxMemory + 100));
    SchedulerUtils.normalizeRequest(ask, resourceCalculator, minResource, maxResource);
    assertEquals(maxResource.getMemorySize(), ask.getCapability().getMemorySize());
}
Also used : DefaultResourceCalculator(org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator) DominantResourceCalculator(org.apache.hadoop.yarn.util.resource.DominantResourceCalculator) ResourceCalculator(org.apache.hadoop.yarn.util.resource.ResourceCalculator) DefaultResourceCalculator(org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator) Resource(org.apache.hadoop.yarn.api.records.Resource) ResourceRequestPBImpl(org.apache.hadoop.yarn.api.records.impl.pb.ResourceRequestPBImpl) ResourceRequest(org.apache.hadoop.yarn.api.records.ResourceRequest) Test(org.junit.Test)

Aggregations

ResourceCalculator (org.apache.hadoop.yarn.util.resource.ResourceCalculator)26 Resource (org.apache.hadoop.yarn.api.records.Resource)22 DefaultResourceCalculator (org.apache.hadoop.yarn.util.resource.DefaultResourceCalculator)16 Test (org.junit.Test)10 DominantResourceCalculator (org.apache.hadoop.yarn.util.resource.DominantResourceCalculator)6 Entry (java.util.Map.Entry)5 ReservationId (org.apache.hadoop.yarn.api.records.ReservationId)4 TreeSet (java.util.TreeSet)3 ApplicationAttemptId (org.apache.hadoop.yarn.api.records.ApplicationAttemptId)3 ReservationDefinition (org.apache.hadoop.yarn.api.records.ReservationDefinition)3 ReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.ReservationAllocation)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 ApplicationId (org.apache.hadoop.yarn.api.records.ApplicationId)2 ResourceRequest (org.apache.hadoop.yarn.api.records.ResourceRequest)2 ResourceRequestPBImpl (org.apache.hadoop.yarn.api.records.impl.pb.ResourceRequestPBImpl)2 ReservationAllocationStateProto (org.apache.hadoop.yarn.proto.YarnProtos.ReservationAllocationStateProto)2 RMContext (org.apache.hadoop.yarn.server.resourcemanager.RMContext)2 InMemoryReservationAllocation (org.apache.hadoop.yarn.server.resourcemanager.reservation.InMemoryReservationAllocation)2 ResourceUsage (org.apache.hadoop.yarn.server.resourcemanager.scheduler.ResourceUsage)2