Class ResourceProfile
java.lang.Object
org.apache.flink.runtime.clusterframework.types.ResourceProfile
- All Implemented Interfaces:
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:
- Memory Size
- CPU cores
- Extended resources
- See Also:
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final ResourceProfileA ResourceProfile that indicates infinite resource that matches any resource requirement.static final ResourceProfileA ResourceProfile that indicates an unknown resource requirement.static final ResourceProfileA ResourceProfile describing zero resources. -
Method Summary
Modifier and TypeMethodDescriptionbooleanCheck whether all fields of this resource profile are no less than the given resource profile.booleanstatic ResourceProfilefromResources(double cpuCores, int taskHeapMemoryMB) static ResourceProfilefromResourceSpec(org.apache.flink.api.common.operators.ResourceSpec resourceSpec, org.apache.flink.configuration.MemorySize networkMemory) org.apache.flink.api.common.resources.CPUResourceGet the cpu cores needed.Get the extended resources.org.apache.flink.configuration.MemorySizeGet the managed memory needed.org.apache.flink.configuration.MemorySizeGet the network memory needed.org.apache.flink.configuration.MemorySizeGet the memory the operators needed.org.apache.flink.configuration.MemorySizeGet the task heap memory needed.org.apache.flink.configuration.MemorySizeGet the task off-heap memory needed.org.apache.flink.configuration.MemorySizeGet the total memory needed.inthashCode()booleanisMatching(ResourceProfile required) Check whether required resource profile can be matched.merge(ResourceProfile other) Calculates the sum of two resource profiles.multiply(int multiplier) static ResourceProfile.Builderstatic ResourceProfile.BuildernewBuilder(ResourceProfile resourceProfile) subtract(ResourceProfile other) Subtracts another piece of resource profile from this one.toString()
-
Field Details
-
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. -
ANY
A ResourceProfile that indicates infinite resource that matches any resource requirement. -
ZERO
A ResourceProfile describing zero resources.
-
-
Method Details
-
getCpuCores
public org.apache.flink.api.common.resources.CPUResource getCpuCores()Get the cpu cores needed.- Returns:
- The cpu cores, 1.0 means a full cpu thread
-
getTaskHeapMemory
public org.apache.flink.configuration.MemorySize getTaskHeapMemory()Get the task heap memory needed.- Returns:
- The task heap memory
-
getTaskOffHeapMemory
public org.apache.flink.configuration.MemorySize getTaskOffHeapMemory()Get the task off-heap memory needed.- Returns:
- The task off-heap memory
-
getManagedMemory
public org.apache.flink.configuration.MemorySize getManagedMemory()Get the managed memory needed.- Returns:
- The managed memory
-
getNetworkMemory
public org.apache.flink.configuration.MemorySize getNetworkMemory()Get the network memory needed.- Returns:
- The network memory
-
getTotalMemory
public org.apache.flink.configuration.MemorySize getTotalMemory()Get the total memory needed.- Returns:
- The total memory
-
getOperatorsMemory
public org.apache.flink.configuration.MemorySize getOperatorsMemory()Get the memory the operators needed.- Returns:
- The operator memory
-
getExtendedResources
Get the extended resources.- Returns:
- The extended resources
-
isMatching
Check whether required resource profile can be matched.- Parameters:
required- the required resource profile- Returns:
- true if the requirement is matched, otherwise false
-
allFieldsNoLessThan
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.
- The comparison will return false if the other profile has 2 core, 10 managed memory and 1000 heap memory.
- 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() -
equals
-
merge
Calculates the sum of two resource profiles.- Parameters:
other- The other resource profile to add.- Returns:
- The merged resource profile.
-
subtract
Subtracts another piece of resource profile from this one.- Parameters:
other- The other resource profile to subtract.- Returns:
- The subtracted resource profile.
-
multiply
-
toString
-
fromResourceSpec
public static ResourceProfile fromResourceSpec(org.apache.flink.api.common.operators.ResourceSpec resourceSpec, org.apache.flink.configuration.MemorySize networkMemory) -
fromResources
@VisibleForTesting public static ResourceProfile fromResources(double cpuCores, int taskHeapMemoryMB) -
newBuilder
-
newBuilder
-