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

feat(rosetta): improve translation throughput #3083

Merged
merged 13 commits into from
Oct 27, 2021
Merged

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Oct 19, 2021

Previously, Rosetta would divide all the examples to translate into N equally
sized arrays, and spawn N workers to translate them all.

Experimentation shows that the time required to translate samples is very
unequally divided, and many workers used to be idle for half of the time after
having finished their 1/Nth of the samples, hurting throughput.

Switch to a model where we have N workers, and we constantly feed them a
small amount of work until all the work is done. This keeps all workers
busy until the work is complete, improving the throughput a lot.

On my machine, improves a run of Rosetta on the CDK repository
with 8 workers from ~30m to ~15m.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

Previously, Rosetta would divide all the examples to translate into `N` equally
sized arrays, and spawn `N` workers to translate them all.

Experimentation shows that the time required to translate samples is very
unequally divided, and many workers used to be idle for half of the time,
hurting throughput.

Switch to a model where we have `N` workers, and we constantly feed them a
small amount of work until all the work is done. This keeps all workers
busy until the work is complete, improving the throughput a lot.

On my machine, improves a run of Rosetta on the CDK repository
with 8 workers from ~30m to ~15m.
@rix0rrr rix0rrr requested a review from a team October 19, 2021 16:04
@rix0rrr rix0rrr self-assigned this Oct 19, 2021
@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Oct 19, 2021
@rix0rrr rix0rrr changed the title feat(rosetta): switch to continuously fed worker pool feat(rosetta): switch to queue+workers for parallelization Oct 20, 2021
@rix0rrr rix0rrr changed the title feat(rosetta): switch to queue+workers for parallelization feat(rosetta): improve translation throughput Oct 22, 2021
Copy link
Contributor

@njlynch njlynch left a comment

Choose a reason for hiding this comment

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

Copying @RomainMuller 's comment from Slack:

Any reason not to use an existing Worker Pool solution, like https://www.npmjs.com/package/workerpool?

@rix0rrr
Copy link
Contributor Author

rix0rrr commented Oct 22, 2021

Apart from keeping the dependency count low and the control that comes from having the entire implementation available (easy to change parameters, memory settings, logging, etc), not really.

Want me to change it?

@njlynch
Copy link
Contributor

njlynch commented Oct 22, 2021

Want me to change it?

I'll defer to @RomainMuller , as he originally raised the point. On the positive side, workerpool carries zero dependencies with it, which is lovely. Then again, you've already rolled your own here....

@nija-at
Copy link
Contributor

nija-at commented Oct 25, 2021

It would be better to use an existing solution rather than rolling our own, unless you think there is a significant advantage to having our own implementation. While the initial implementation is already done, there is the question of continued maintenance which would build up if we go down this path for every new feature we want.

The npm module referred to here has 3M weekly downloads, which should be sufficient indication about its reliability and updates.

@rix0rrr rix0rrr requested a review from njlynch October 26, 2021 09:45
@rix0rrr rix0rrr requested a review from nija-at October 26, 2021 09:46
@rix0rrr
Copy link
Contributor Author

rix0rrr commented Oct 26, 2021

Switched to using workerpool module

@@ -192,3 +192,10 @@ Since TypeScript compilation takes a lot of time, much time can be gained by usi
If worker thread support is available, `jsii-rosetta` will use a number of workers equal to half the number of CPU cores,
up to a maximum of 16 workers. This default maximum can be overridden by setting the `JSII_ROSETTA_MAX_WORKER_COUNT`
environment variable.

Copy link
Contributor

Choose a reason for hiding this comment

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

Lines above mention "if support is available". Update those to match the current impl.

@nija-at nija-at added the pr/do-not-merge This PR should not be merged at this time. label Oct 26, 2021
@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Oct 26, 2021
@rix0rrr rix0rrr removed the request for review from RomainMuller October 27, 2021 07:49
@rix0rrr rix0rrr removed the request for review from njlynch October 27, 2021 07:49
@rix0rrr rix0rrr added blocked Work is blocked on this issue for this codebase. Other labels or comments may indicate why. and removed blocked Work is blocked on this issue for this codebase. Other labels or comments may indicate why. labels Oct 27, 2021
@mergify
Copy link
Contributor

mergify bot commented Oct 27, 2021

Thank you for contributing! ❤️ I will now look into making sure the PR is up-to-date, then proceed to try and merge it!

@mergify mergify bot added the pr/ready-to-merge This PR is ready to be merged. label Oct 27, 2021
@mergify mergify bot merged commit 919d895 into main Oct 27, 2021
@mergify mergify bot deleted the huijbers/worker-pool branch October 27, 2021 08:46
@mergify
Copy link
Contributor

mergify bot commented Oct 27, 2021

Merging (with squash)...

@mergify mergify bot removed the pr/ready-to-merge This PR is ready to be merged. label Oct 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contribution/core This is a PR that came from AWS.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants