Skip to content
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

Do not create new Executor everytime createRunner #32272

Merged
merged 4 commits into from
Aug 21, 2024
Merged

Conversation

Abacn
Copy link
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.

@@ -131,6 +136,11 @@ public DoFnRunner<KeyedWorkItem<byte[], KV<InputT, RestrictionT>>, OutputT> crea
OutputManager outputManager,
DoFnSchemaInformation doFnSchemaInformation,
Map<String, PCollectionView<?>> sideInputMapping) {
if (this.ses == null) {
Copy link
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
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
Contributor Author

Abacn commented Aug 21, 2024

R: @scwhittle

Copy link
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
Contributor Author

Abacn commented Aug 21, 2024

assign set of reviewers

Copy link
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).

@@ -131,6 +136,11 @@ public DoFnRunner<KeyedWorkItem<byte[], KV<InputT, RestrictionT>>, OutputT> crea
OutputManager outputManager,
DoFnSchemaInformation doFnSchemaInformation,
Map<String, PCollectionView<?>> sideInputMapping) {
if (this.ses == null) {
this.ses =
Executors.newSingleThreadScheduledExecutor(
Copy link
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
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

@@ -131,6 +136,11 @@ public DoFnRunner<KeyedWorkItem<byte[], KV<InputT, RestrictionT>>, OutputT> crea
OutputManager outputManager,
DoFnSchemaInformation doFnSchemaInformation,
Map<String, PCollectionView<?>> sideInputMapping) {
if (this.ses == null) {
Copy link
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
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

@@ -137,6 +141,12 @@ public void open(
isBounded,
pipelineOptions);

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

@@ -131,6 +137,13 @@ public DoFnRunner<KeyedWorkItem<byte[], KV<InputT, RestrictionT>>, OutputT> crea
OutputManager outputManager,
DoFnSchemaInformation doFnSchemaInformation,
Map<String, PCollectionView<?>> sideInputMapping) {
if (this.ses.get() == null) {
Copy link
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
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
24 checks passed
@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
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