Class ResourceProfile
- java.lang.Object
-
- org.apache.flink.runtime.clusterframework.types.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 fromResourceSpecwith 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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classResourceProfile.BuilderBuilder for theResourceProfile.
-
Field Summary
Fields Modifier and Type Field Description static ResourceProfileANYA ResourceProfile that indicates infinite resource that matches any resource requirement.static ResourceProfileUNKNOWNA ResourceProfile that indicates an unknown resource requirement.static ResourceProfileZEROA ResourceProfile describing zero resources.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanallFieldsNoLessThan(ResourceProfile other)Check whether all fields of this resource profile are no less than the given resource profile.booleanequals(Object obj)static 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.CPUResourcegetCpuCores()Get the cpu cores needed.Map<String,org.apache.flink.api.common.resources.ExternalResource>getExtendedResources()Get the extended resources.org.apache.flink.configuration.MemorySizegetManagedMemory()Get the managed memory needed.org.apache.flink.configuration.MemorySizegetNetworkMemory()Get the network memory needed.org.apache.flink.configuration.MemorySizegetOperatorsMemory()Get the memory the operators needed.org.apache.flink.configuration.MemorySizegetTaskHeapMemory()Get the task heap memory needed.org.apache.flink.configuration.MemorySizegetTaskOffHeapMemory()Get the task off-heap memory needed.org.apache.flink.configuration.MemorySizegetTotalMemory()Get the total memory needed.inthashCode()booleanisMatching(ResourceProfile required)Check whether required resource profile can be matched.ResourceProfilemerge(ResourceProfile other)Calculates the sum of two resource profiles.ResourceProfilemultiply(int multiplier)static ResourceProfile.BuildernewBuilder()static ResourceProfile.BuildernewBuilder(ResourceProfile resourceProfile)ResourceProfilesubtract(ResourceProfile other)Subtracts another piece of resource profile from this one.StringtoString()
-
-
-
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.
-
ANY
@VisibleForTesting public static final ResourceProfile ANY
A ResourceProfile that indicates infinite resource that matches any resource requirement.
-
ZERO
public static final ResourceProfile ZERO
A ResourceProfile describing zero resources.
-
-
Method Detail
-
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
public Map<String,org.apache.flink.api.common.resources.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.
- 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
-
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.
-
multiply
@Nonnull public ResourceProfile multiply(int multiplier)
-
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
public static ResourceProfile.Builder newBuilder()
-
newBuilder
public static ResourceProfile.Builder newBuilder(ResourceProfile resourceProfile)
-
-