Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FLINK-21433][runtime] Pass number of slots as dynamic properties to TMs. #15128

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ public class TaskExecutorProcessSpec extends CommonProcessMemorySpec<TaskExecuto

private final CPUResource cpuCores;

private final int numSlots;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We all also need to cover this field in toString .


@VisibleForTesting
public TaskExecutorProcessSpec(
CPUResource cpuCores,
Expand All @@ -106,16 +108,19 @@ public TaskExecutorProcessSpec(
taskOffHeapSize,
networkMemSize,
managedMemorySize),
new JvmMetaspaceAndOverhead(jvmMetaspaceSize, jvmOverheadSize));
new JvmMetaspaceAndOverhead(jvmMetaspaceSize, jvmOverheadSize),
1);
}

protected TaskExecutorProcessSpec(
CPUResource cpuCores,
TaskExecutorFlinkMemory flinkMemory,
JvmMetaspaceAndOverhead jvmMetaspaceAndOverhead) {
JvmMetaspaceAndOverhead jvmMetaspaceAndOverhead,
int numSlots) {

super(flinkMemory, jvmMetaspaceAndOverhead);
this.cpuCores = cpuCores;
this.numSlots = numSlots;
}

public CPUResource getCpuCores() {
Expand Down Expand Up @@ -146,6 +151,10 @@ public MemorySize getManagedMemorySize() {
return getFlinkMemory().getManaged();
}

public int getNumSlots() {
return numSlots;
}

@Override
public boolean equals(Object obj) {
if (obj == this) {
Expand All @@ -155,14 +164,15 @@ public boolean equals(Object obj) {
return Objects.equals(this.cpuCores, that.cpuCores)
&& Objects.equals(
this.getJvmMetaspaceAndOverhead(), that.getJvmMetaspaceAndOverhead())
&& Objects.equals(this.getFlinkMemory(), that.getFlinkMemory());
&& Objects.equals(this.getFlinkMemory(), that.getFlinkMemory())
&& Objects.equals(this.numSlots, that.numSlots);
}
return false;
}

@Override
public int hashCode() {
return Objects.hash(getJvmMetaspaceAndOverhead(), getFlinkMemory(), cpuCores);
return Objects.hash(getJvmMetaspaceAndOverhead(), getFlinkMemory(), cpuCores, numSlots);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ public static TaskExecutorProcessSpec processSpecFromWorkerResourceSpec(
config, flinkMemory.getTotalFlinkMemorySize());

return new TaskExecutorProcessSpec(
workerResourceSpec.getCpuCores(), flinkMemory, jvmMetaspaceAndOverhead);
workerResourceSpec.getCpuCores(),
flinkMemory,
jvmMetaspaceAndOverhead,
workerResourceSpec.getNumSlots());
}

private static TaskExecutorProcessSpec createMemoryProcessSpec(
Expand All @@ -173,13 +176,17 @@ private static TaskExecutorProcessSpec createMemoryProcessSpec(
JvmMetaspaceAndOverhead jvmMetaspaceAndOverhead =
processMemory.getJvmMetaspaceAndOverhead();
return new TaskExecutorProcessSpec(
getCpuCores(config), flinkMemory, jvmMetaspaceAndOverhead);
getCpuCores(config), flinkMemory, jvmMetaspaceAndOverhead, getNumSlots(config));
}

private static CPUResource getCpuCores(final Configuration config) {
return getCpuCoresWithFallback(config, -1.0);
}

private static int getNumSlots(final Configuration config) {
return config.getInteger(TaskManagerOptions.NUM_TASK_SLOTS);
}

public static double getCpuCoresWithFallbackConfigOption(
final Configuration config, ConfigOption<Double> fallbackOption) {
double fallbackValue = config.getDouble(fallbackOption);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@ public final class WorkerResourceSpec implements Serializable {

private final MemorySize managedMemSize;

private final int numSlots;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here.


private WorkerResourceSpec(
CPUResource cpuCores,
MemorySize taskHeapSize,
MemorySize taskOffHeapSize,
MemorySize networkMemSize,
MemorySize managedMemSize) {
MemorySize managedMemSize,
int numSlots) {

this.cpuCores = Preconditions.checkNotNull(cpuCores);
this.taskHeapSize = Preconditions.checkNotNull(taskHeapSize);
this.taskOffHeapSize = Preconditions.checkNotNull(taskOffHeapSize);
this.networkMemSize = Preconditions.checkNotNull(networkMemSize);
this.managedMemSize = Preconditions.checkNotNull(managedMemSize);
this.numSlots = numSlots;
}

public static WorkerResourceSpec fromTaskExecutorProcessSpec(
Expand All @@ -68,18 +72,20 @@ public static WorkerResourceSpec fromTaskExecutorProcessSpec(
taskExecutorProcessSpec.getTaskHeapSize(),
taskExecutorProcessSpec.getTaskOffHeapSize(),
taskExecutorProcessSpec.getNetworkMemSize(),
taskExecutorProcessSpec.getManagedMemorySize());
taskExecutorProcessSpec.getManagedMemorySize(),
taskExecutorProcessSpec.getNumSlots());
}

public static WorkerResourceSpec fromTotalResourceProfile(
final ResourceProfile resourceProfile) {
final ResourceProfile resourceProfile, final int numSlots) {
Preconditions.checkNotNull(resourceProfile);
return new WorkerResourceSpec(
(CPUResource) resourceProfile.getCpuCores(),
resourceProfile.getTaskHeapMemory(),
resourceProfile.getTaskOffHeapMemory(),
resourceProfile.getNetworkMemory(),
resourceProfile.getManagedMemory());
resourceProfile.getManagedMemory(),
numSlots);
}

public CPUResource getCpuCores() {
Expand All @@ -102,10 +108,14 @@ public MemorySize getManagedMemSize() {
return managedMemSize;
}

public int getNumSlots() {
return numSlots;
}

@Override
public int hashCode() {
return Objects.hash(
cpuCores, taskHeapSize, taskOffHeapSize, networkMemSize, managedMemSize);
cpuCores, taskHeapSize, taskOffHeapSize, networkMemSize, managedMemSize, numSlots);
}

@Override
Expand All @@ -118,7 +128,8 @@ public boolean equals(Object obj) {
&& Objects.equals(this.taskHeapSize, that.taskHeapSize)
&& Objects.equals(this.taskOffHeapSize, that.taskOffHeapSize)
&& Objects.equals(this.networkMemSize, that.networkMemSize)
&& Objects.equals(this.managedMemSize, that.managedMemSize);
&& Objects.equals(this.managedMemSize, that.managedMemSize)
&& Objects.equals(this.numSlots, that.numSlots);
}
return false;
}
Expand Down Expand Up @@ -146,6 +157,7 @@ public static class Builder {
private MemorySize taskOffHeapSize = MemorySize.ZERO;
private MemorySize networkMemSize = MemorySize.ZERO;
private MemorySize managedMemSize = MemorySize.ZERO;
private int numSlots = 1;

public Builder() {}

Expand Down Expand Up @@ -174,9 +186,19 @@ public Builder setManagedMemoryMB(int managedMemoryMB) {
return this;
}

public Builder setNumSlots(int numSlots) {
this.numSlots = numSlots;
return this;
}

public WorkerResourceSpec build() {
return new WorkerResourceSpec(
cpuCores, taskHeapSize, taskOffHeapSize, networkMemSize, managedMemSize);
cpuCores,
taskHeapSize,
taskOffHeapSize,
networkMemSize,
managedMemSize,
numSlots);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -585,8 +585,11 @@ public int getNumberFreeSlotsOf(InstanceID instanceId) {
@Override
public Map<WorkerResourceSpec, Integer> getRequiredResources() {
return taskManagerTracker.getPendingTaskManagers().stream()
.map(PendingTaskManager::getTotalResourceProfile)
.map(WorkerResourceSpec::fromTotalResourceProfile)
.map(
pendingTaskManager ->
WorkerResourceSpec.fromTotalResourceProfile(
pendingTaskManager.getTotalResourceProfile(),
pendingTaskManager.getNumSlots()))
.collect(Collectors.groupingBy(Function.identity(), Collectors.summingInt(e -> 1)));
}

Expand Down Expand Up @@ -668,7 +671,8 @@ private void releaseIdleTaskExecutor(InstanceID timedOutTaskManagerId) {
private boolean allocateResource(PendingTaskManager pendingTaskManager) {
if (!resourceActions.allocateResource(
WorkerResourceSpec.fromTotalResourceProfile(
pendingTaskManager.getTotalResourceProfile()))) {
pendingTaskManager.getTotalResourceProfile(),
pendingTaskManager.getNumSlots()))) {
// resource cannot be allocated
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@ public void testProcessSpecFromWorkerResourceSpec() {
.setTaskOffHeapMemoryMB(200)
.setNetworkMemoryMB(300)
.setManagedMemoryMB(400)
.setNumSlots(5)
.build();
final TaskExecutorProcessSpec taskExecutorProcessSpec =
TaskExecutorProcessUtils.processSpecFromWorkerResourceSpec(
Expand All @@ -139,6 +140,7 @@ public void testProcessSpecFromWorkerResourceSpec() {
assertEquals(
workerResourceSpec.getManagedMemSize(),
taskExecutorProcessSpec.getManagedMemorySize());
assertEquals(workerResourceSpec.getNumSlots(), taskExecutorProcessSpec.getNumSlots());
}

@Test
Expand Down Expand Up @@ -596,6 +598,20 @@ public void testExceptionShouldContainRequiredConfigOptions() {
}
}

@Test
public void testConfigNumSlots() {
final int numSlots = 5;

Configuration conf = new Configuration();
conf.set(TaskManagerOptions.NUM_TASK_SLOTS, numSlots);

validateInAllConfigurations(
conf,
taskExecutorProcessSpec -> {
assertThat(taskExecutorProcessSpec.getNumSlots(), is(numSlots));
});
}

@Override
protected void validateInAllConfigurations(
final Configuration customConfig, Consumer<TaskExecutorProcessSpec> validateFunc) {
Expand Down