org.apache.hadoop.yarn.api.records.impl

## 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>

      @InterfaceAudience.Private
       @InterfaceStability.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:
    `Resource`

- - ### Field Summary

    - ### Fields inherited from class org.apache.hadoop.yarn.api.records.Resource

      `MEMORY_INDEX, NUM_MANDATORY_RESOURCES, resources, VCORES_INDEX`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `LightWeightResource(long memory, int vcores)`
    `LightWeightResource(long memory, int vcores, ResourceInformation[] source)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `compareTo(Resource other)`
    `boolean` | `equals(Object obj)`
    `int` | `getMemory()` This method is DEPRECATED: Use `Resource.getMemorySize()` instead Get memory of the resource.
    `long` | `getMemorySize()` Get memory of the resource.
    `int` | `getVirtualCores()` Get number of virtual cpu cores of the resource.
    `int` | `hashCode()`
    `void` | `setMemory(int memory)` Set memory of the resource.
    `void` | `setMemorySize(long memory)` Set memory of the resource.
    `void` | `setVirtualCores(int vcores)` Set number of virtual cpu cores of the resource.

    - ### Methods inherited from class org.apache.hadoop.yarn.api.records.Resource

      `castToIntSafely, copy, getAllResourcesListCopy, getFormattedString, getResourceInformation, getResourceInformation, getResources, getResourceValue, newDefaultInformation, newInstance, newInstance, newInstance, newInstance, setResourceInformation, setResourceInformation, setResourceValue, setResourceValue, throwExceptionWhenArrayOutOfBound, toString`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### LightWeightResource

          public LightWeightResource(long memory,
                                     int vcores)

    - #### LightWeightResource

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

  - ### Method Detail

    - #### 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`

Copyright © 2008–2022 Apache Software Foundation. All rights reserved.