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

Ability to set concurrency to max (equal to CPU cores) --concurrency=max #761

Closed
moltar opened this issue Feb 20, 2022 · 2 comments · Fixed by #873
Closed

Ability to set concurrency to max (equal to CPU cores) --concurrency=max #761

moltar opened this issue Feb 20, 2022 · 2 comments · Fixed by #873

Comments

@moltar
Copy link

moltar commented Feb 20, 2022

Describe the feature you'd like to request

I am not an expert in this area, but I think it's counter-productive to set the concurrency to a higher number than there are CPU cores available for CPU-hungry processes, like tests and builds, as these processes would be competing for resources.

Thus, a default setting of 10 might be counter-productive in certain environments, like CI, where the number of cores can be lower.

For example, GitHub Actions only have 2 cores available for Windows and Linux, yet 3 for macOS.

Describe the solution you'd like

I think there should be a way to specify "max" or some other variation of that, that signals Turbo to sniff out the number of cores and set the concurrency to that value.

Describe alternatives you've considered

turbo run build --concurrency=$(node -r os -e 'process.stdout.write(os.cpus().length.toString())')
@marcelltoth
Copy link

marcelltoth commented Mar 8, 2022

In my opinion it would probably be even better if we could set the global default using an environment variable. I'm sure many people are like us: we have a long and complex CI pipeline with lots of jobs, adding --concurrency everywhere is cumbersome.

It would be much simpler if we could specify e.g. TURBO_DEFAULT_CONCURRENCY=4 globally, then we

  1. wouldn't have to litter the CI config file with --concurrency settings everywhere.
  2. would have a single place to change in case I were to change the executor size.

Note that simply changing turbo's default to the CPU count (like jest does for example) is not adequate, as some CI providers like CircleCI always show a lot of CPU cores (32 in CCI's case), regardless of the actually available size.

What do you think?

@moltar
Copy link
Author

moltar commented Mar 8, 2022

I think these are separate features and both have the place.

@kodiakhq kodiakhq bot closed this as completed in #873 Mar 21, 2022
kodiakhq bot pushed a commit that referenced this issue Mar 21, 2022
Closes #761

This is modeled after the way that `jest` [allows to set workers by providing a percent with `--maxWorkers=50%`](https://jestjs.io/docs/configuration#maxworkers-number--string).

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.
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 a pull request may close this issue.

2 participants