-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Conversation
@VanTanev is attempting to deploy a commit to the Vercel Team on Vercel. A member of the Team first needs to authorize it. |
I would also want to work on adding the |
@jaredpalmer Is there anything I can do to help move this PR forward? Any changes I should do? |
There was a problem hiding this 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) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, thanks!
I want to also write a PR to allow default |
@VanTanev Maybe start a discussion for the config file? |
@VanTanev Thanks for this PR! IMO having an environment config would be more useful than having an entry in the config file. To me, 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. |
@moltar Can I add both, with precedence going argument > env > turbo.json? |
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 usesruntime.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 least1
as the value for concurrency.