Skip to content

[improve][fn] Run connectors extraction in parallel - #17902

Merged
Technoboy- merged 4 commits into
apache:masterfrom
aymkhalil:parallel-search-connectors
Oct 17, 2022
Merged

Technoboy- merged 4 commits into
apache:masterfrom
aymkhalil:parallel-search-connectors

Conversation

@aymkhalil

Copy link
Copy Markdown
Contributor

Motivation

Improve functions worker bootstrap time with increased number of connectors. Currently all nar files are unpacked during startup to perform validation steps (e.g. if the connector class implements the correct interfaces). For that, the NarClassLoader will unpack all nars to disk sequentially which could delay startup.

On my Machine (Mac M1) I observed an improvement of ~ 3X (from 48 seconds down to 15 seconds). I know the max number of chosen threads (4) is a magic number (I have not seen improvements beyond that number), but if this is the right approach and it is worth it, we can make this number configurable (need guidance on the right config place)

Sample output:

2022-09-30T01:22:13,778+0000 [main] INFO  org.apache.pulsar.functions.utils.io.ConnectorUtils - Searching for connectors in /pulsar/./connectors
2022-09-30T01:22:13,779+0000 [main] INFO  org.apache.pulsar.functions.utils.io.ConnectorUtils - Loading 58 connector definitions with a thread pool of size 4
2022-09-30T01:22:13,781+0000 [search-connectors-executor-0] INFO  org.apache.pulsar.common.nar.NarUnpacker - Created directory /tmp/pulsar-nar/pulsar-io-debezium-mssql-2.10.1.8-SNAPSHOT.nar-unpacked
2022-09-30T01:22:13,781+0000 [search-connectors-executor-1] INFO  org.apache.pulsar.common.nar.NarUnpacker - Created directory /tmp/pulsar-nar/pulsar-snowflake-connector-0.1.10.nar-unpacked
2022-09-30T01:22:13,781+0000 [search-connectors-executor-2] INFO  org.apache.pulsar.common.nar.NarUnpacker - Created directory /tmp/pulsar-nar/pulsar-io-mongo-2.10.1.8-SNAPSHOT.nar-unpacked
2022-09-30T01:22:13,784+0000 [search-connectors-executor-3] INFO  org.apache.pulsar.common.nar.NarUnpacker - Created directory /tmp/pulsar-nar/pulsar-io-kinesis-2.10.1.8-SNAPSHOT.nar-unpacked
2022-09-30T01:22:13,895+0000 [search-connectors-executor-2] INFO  org.apache.pulsar.common.nar.NarUnpacker - Extracting /pulsar/./connectors/pulsar-io-mongo-2.10.1.8-SNAPSHOT.nar to /tmp/pulsar-nar/pulsar-io-mongo-2.10.1.8-SNAPSHOT.nar-unpacked/gs7wF7XmmgT1MjvpwSxFfA

Modifications

Just run the connectors search function (which unpacks the nars) in parallel via a CachedThreadPool.

Verifying this change

  • Make sure that the change passes the CI checks.

This change is already covered by existing tests, such as the unit tests under PulsarFunctionLocalRunTest already covers this path. Also CI for each existing connector will cover the change

Does this pull request potentially affect one of the following parts:

If the box was checked, please highlight the changes

  • Dependencies (add or upgrade a dependency)
  • The public API
  • The schema
  • The default values of configurations
  • The binary protocol
  • The REST endpoints
  • The admin CLI options
  • Anything that affects deployment

Documentation

  • doc-required
    (Your PR needs to update docs and you will update later)

  • doc-not-needed
    (Please explain why)

  • doc
    (Your PR contains doc changes)

  • doc-complete
    (Docs have been already added)

Matching PR in forked repository

PR in forked repository: (aymkhalil#2)

After opening this PR, the build in apache/pulsar will fail and instructions will
be provided for opening a PR in the PR author's forked repository.

apache/pulsar pull requests should be first tested in your own fork since the
apache/pulsar CI based on GitHub Actions has constrained resources and quota.
GitHub Actions provides separate quota for pull requests that are executed in
a forked repository.

The tests will be run in the forked repository until all PR review comments have
been handled, the tests pass and the PR is approved by a reviewer.

-->

@github-actions github-actions Bot added the doc-not-needed Your PR changes do not impact docs label Sep 30, 2022
@lhotari

lhotari commented Oct 1, 2022

Copy link
Copy Markdown
Member

"Run search connectors in parallel"

Isn't this completely generic?

@lhotari

lhotari commented Oct 1, 2022

Copy link
Copy Markdown
Member

Oh, it seems that I misunderstood the naming.

... INFO org.apache.pulsar.functions.utils.io.ConnectorUtils - Searching for connectors in /pulsar/./connectors

"connector extraction" etc. would make more sense to me.

@aymkhalil aymkhalil changed the title [improve][fn] Run search connectors in parallel [improve][fn] Run connectors extraction in parallel Oct 1, 2022

@eolivelli eolivelli left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM
I have left some suggestions

ExecutorService oneTimeExecutor = null;
try {
int nThreads = Math.min(Runtime.getRuntime().availableProcessors(), archives.size());
log.info("Loading {} connector definitions with a thread pool of size {}", archives.size(), nThreads);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can log this at debug level. It is not useful.
Please add the if log.isDebugEnabled guard, as this is the code style in Pulsar for DEBUG statements

@aymkhalil aymkhalil Oct 3, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually think the log is useful for troubleshooting no? Both # of connectors and # of CPU are variables, and if someone observes a long bootstrap time, we could quickly support them by ruling out the obvious (for example, they have 100 connectors but only single CPU...)

@aymkhalil

Copy link
Copy Markdown
Contributor Author

Side note for committer (@eolivelli @nicoloboschi) : Please update the commit message to match the PR title when merging,.

@aymkhalil
aymkhalil requested review from eolivelli and nicoloboschi and removed request for eolivelli and nicoloboschi October 3, 2022 18:27
@eolivelli eolivelli added this to the 2.12.0 milestone Oct 5, 2022
@eolivelli eolivelli closed this Oct 6, 2022
@eolivelli eolivelli reopened this Oct 6, 2022
@eolivelli

eolivelli commented Oct 6, 2022 •

Copy link
Copy Markdown
Contributor

Opened closed to trigger CI.
Something is blocked

@Technoboy-
Technoboy- force-pushed the parallel-search-connectors branch from 595f79b to 6f99bb6 Compare October 17, 2022 03:53
@codecov-commenter

codecov-commenter commented Oct 17, 2022 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 47 lines in your changes missing coverage. Please review.
✅ Project coverage is 46.64%. Comparing base (6c65ca0) to head (6f99bb6).
⚠️ Report is 3502 commits behind head on master.

Files with missing lines Patch % Lines
...ache/pulsar/functions/utils/io/ConnectorUtils.java 0.00% 47 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@              Coverage Diff              @@
##             master   #17902       +/-   ##
=============================================
+ Coverage     34.91%   46.64%   +11.72%     
- Complexity     5707    17814    +12107     
=============================================
  Files           607     1574      +967     
  Lines         53396   128331    +74935     
  Branches       5712    14115     +8403     
=============================================
+ Hits          18644    59859    +41215     
- Misses        32119    62317    +30198     
- Partials       2633     6155     +3522     
Flag Coverage Δ
unittests 46.64% <0.00%> (+11.72%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...ache/pulsar/functions/utils/io/ConnectorUtils.java 0.00% <0.00%> (ø)

... and 1143 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs ready-to-test

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants