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

Allow concurrency to be set with percentage values #873

Merged
merged 4 commits into from
Mar 21, 2022

Conversation

VanTanev
Copy link
Contributor

Closes #761

This is modeled after the way that jest allows to set workers by providing a percent with --maxWorkers=50%.

I've updated Turbo's CLI parsing to accept --concurrency=50%. It also supports percentages over 100%, so --concurrency=500% is valid. It uses runtime.NumCPU() to get the number of available logical processors, and calculates from there.

Setting the percentage to zero or less is an error. Setting percentage very low, to eg 1% results in always at least 1 as the value for concurrency.

@vercel
Copy link

vercel bot commented Mar 12, 2022

@VanTanev is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@VanTanev
Copy link
Contributor Author

VanTanev commented Mar 13, 2022

I would also want to work on adding the concurrency setting to the turbo.json config file but wanted to submit one PR at a time.

@VanTanev
Copy link
Contributor Author

@jaredpalmer Is there anything I can do to help move this PR forward? Any changes I should do?

Copy link
Contributor

@gsoltis gsoltis left a comment

Choose a reason for hiding this comment

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

Overall this looks solid. Just one minor nit.

func ParseConcurrency(concurrencyRaw string) (int, error) {
if strings.HasSuffix(concurrencyRaw, "%") {
if percent, err := strconv.ParseFloat(concurrencyRaw[:len(concurrencyRaw)-1], 64); err != nil {
return -1, fmt.Errorf("invalid value for --concurrency CLI flag. This should be a number --concurrency=4 or percentage of CPU cores --concurrency=50%% : %w", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Minor nit, but I think the Go convention is to return the zero-value for a type when also returning an error. Here and elsewhere in this function.

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, thanks!

@VanTanev
Copy link
Contributor Author

I want to also write a PR to allow default concurrency to be set in turbo.json - are you open to the idea, and do you have any specific requirements around that?

@gsoltis
Copy link
Contributor

gsoltis commented Mar 21, 2022

@VanTanev Maybe start a discussion for the config file? turbo.json is intended to be checked in and shared, and it's not immediately clear to me that everyone would want to default to the same concurrency. Just as an example, I would imagine your CI might want 100% while devs might prefer some headroom left over. My intuition is that this is a setting that is per-machine, like login information. But happy to get input from the community on what would be helpful here.

@kodiakhq kodiakhq bot merged commit 321c8b6 into vercel:main Mar 21, 2022
@moltar
Copy link

moltar commented Mar 22, 2022

@VanTanev Thanks for this PR!

IMO having an environment config would be more useful than having an entry in the config file.

To me, turbo.json config is something permanent, that is project-dependant, and does not change from environment to environment.

But what changes from environment to environment are ... the environment variables 😁

I might want to run at 100% on CI, and at 50% on my local machine, because it's busy doing other things.

And that's what the environment variables are exactly for! I could even configure my local env permanently via bashrc to always run turbo on 50% settings (again, because I want to use my dev box while it's running builds, regardless of the project). But I always want to take up 100% of the CI.

And if turbo is just another command in a custom build script, then I lose control of the concurrency setting via CLI option and I also cannot change the config from env to env.

@VanTanev
Copy link
Contributor Author

@moltar Can I add both, with precedence going argument > env > turbo.json?

@moltar
Copy link

moltar commented Mar 22, 2022

Can I add both

@VanTanev I am not the project maintainer, merely the one who raised issue #761 😁

But I personally see no value in having it inside the config. But to each their own!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ability to set concurrency to max (equal to CPU cores) --concurrency=max
4 participants