-
Notifications
You must be signed in to change notification settings - Fork 592
HDDS-9528. Managed objects should not override finalize() #5853
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
Conversation
|
I think this can be much simpler to implement within RocksDB java lib (and a good contribution to RocksDB too). I will submit a patch to rocksdb, but we need to proceed with this change too. |
adoroszlai
left a comment
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.
Thanks @duongkame for the patch, LGTM.
Few trivial items noted. I'll commit them to the PR soon to trigger CI.
I also have a few ideas for minor improvements to be done as a follow-up. Filed the task for myself for now.
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/resource/LeakDetector.java
Outdated
Show resolved
Hide resolved
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/resource/package-info.java
Outdated
Show resolved
Hide resolved
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/resource/package-info.java
Outdated
Show resolved
Hide resolved
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/resource/LeakTracker.java
Outdated
Show resolved
Hide resolved
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.
@duongkame , thanks a lot for working on this! Please see the comments inlined and also https://issues.apache.org/jira/secure/attachment/13065566/5853_review.patch
BTW, have you done some benchmarks to see if this can improve the performance?
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/resource/LeakDetector.java
Show resolved
Hide resolved
| * limitations under the License. | ||
| * | ||
| */ | ||
| package org.apache.hadoop.hdds.resource; |
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 should use the org.apache.hadoop.hdds.utils package.
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.
@duongkame , any comments on this?
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.
Moved.
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/resource/LeakTracker.java
Show resolved
Hide resolved
hadoop-hdds/common/src/main/java/org/apache/hadoop/hdds/resource/LeakDetector.java
Show resolved
Hide resolved
| static void assertClosed(RocksObject rocksObject, String stackTrace) { | ||
| private static final LeakDetector LEAK_DETECTOR = new LeakDetector("ManagedRocksObject"); | ||
|
|
||
| static LeakTracker track(AutoCloseable object, @Nullable StackTraceElement[] stackTrace) { |
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.
- Use
RocksObjectinstead ofAutoCloseable. - Get
stackTraceinside this method instead of passing it in order to reduce code duplication.
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.
- Get
stackTraceinside this method instead of passing it in order to reduce code duplication.
This one I also included in HDDS-10000. Since the stackTrace members already exist, i.e. the duplication is not introduced here, I thought it can be done as a follow-up.
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.
There's also RocksMutableObject and other custom object in the same package to be tracked here. AutoCloseable is the most convenient here. Btw, it's package private and only used for managed object in this package.
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.
Use RocksObject instead of AutoCloseable.
Get stackTrace inside this method instead of passing it in order to reduce code duplication.
This is great. Thanks.
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.
Increment startIndex (to 4) here:
Lines 73 to 74 in 333e6a1
| static String formatStackTrace(@Nullable StackTraceElement[] elements) { | |
| return HddsUtils.formatStackTrace(elements, 3); |
| if (rocksObject.isOwningHandle()) { | ||
| reportLeak(rocksObject, stackTrace); | ||
| } | ||
| final String name = object.getClass().getSimpleName(); |
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.
Use object.toString() instead.
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.
@duongkame , any comments on this?
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 don't think we need anything specific in toString(). Plus, toString gives an uncertain performance.
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 fine to use Class.getSimpleName() although it is known to have bad performance; see https://stackoverflow.com/questions/17369304/why-is-class-getsimplename-not-cached
It seems minor.
...d-rocksdb/src/main/java/org/apache/hadoop/hdds/utils/db/managed/ManagedRocksObjectUtils.java
Show resolved
Hide resolved
| * | ||
| * }</pre> | ||
| */ | ||
| public class LeakDetector implements Runnable { |
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.
Use generic type and don't implements Runnable.
| Thread t = new Thread(this); | ||
| t.setName(LeakDetector.class.getSimpleName() + "-" + name); | ||
| t.setDaemon(true); | ||
| LOG.info("Starting leak detector thread {}.", name); | ||
| t.start(); | ||
| } | ||
|
|
||
| @Override | ||
| public void run() { |
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.
Make a private and pass it using new Thread(this::run).
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.
Make sense.
szetszwo
left a comment
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.
... have you done some benchmarks to see if this can improve the performance?
@duongkame , have you got a chance to run some benchmarks?
| * limitations under the License. | ||
| * | ||
| */ | ||
| package org.apache.hadoop.hdds.resource; |
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.
@duongkame , any comments on this?
| if (rocksObject.isOwningHandle()) { | ||
| reportLeak(rocksObject, stackTrace); | ||
| } | ||
| final String name = object.getClass().getSimpleName(); |
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.
@duongkame , any comments on this?
I didn't run benchmarks on any ozone scenarios. However, I did a simple benchmark scenario each creating 100M managed objects with a percentage of leaks. The new solution consistently beats the old one by a 33% gap. New solution result: Old solution (with finalizer) result. Benchmarking code: Theoretically, this improvement unblocks GC and optimizes leak detection by only processing unclosed resources (closed ones are not enqueued). |
szetszwo
left a comment
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.
+1 the change looks good. Just some very minor comments.
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you 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. | ||
| */ | ||
|
|
||
| /** | ||
| * Contains utilities for resource management. | ||
| */ | ||
| package org.apache.hadoop.hdds.resource; |
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 file should be removed.
| if (rocksObject.isOwningHandle()) { | ||
| reportLeak(rocksObject, stackTrace); | ||
| } | ||
| final String name = object.getClass().getSimpleName(); |
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 fine to use Class.getSimpleName() although it is known to have bad performance; see https://stackoverflow.com/questions/17369304/why-is-class-getsimplename-not-cached
It seems minor.
Good to know, thanks! (Sorry that I thought you would run the same OM performance benchmarks. I understand that ref queue is better solution than finalizer. However, I am not sure if it would help the OM performance.) |
|
Thanks @duongkame for the patch, @szetszwo for the review. |
(cherry picked from commit b13f01c)
What changes were proposed in this pull request?
Simple and efficient (to be verified) way to do leak detection without relying on
finalize().What is the link to the Apache JIRA
https://issues.apache.org/jira/browse/HDDS-9528
How was this patch tested?
CI.