-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Add listener model for TaskThresholdMemoryRevokingScheduler #15505
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.facebook.presto.execution; | ||
|
|
||
| import com.facebook.presto.memory.LocalMemoryManager; | ||
| import com.facebook.presto.memory.MemoryPool; | ||
| import com.google.common.collect.ImmutableList; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import static java.util.Objects.requireNonNull; | ||
|
|
||
| public class MemoryRevokingUtils | ||
| { | ||
| private MemoryRevokingUtils() {} | ||
|
|
||
| public static List<MemoryPool> getMemoryPools(LocalMemoryManager localMemoryManager) | ||
| { | ||
| requireNonNull(localMemoryManager, "localMemoryManager can not be null"); | ||
| ImmutableList.Builder<MemoryPool> builder = new ImmutableList.Builder<>(); | ||
| builder.add(localMemoryManager.getGeneralPool()); | ||
| localMemoryManager.getReservedPool().ifPresent(builder::add); | ||
| return builder.build(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| /* | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package com.facebook.presto.memory; | ||
|
|
||
| import com.facebook.presto.execution.TaskId; | ||
|
|
||
| import java.util.function.BiConsumer; | ||
|
|
||
| public interface TaskRevocableMemoryListener | ||
| { | ||
| /** | ||
| * Listener function that is called when a Task reserves | ||
| * memory in a given MemoryPool successfully | ||
| * | ||
| * @param taskId the {@link TaskId} of the task that reserved the memory | ||
| * @param memoryPool the {@link MemoryPool} where the reservation took place | ||
| */ | ||
| void onMemoryReserved(TaskId taskId, MemoryPool memoryPool); | ||
|
|
||
| static TaskRevocableMemoryListener onMemoryReserved(BiConsumer<TaskId, ? super MemoryPool> action) | ||
| { | ||
| return action::accept; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -255,7 +255,7 @@ public LocalMemoryContext localSystemMemoryContext() | |
| // caller shouldn't close this context as it's managed by the OperatorContext | ||
| public LocalMemoryContext localRevocableMemoryContext() | ||
| { | ||
| return new InternalLocalMemoryContext(operatorMemoryContext.localRevocableMemoryContext(), revocableMemoryFuture, () -> {}, false); | ||
| return new InternalLocalMemoryContext(operatorMemoryContext.localRevocableMemoryContext(), revocableMemoryFuture, this::updateTaskRevocableMemoryReservation, false); | ||
| } | ||
|
|
||
| // caller shouldn't close this context as it's managed by the OperatorContext | ||
|
|
@@ -267,7 +267,7 @@ public AggregatedMemoryContext aggregateUserMemoryContext() | |
| // caller shouldn't close this context as it's managed by the OperatorContext | ||
| public AggregatedMemoryContext aggregateRevocableMemoryContext() | ||
| { | ||
| return new InternalAggregatedMemoryContext(operatorMemoryContext.aggregateRevocableMemoryContext(), memoryFuture, () -> {}, false); | ||
| return new InternalAggregatedMemoryContext(operatorMemoryContext.aggregateRevocableMemoryContext(), memoryFuture, this::updateTaskRevocableMemoryReservation, false); | ||
| } | ||
|
|
||
| // caller should close this context as it's a new context | ||
|
|
@@ -287,6 +287,12 @@ private void updatePeakMemoryReservations() | |
| peakTotalMemoryReservation.accumulateAndGet(totalMemory, Math::max); | ||
| } | ||
|
|
||
| // listen to revocable memory allocations and call any listeners waiting on task memory allocation | ||
| private void updateTaskRevocableMemoryReservation() | ||
| { | ||
| driverContext.getPipelineContext().getTaskContext().getQueryContext().getMemoryPool().onTaskMemoryReserved(driverContext.getTaskId()); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not too sure what we think of this way of alerting the TaskThresholdMemoryRevokingScheduler. Not ideal but this is the cleanest way I could think of - other alternatives are passing the listener around somehow instead of piggybacking on MemoryPool. The thing I dont like about this is that MemoryPool now has two sets of disparate listeners and technically this is a task/operator context allocation. |
||
| } | ||
|
|
||
| public long getReservedRevocableBytes() | ||
| { | ||
| return operatorMemoryContext.getRevocableMemory(); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not just keep
SqlTaskManagerhere directly?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing - without parameterizing it, it is difficult to make this part of the code modular and testable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See @VisibleForTesting constructor for reference