-
Notifications
You must be signed in to change notification settings - Fork 13k
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-16245] Decoupling user classloader from context classloader. #13027
Conversation
Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community Automated ChecksLast check on commit 4301bfa (Thu Jul 30 08:23:01 UTC 2020) Warnings:
Mention the bot in a comment to re-run the automated checks. Review Progress
Please see the Pull Request Review Guide for a full explanation of the review process. The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commandsThe @flinkbot bot supports the following commands:
|
Could you summarize what the problem was that caused the performance regression? |
Allows user classloader can be unloaded even if a reference on the context classloader outlives the user code.
Because the classloader is now closed when the task fails the UDF only has access to the bootstrap classloader, which doesn't contain our own test classes.
For some reason, not setting a parent classloader in the wrapper is much slower. I cannot see an obvious reason and added a couple of measurements. First, I wanted to know if the performance difference was caused by slower class loading. So I measured the total time spent in Second, a profiler revealed that much time in the slow version was spent in Without the parent, creating an instance of the 4 specific blink operators Interestingly, they use only the instantiation method with explicit arguments I have also forced class resolution through reflection on the generated classes, but resolution is fast in all cases. It's really just about creating the instances. edit: log of the timed measurements without parent: https://gist.github.com/AHeise/50375144fb6d6da7acb324544722e10b ; I can also provide the full logs. |
There was also a classloader leak in ORC, for which I added a workaround. |
See https://issues.apache.org/jira/browse/ORC-653 OrcFile#getStaticMemoryManager caches initial configuration and leaks classloader in it. Thus, new Flink jobs use the classloader of the first job implicitly. By adding ThreadLocalClassLoaderConfiguration, which forces the use of thread-local classloader over the initial classloader, Flink jobs use the appropriate classloader on higher runtime costs (no caches). This commit should be reverted, once the bug in ORC is fixed.
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.
One question for clarity, otherwise this looks good.
return Optional.of(ParquetRowDataBuilder.createWriterFactory( | ||
formatType, formatConf, hiveVersion.startsWith("3."))); | ||
} else if (serLib.contains("orc")) { | ||
Configuration formatConf = new ThreadLocalClassLoaderConfiguration(jobConf); |
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.
If we were to use a normal configuration, what would happen? Subsequent jobs would not be able to 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.
Yes. That makes me believe that we should probably make the safety net configurable (on by default). Or would you think we can catch up and fix leaks much quicker?
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.
An opt-out switch is a good idea; also for cases where things don't behave as expected close to the next release, and we don't want to revert commits at that point.
@@ -124,6 +124,15 @@ | |||
return parseParentFirstLoaderPatterns(base, append); | |||
} | |||
|
|||
@Documentation.Section(Documentation.Sections.EXPERT_CLASS_LOADING) | |||
public static final ConfigOption<Boolean> CHECK_LEAKED_CLASSLOADER = ConfigOptions | |||
.key("classloader.check_leaked_classloader") |
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.
we don't use underscores.
throw new IllegalStateException("Trying to access closed classloader. Please check if you store " + | ||
"classloaders directly or indirectly in static fields. If the stacktrace suggests that the leak " + | ||
"occurs in a third party library and cannot be fixed immediately, you can disable this check " + | ||
"with the configuration 'classloader.check_leaked_classloader'."); |
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.
Retrieve the key from the actual configuration object instead.
.withDescription("Fails if a user classloader is used in another job after a job has been finished. This " + | ||
"check should only be disabled if the class leak occurs in an external library cannot be fixed " + | ||
"immediately."); |
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.
Fails attempts at loading classes if the user classloader of a job is used after it has terminated.
This is usually caused by the classloader being leaked by lingering threads or misbehaving libraries, which may also result in the classloader being used by other jobs.
This check should only be disabled if such a leak prevents further jobs from running.
…oader. If users experience class loader leaks in libraries not under his control, they can force old behavior with the config option.
This is a follow-up PR of #11303 after #11611 disabled it because of performance regression in blink e2e test.
What is the purpose of the change
Decoupling user class loader from context classloader.
Thus, user classloader can be unloaded even though a reference on the context classloader outlives the user code.
Brief change log
Compared to the original PR, it includes the following changes
Verifying this change
Added unit test.
Does this pull request potentially affect one of the following parts:
@Public(Evolving)
: (yes / no)Documentation