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 fromResourceSpec
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:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ResourceProfile.Builder
Builder for theResourceProfile
.
-
Field Summary
Fields Modifier and Type Field Description static ResourceProfile
ANY
A ResourceProfile that indicates infinite resource that matches any resource requirement.static ResourceProfile
UNKNOWN
A ResourceProfile that indicates an unknown resource requirement.static ResourceProfile
ZERO
A ResourceProfile describing zero resources.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
allFieldsNoLessThan(ResourceProfile other)
Check whether all fields of this resource profile are no less than the given resource profile.boolean
equals(Object obj)
static ResourceProfile
fromResources(double cpuCores, int taskHeapMemoryMB)
static ResourceProfile
fromResourceSpec(ResourceSpec resourceSpec, MemorySize networkMemory)
CPUResource
getCpuCores()
Get the cpu cores needed.Map<String,ExternalResource>
getExtendedResources()
Get the extended resources.MemorySize
getManagedMemory()
Get the managed memory needed.MemorySize
getNetworkMemory()
Get the network memory needed.MemorySize
getOperatorsMemory()
Get the memory the operators needed.MemorySize
getTaskHeapMemory()
Get the task heap memory needed.MemorySize
getTaskOffHeapMemory()
Get the task off-heap memory needed.MemorySize
getTotalMemory()
Get the total memory needed.int
hashCode()
boolean
isMatching(ResourceProfile required)
Check whether required resource profile can be matched.ResourceProfile
merge(ResourceProfile other)
Calculates the sum of two resource profiles.ResourceProfile
multiply(int multiplier)
static ResourceProfile.Builder
newBuilder()
static ResourceProfile.Builder
newBuilder(ResourceProfile resourceProfile)
ResourceProfile
subtract(ResourceProfile other)
Subtracts another piece of resource profile from this one.String
toString()
-
-
-
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 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.
- 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(ResourceSpec resourceSpec, 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)
-
-