Class LightWeightResource

java.lang.Object
org.apache.hadoop.yarn.api.records.Resource
org.apache.hadoop.yarn.api.records.impl.LightWeightResource
All Implemented Interfaces:
Comparable<Resource>

@Private @Unstable public class LightWeightResource extends Resource

LightWeightResource extends Resource to handle base resources such as memory and CPU. TODO: We have a long term plan to use AbstractResource when additional resource types are to be handled as well. This will be used to speed up internal calculation to avoid creating costly PB-backed Resource object: ResourcePBImpl

Currently it models both memory and CPU.

The unit for memory is megabytes. CPU is modeled with virtual cores (vcores), a unit for expressing parallelism. A node's capacity should be configured with virtual cores equal to its number of physical cores. A container should be requested with the number of cores it can saturate, i.e. the average number of threads it expects to have runnable at a time.

Virtual cores take integer values and thus currently CPU-scheduling is very coarse. A complementary axis for CPU requests that represents processing power will likely be added in the future to enable finer-grained resource configuration.

See Also:
  • Constructor Details

    • LightWeightResource

      public LightWeightResource(long memory, int vcores)
    • LightWeightResource

      public LightWeightResource(long memory, int vcores, ResourceInformation[] source)
  • Method Details

    • getMemory

      public int getMemory()
      Description copied from class: Resource
      This method is DEPRECATED: Use Resource.getMemorySize() instead Get memory of the resource. Note - while memory has never had a unit specified, all YARN configurations have specified memory in MB. The assumption has been that the daemons and applications are always using the same units. With the introduction of the ResourceInformation class we have support for units - so this function will continue to return memory but in the units of MB
      Specified by:
      getMemory in class Resource
      Returns:
      memory(in MB) of the resource
    • setMemory

      public void setMemory(int memory)
      Description copied from class: Resource
      Set memory of the resource. Note - while memory has never had a unit specified, all YARN configurations have specified memory in MB. The assumption has been that the daemons and applications are always using the same units. With the introduction of the ResourceInformation class we have support for units - so this function will continue to set memory but the assumption is that the value passed is in units of MB.
      Specified by:
      setMemory in class Resource
      Parameters:
      memory - memory(in MB) of the resource
    • getMemorySize

      public long getMemorySize()
      Description copied from class: Resource
      Get memory of the resource. Note - while memory has never had a unit specified, all YARN configurations have specified memory in MB. The assumption has been that the daemons and applications are always using the same units. With the introduction of the ResourceInformation class we have support for units - so this function will continue to return memory but in the units of MB
      Overrides:
      getMemorySize in class Resource
      Returns:
      memory of the resource
    • setMemorySize

      public void setMemorySize(long memory)
      Description copied from class: Resource
      Set memory of the resource.
      Overrides:
      setMemorySize in class Resource
      Parameters:
      memory - memory of the resource
    • getVirtualCores

      public int getVirtualCores()
      Description copied from class: Resource
      Get number of virtual cpu cores of the resource. Virtual cores are a unit for expressing CPU parallelism. A node's capacity should be configured with virtual cores equal to its number of physical cores. A container should be requested with the number of cores it can saturate, i.e. the average number of threads it expects to have runnable at a time.
      Specified by:
      getVirtualCores in class Resource
      Returns:
      num of virtual cpu cores of the resource
    • setVirtualCores

      public void setVirtualCores(int vcores)
      Description copied from class: Resource
      Set number of virtual cpu cores of the resource. Virtual cores are a unit for expressing CPU parallelism. A node's capacity should be configured with virtual cores equal to its number of physical cores. A container should be requested with the number of cores it can saturate, i.e. the average number of threads it expects to have runnable at a time.
      Specified by:
      setVirtualCores in class Resource
      Parameters:
      vcores - number of virtual cpu cores of the resource
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Resource
    • compareTo

      public int compareTo(Resource other)
      Specified by:
      compareTo in interface Comparable<Resource>
      Overrides:
      compareTo in class Resource
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Resource