-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
[improve][fn] Optimize Function Worker startup by lazy loading and direct zip/bytecode access #22122
Merged
lhotari
merged 1 commit into
apache:master
from
lhotari:lh-optimize-function-worker-with-lazy-loading
Feb 26, 2024
Merged
[improve][fn] Optimize Function Worker startup by lazy loading and direct zip/bytecode access #22122
lhotari
merged 1 commit into
apache:master
from
lhotari:lh-optimize-function-worker-with-lazy-loading
Feb 26, 2024
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…rect zip/bytecode access
lhotari
requested review from
merlimat,
Technoboy-,
eolivelli,
codelipenghui and
nicoloboschi
February 26, 2024 09:56
eolivelli
approved these changes
Feb 26, 2024
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.
Lgtm
This is an amazing improvement
freeznet
approved these changes
Feb 26, 2024
lhotari
added a commit
to lhotari/pulsar
that referenced
this pull request
Feb 26, 2024
…rect zip/bytecode access (apache#22122) (cherry picked from commit bbc6224)
lhotari
added a commit
to lhotari/pulsar
that referenced
this pull request
Feb 26, 2024
…rect zip/bytecode access (apache#22122) (cherry picked from commit bbc6224) (cherry picked from commit 597cfa1) # Conflicts: # pulsar-functions/localrun/src/main/java/org/apache/pulsar/functions/LocalRunner.java # pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/thread/ThreadRuntime.java # pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/worker/ConnectorsManager.java # pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/worker/WorkerConfig.java # pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionCommon.java # pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionConfigUtils.java # pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/SinkConfigUtils.java # pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/SourceConfigUtils.java # pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/ValidatorUtils.java # pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/functions/FunctionUtils.java # pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/functions/Functions.java # pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/io/ConnectorUtils.java # pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/FunctionCommonTest.java # pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/FunctionConfigUtilsTest.java # pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/SinkConfigUtilsTest.java # pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/FunctionsManager.java # pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java # pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java # pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SinksImpl.java # pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SourcesImpl.java # pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/FunctionAssignmentTailerTest.java # pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImplTest.java # pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2ResourceTest.java # pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionApiV3ResourceTest.java # pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SinkApiV3ResourceTest.java # pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SourceApiV3ResourceTest.java # tests/docker-images/latest-version-image/conf/functions_worker.conf
mukesh-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Mar 1, 2024
…rect zip/bytecode access (apache#22122) (cherry picked from commit bbc6224) (cherry picked from commit 3d3606b)
nikhil-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Mar 5, 2024
…rect zip/bytecode access (apache#22122) (cherry picked from commit bbc6224) (cherry picked from commit 597cfa1) (cherry picked from commit d608bfc) Conflicts: pulsar-broker/pom.xml pulsar-functions/localrun/src/main/java/org/apache/pulsar/functions/LocalRunner.java pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/thread/ThreadRuntime.java pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/runtime/thread/ThreadRuntimeFactory.java pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/worker/FunctionsManager.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionCommon.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionConfigUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/SinkConfigUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/functions/FunctionArchive.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/functions/FunctionUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/io/ConnectorUtils.java pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/FunctionCommonTest.java pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/FunctionConfigUtilsTest.java pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/SinkConfigUtilsTest.java pulsar-functions/worker/pom.xml pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SinksImpl.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SourcesImpl.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImplTest.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2ResourceTest.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionApiV3ResourceTest.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SinkApiV3ResourceTest.java
nikhil-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Mar 6, 2024
…rect zip/bytecode access (apache#22122) (cherry picked from commit bbc6224) Conflicts: pulsar-common/src/main/java/org/apache/pulsar/common/nar/NarUnpacker.java pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/worker/ConnectorsManager.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionCommon.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionConfigUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/SinkConfigUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/SourceConfigUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/ValidatorUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/functions/FunctionUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/io/ConnectorUtils.java pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/FunctionCommonTest.java pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/FunctionConfigUtilsTest.java pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/SinkConfigUtilsTest.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/PulsarWorkerService.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SinksImpl.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SourcesImpl.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2ResourceTest.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionApiV3ResourceTest.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SinkApiV3ResourceTest.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SourceApiV3ResourceTest.java tests/docker-images/latest-version-image/conf/functions_worker.conf tests/integration/src/test/java/org/apache/pulsar/tests/integration/topologies/PulsarCluster.java
4 tasks
mukesh-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Mar 6, 2024
…rect zip/bytecode access (apache#22122) (cherry picked from commit bbc6224) (cherry picked from commit 3d3606b)
4 tasks
nikhil-ctds
pushed a commit
to datastax/pulsar
that referenced
this pull request
Mar 7, 2024
…rect zip/bytecode access (apache#22122) (cherry picked from commit bbc6224) Conflicts: pulsar-common/src/main/java/org/apache/pulsar/common/nar/NarUnpacker.java pulsar-functions/runtime/src/main/java/org/apache/pulsar/functions/worker/ConnectorsManager.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionCommon.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/FunctionConfigUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/SinkConfigUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/SourceConfigUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/ValidatorUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/functions/FunctionUtils.java pulsar-functions/utils/src/main/java/org/apache/pulsar/functions/utils/io/ConnectorUtils.java pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/FunctionCommonTest.java pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/FunctionConfigUtilsTest.java pulsar-functions/utils/src/test/java/org/apache/pulsar/functions/utils/SinkConfigUtilsTest.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/PulsarWorkerService.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/ComponentImpl.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/FunctionsImpl.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SinksImpl.java pulsar-functions/worker/src/main/java/org/apache/pulsar/functions/worker/rest/api/SourcesImpl.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v2/FunctionApiV2ResourceTest.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/FunctionApiV3ResourceTest.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SinkApiV3ResourceTest.java pulsar-functions/worker/src/test/java/org/apache/pulsar/functions/worker/rest/api/v3/SourceApiV3ResourceTest.java tests/docker-images/latest-version-image/conf/functions_worker.conf tests/integration/src/test/java/org/apache/pulsar/tests/integration/topologies/PulsarCluster.java
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Currently the Functions Worker eagerly unpacks and extracts all Pulsar IO connectors when the function worker starts up.
This takes a significant amount of CPU resources and also slows down the startup. On Kubernetes with an empheral filesystem, this will happen every single time the Functions Worker is restarted.
When CPU is limited with k8s resource limits on the Functions Worker, this problem is even worse.
Modifications
Refactor the Functions Worker in a way where it is possible to do minimal work at startup time. This requires avoiding class loading and therefore this PR contains a refactoring where the previous logic that was coupled with classloading is now decoupled. Instead of classloading, Byte Buddy library is used to read the required metadata from the functions and connector packages.
Instead of using the JarFile API, NarClassloader has been modified to use the ZipFile API since the Nar files don't need any features that are specific to Jar file handling.
Additional Context
There was a previous PR #17902 that made the unpacking run in parallel. Those changes aren't needed any more since startup will be fast when no nar files are unpacked on startup time.
This PR doesn't require a PIP since this doesn't change external interfaces. This doesn't introduce new external features and is also a bug fix for the maintained Pulsar releases.
Documentation
doc
doc-required
doc-not-needed
doc-complete