Class ResourceProfile

  • All Implemented Interfaces:
    Serializable

    public class ResourceProfile
    extends Object
    implements Serializable
    Describe the immutable resource profile of the slot, either when requiring or offering it. The profile can be checked whether it can match another profile's requirement, and furthermore we may calculate a matching score to decide which profile we should choose when we have lots of candidate slots. It should be generated from ResourceSpec with the input and output memory calculated in JobMaster.

    Resource Profiles have a total ordering, defined by comparing these fields in sequence:

    1. Memory Size
    2. CPU cores
    3. Extended resources
    The extended resources are compared ordered by the resource names.
    See Also:
    Serialized Form
    • Field Detail

      • UNKNOWN

        public static final ResourceProfile UNKNOWN
        A ResourceProfile that indicates an unknown resource requirement. This is mainly used for describing resource requirements that the exact amount of resource needed is not specified. It can also be used for describing remaining resource of a multi task slot that contains tasks with unknown resource requirements. It should not be used for describing total resource of a task executor / slot, which should always be specific.
      • ZERO

        public static final ResourceProfile ZERO
        A ResourceProfile describing zero resources.
    • Method Detail

      • getCpuCores

        public CPUResource getCpuCores()
        Get the cpu cores needed.
        Returns:
        The cpu cores, 1.0 means a full cpu thread
      • getTaskHeapMemory

        public MemorySize getTaskHeapMemory()
        Get the task heap memory needed.
        Returns:
        The task heap memory
      • getTaskOffHeapMemory

        public MemorySize getTaskOffHeapMemory()
        Get the task off-heap memory needed.
        Returns:
        The task off-heap memory
      • getManagedMemory

        public MemorySize getManagedMemory()
        Get the managed memory needed.
        Returns:
        The managed memory
      • getNetworkMemory

        public MemorySize getNetworkMemory()
        Get the network memory needed.
        Returns:
        The network memory
      • getTotalMemory

        public MemorySize getTotalMemory()
        Get the total memory needed.
        Returns:
        The total memory
      • getOperatorsMemory

        public MemorySize getOperatorsMemory()
        Get the memory the operators needed.
        Returns:
        The operator memory
      • getExtendedResources

        public Map<String,​ExternalResource> getExtendedResources()
        Get the extended resources.
        Returns:
        The extended resources
      • isMatching

        public boolean isMatching​(ResourceProfile required)
        Check whether required resource profile can be matched.
        Parameters:
        required - the required resource profile
        Returns:
        true if the requirement is matched, otherwise false
      • allFieldsNoLessThan

        public boolean allFieldsNoLessThan​(ResourceProfile other)
        Check whether all fields of this resource profile are no less than the given resource profile.

        It is not same with the total resource comparison. It return true iff each resource field(cpu, task heap memory, managed memory, etc.) is no less than the respective field of the given profile.

        For example, assume that this profile has 1 core, 50 managed memory and 100 heap memory.

        1. The comparison will return false if the other profile has 2 core, 10 managed memory and 1000 heap memory.
        2. The comparison will return true if the other profile has 1 core, 50 managed memory and 150 heap memory.
        Parameters:
        other - the other resource profile
        Returns:
        true if all fields of this are no less than the other's, otherwise false
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • merge

        @Nonnull
        public ResourceProfile merge​(ResourceProfile other)
        Calculates the sum of two resource profiles.
        Parameters:
        other - The other resource profile to add.
        Returns:
        The merged resource profile.
      • subtract

        public ResourceProfile subtract​(ResourceProfile other)
        Subtracts another piece of resource profile from this one.
        Parameters:
        other - The other resource profile to subtract.
        Returns:
        The subtracted resource profile.