Skip to content

Do not create new Executor everytime createRunner#32272

Merged
Abacn merged 4 commits intoapache:masterfrom
Abacn:reuseexec
Aug 21, 2024
Merged

Do not create new Executor everytime createRunner#32272
Abacn merged 4 commits intoapache:masterfrom
Abacn:reuseexec

Conversation

@Abacn
Copy link
Copy Markdown
Contributor

@Abacn Abacn commented Aug 21, 2024

Please add a meaningful description for your change here


Thank you for your contribution! Follow this checklist to help us incorporate your contribution quickly and easily:

  • Mention the appropriate issue in your description (for example: addresses #123), if applicable. This will automatically add a link to the pull request in the issue. If you would like the issue to automatically close on merging the pull request, comment fixes #<ISSUE NUMBER> instead.
  • Update CHANGES.md with noteworthy changes.
  • If this contribution is large, please file an Apache Individual Contributor License Agreement.

See the Contributor Guide for more tips on how to make review process smoother.

To check the build health, please visit https://github.com/apache/beam/blob/master/.test-infra/BUILD_STATUS.md

GitHub Actions Tests Status (on master branch)

Build python source distribution and wheels
Python tests
Java tests
Go tests

See CI.md for more information about GitHub Actions CI or the workflows README to see a list of phrases to trigger workflows.

OutputManager outputManager,
DoFnSchemaInformation doFnSchemaInformation,
Map<String, PCollectionView<?>> sideInputMapping) {
if (this.ses == null) {
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.

added debug log in both branch and run a sample job, saw

INFO 2024-08-21T18:47:53.569Z creating new sdf executor
INFO 2024-08-21T18:47:55.698Z Reuse old sdf executor
INFO 2024-08-21T18:47:56.812Z Reuse old sdf executor
INFO 2024-08-21T18:47:57.919Z Reuse old sdf executor
INFO 2024-08-21T18:47:59.030Z Reuse old sdf executor
INFO 2024-08-21T18:48:00.138Z Reuse old sdf executor
INFO 2024-08-21T18:48:00.699Z Reuse old sdf executor
INFO 2024-08-21T18:48:01.871Z Reuse old sdf executor
INFO 2024-08-21T18:48:03.044Z Reuse old sdf executor
INFO 2024-08-21T18:48:04.121Z Reuse old sdf executor
INFO 2024-08-21T18:48:04.715Z Reuse old sdf executor
INFO 2024-08-21T18:48:05.821Z Reuse old sdf executor
...

indicating this change is effective

@Abacn
Copy link
Copy Markdown
Contributor Author

Abacn commented Aug 21, 2024

internal tracker: 361080602

example dataflow job

before: 2024-08-21_11_14_45-8135795605757551727

memory usage increasing overtime (will ultimately OOM due to thread leak)

after: 2024-08-21_11_39_15-12114433774010769671

memory usage is flat

@Abacn
Copy link
Copy Markdown
Contributor Author

Abacn commented Aug 21, 2024

R: @scwhittle

@github-actions
Copy link
Copy Markdown
Contributor

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control. If you'd like to restart, comment assign set of reviewers

@Abacn
Copy link
Copy Markdown
Contributor Author

Abacn commented Aug 21, 2024

assign set of reviewers

@github-actions
Copy link
Copy Markdown
Contributor

Assigning reviewers. If you would like to opt out of this review, comment assign to next reviewer:

R: @chamikaramj added as fallback since no labels match configuration

Available commands:

  • stop reviewer notifications - opt out of the automated review tooling
  • remind me after tests pass - tag the comment author after tests pass
  • waiting on author - shift the attention set back to the author (any comment or push by the author will return the attention set to the reviewers)

The PR bot will only process comments in the main thread (not review comments).

Map<String, PCollectionView<?>> sideInputMapping) {
if (this.ses == null) {
this.ses =
Executors.newSingleThreadScheduledExecutor(
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.

I don't think we want a single threaded one here, because I believe the factory vends many different dofnrunner which will want some parallel threads for splits.

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.

changed to use Executors.newScheduledThreadPool

OutputManager outputManager,
DoFnSchemaInformation doFnSchemaInformation,
Map<String, PCollectionView<?>> sideInputMapping) {
if (this.ses == null) {
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.

if this factory possibly called concurrently? might need some synchronization if so?

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 am not sure but now guard with AtomicReference


if (this.ses == null) {
this.ses =
Executors.newSingleThreadScheduledExecutor(
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.

not yet using this below

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.

fixed the mistake

Copy link
Copy Markdown
Contributor

@scwhittle scwhittle left a comment

Choose a reason for hiding this comment

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

Thanks for fixing these!

OutputManager outputManager,
DoFnSchemaInformation doFnSchemaInformation,
Map<String, PCollectionView<?>> sideInputMapping) {
if (this.ses.get() == null) {
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.

remembered a cleaner way to do this:

private final Supplier sesSupplier =
Suppliers.memoize(
() -> Executors.newScheduledThreadPool(
Runtime.getRuntime().availableProcessors(),
new ThreadFactoryBuilder().setNameFormat("df-sdf-executor-%d").build())));

and then just ses.get() below

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.

thanks, good to learn, for now merging it before release cut

@Abacn Abacn merged commit ed4c03e into apache:master Aug 21, 2024
@Abacn Abacn deleted the reuseexec branch August 21, 2024 21:08
@lostluck lostluck added this to the 2.59.0 Release milestone Aug 27, 2024
reeba212 pushed a commit to reeba212/beam that referenced this pull request Dec 4, 2024
* Do not create new Executor everytime createRunner

* reset executorService after shutdown

* Switch to use newScheduledThreadPool; guard ses with AtomicReference

* Partially revert changes on flink and samza runner
@Abacn Abacn mentioned this pull request Aug 7, 2025
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants