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

Migrate GcsOptions#getExecutorService to an unbounded ScheduledExecutorService #23545

Merged
merged 1 commit into from
Oct 12, 2022

Conversation

lukecwik
Copy link
Member

@lukecwik lukecwik commented Oct 7, 2022

This is a preliminary piece for issue #21368


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

  • Choose reviewer(s) and mention them in a comment (R: @username).
  • 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.

@lukecwik lukecwik force-pushed the 21368 branch 2 times, most recently from 603f030 to 89819d7 Compare October 7, 2022 23:31
@lukecwik lukecwik changed the title [WIP] Migrate GcsOptions#getExecutorService to an unbounded ScheduledExecutorService Migrate GcsOptions#getExecutorService to an unbounded ScheduledExecutorService Oct 7, 2022
@lukecwik
Copy link
Member Author

lukecwik commented Oct 7, 2022

R: @johnjcasey

@github-actions
Copy link
Contributor

github-actions bot commented Oct 7, 2022

Stopping reviewer notifications for this pull request: review requested by someone other than the bot, ceding control

@lukecwik
Copy link
Member Author

lukecwik commented Oct 8, 2022

Fixed spotbugs/fb warnings

@lukecwik
Copy link
Member Author

lukecwik commented Oct 8, 2022

Run Java PreCommit

@johnjcasey
Copy link
Contributor

I think this is good, but it is pretty complex.

Copy link
Contributor

@johnjcasey johnjcasey left a comment

Choose a reason for hiding this comment

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

A few questions, but looks good overall

threadFactoryBuilder.setThreadFactory(MoreExecutors.platformThreadFactory());
threadFactoryBuilder.setDaemon(true);

this.threadPoolExecutor =
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that we are basically wrapping a thread pool executor here, does it make sense to allow users to configure different TPEs?

Copy link
Member Author

@lukecwik lukecwik Oct 11, 2022

Choose a reason for hiding this comment

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

Eventually yes, but as an initial implementation I decided against it since it is easier to add features then remove them in the future.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good

@Override
public Void call() throws Exception {
while (true) {
synchronized (tasks) {
Copy link
Contributor

Choose a reason for hiding this comment

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

because we sync on tasks here, is it possible for us to have late execution of a task that is intended to be submitted during this lock?

Copy link
Member Author

@lukecwik lukecwik Oct 11, 2022

Choose a reason for hiding this comment

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

We only sync on tasks until we can pull out an entry and submit it to the executor.

Note that tasks.wait() frees the monitor lock allowing other threads to synchronize on the tasks monitor so the amount of time in the critical section is relatively short.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense

}

@Override
public void execute(Runnable command) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I assume we can't use an @nonnull annotation because we are implementing a method?

Copy link
Member Author

@lukecwik lukecwik Oct 11, 2022

Choose a reason for hiding this comment

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

@nonnull is the default by the way, we have to explicitly say something is @nullable.

Also @nonnull only adds checking for those that use that tooling when compiling their code.

The explicit check makes sure command isn't null for all those that don't use findbugs/spotbugs and to match the ScheduledExecutorService method contracts.

Copy link
Contributor

Choose a reason for hiding this comment

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

makes sense

@johnjcasey
Copy link
Contributor

LTGM

@johnjcasey johnjcasey merged commit 3cb512e into apache:master Oct 12, 2022
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.

2 participants