-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Optimize how we merge multiple operatorStats #24414
Optimize how we merge multiple operatorStats #24414
Conversation
dfcc4ca
to
a8ecf10
Compare
presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java
Outdated
Show resolved
Hide resolved
727cf06
to
6808005
Compare
Thanks for the release note! Rephrasing suggestions to follow the Order of changes in the Release Notes Guidelines:
|
@arhimondr feel free to take another look. Thank you so much for all the awesome suggestionsl |
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.
Thank you for following up. Looks good to me % comments
presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/execution/StageExecutionInfo.java
Outdated
Show resolved
Hide resolved
1d78017
to
a3c6221
Compare
presto-main/src/main/java/com/facebook/presto/operator/OperatorStats.java
Outdated
Show resolved
Hide resolved
presto-main/src/main/java/com/facebook/presto/operator/OperatorStats.java
Outdated
Show resolved
Hide resolved
for (OperatorStats operator : operators) { | ||
operatorSummaries.compute(operator.getOperatorId(), (operatorId, summaryStats) -> summaryStats == null ? operator : summaryStats.add(operator)); | ||
} | ||
operators.stream().collect(Collectors.groupingBy(OperatorStats::getOperatorId)) |
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.
This will only have one OperatorStats
per operator. Probably we can keep the loop and avoid groupingBy
.
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.
Yep. I should have double checked on that. Thanks for catching it.
} | ||
operatorSummaries.put(operatorId, combined); | ||
} | ||
runningOperators.asMap().forEach((operatorId, runningStats) -> { |
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.
Consider using the same approach with merge
+ toImmutableList
)
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.
Good point. Did not realize this part is rather similar to StageExecutionStats
1cedaea
to
749d60b
Compare
int stageExecutionId = first.getStageExecutionId(); | ||
int pipelineId = first.getPipelineId(); | ||
PlanNodeId planNodeId = first.getPlanNodeId(); | ||
String operatorType = first.getOperatorType(); |
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.
@arhimondr one issue with "0" based initial value is we dont have a starting value for those ids but need to grab them from the first item of the collections passed in. This is safe since we check its emptiness right above. Let me know what you think.
6ea95c3
to
cec07cd
Compare
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.
Very good. Thank you for the follow up.
Looks great to me % two small questions
ImmutableList.Builder<DriverStats> drivers = ImmutableList.builderWithExpectedSize(driverContexts.size()); | ||
// Make deep copy of each list | ||
ConcurrentMap<Integer, List<OperatorStats>> operatorStatsById = this.operatorStatsById.entrySet().stream() |
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.
Does it have to be ConcurrentMap
? Have you considered a simple Map
and the toMap
collector?
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.
You are absolutely correct. It does not need to be concurrentMap. Regular map will do the job.
ImmutableList.Builder<DriverStats> drivers = ImmutableList.builderWithExpectedSize(driverContexts.size()); | ||
// Make deep copy of each list | ||
ConcurrentMap<Integer, List<OperatorStats>> operatorStatsById = this.operatorStatsById.entrySet().stream() | ||
.collect(toConcurrentMap(Map.Entry::getKey, e -> new ArrayList<>(Arrays.asList(e.getValue())))); |
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.
Do you need to have an extra new ArrayList<>(...)
? Would Arrays.asList(e.getValue())
alone work?
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.
Yeah, it needs to be new ArrayList<> since Arrays.asList(e.getValue()) will create a immutable resizable list but we need it be mutable so we can add item to it later on here
for (OperatorStats operatorStats : driverStats.getOperatorStats()) {
operatorStatsById.computeIfAbsent(operatorStats.getOperatorId(), k -> new ArrayList<>()).add(operatorStats);
}
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.
The standard JDK Arrays.asList
returns a mutable ArrayList: https://github.com/openjdk/jdk21/blob/master/src/java.base/share/classes/java/util/Arrays.java#L4222
Is this the JDK Arrays.asList
used here? Or is there one in Guava?
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.
It is from standard JDK. It gives the following exception because the Arrays.asList call "returns a fixed-size list backed by the specified array." (so basically a view of the array) We can modify existing elements but can not resize the list. I should have said it is mutable by not resizable. Sorry about the confusion and let me know if there is a better way. Really appreciate all the discussion. Learned a lot!
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.
I didn't know that. Thank you for the explanation
cec07cd
to
35c51ba
Compare
Description
Motivation and Context
Impact
Test Plan
Contributor checklist
Release Notes
Please follow release notes guidelines and fill in the release notes below.