Skip to content

feat: allow specifying concurrency in config / environment #10236

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

Merged

Conversation

kade-robertson
Copy link
Contributor

@kade-robertson kade-robertson commented Mar 26, 2025

Description

This adds a couple new ways to configure task run concurrency:

  • A TURBO_CONCURRENCY environment variable
  • A concurrency configuration value in turbo.json

These options should follow the same precedence rules for other options which are made available in multiple locations. I think the environment variable is the most valuable to me (IMO), as this would make it a lot easier to turn off or drastically reduce concurrency in CI scenarios with restricted performance, where running multiple test suites at the same time could cause flaky results due to timeouts, or too much resource contention in general scenarios. Being able to specify this in the configuration file is maybe less valuable, but there are situations where it might be desirable.

The --concurrency option is obviously already available and certainly usable in combination with other changes (enforcing the use of an alias, or setting up different package.json scripts for CI and local development), but enabling this to be enforced via the config or an environment variable makes it a lot easier to turn off concurrency in CI, for example.

There is some active desire for this feature to exist:

Notably, this does not enable configuring concurrency per task, which was part of one of the discussions here. That seemed like a much larger lift vs. just adding an environment variable and config option that behaved exactly like the CLI argument already does. There is still some demand for this "simple" option.

Testing Instructions

  1. Build turbo
  2. Check that you can now specify a top-level "concurrency" property in your turbo.json, with the same behaviour as the CLI argument.
  3. Check that you can now specify a TURBO_CONCURRENCY environment variable, with the same behaviour as the CLI argument.
  4. Check that this settings maintains expected preference (i.e. CLI arg > env var > turbo.json)

I've done this checks (with some print debugging) on repos where I use turbo and it seems to work as expected. I've added some unit and integration tests where it seemed to make the most sense, but there were some spots where it was unclear if I should add something. If I've missed a spot or need some additional checks, let me know!

@kade-robertson kade-robertson requested review from anthonyshew and a team as code owners March 26, 2025 15:20
@turbo-orchestrator turbo-orchestrator bot added area: docs Improvements or additions to documentation needs: triage New issues get this label. Remove it after triage labels Mar 26, 2025
Copy link

vercel bot commented Mar 26, 2025

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
examples-basic-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2025 1:44pm
examples-designsystem-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2025 1:44pm
examples-native-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2025 1:44pm
examples-svelte-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2025 1:44pm
examples-tailwind-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2025 1:44pm
examples-vite-web ✅ Ready (Inspect) Visit Preview 💬 Add feedback Apr 11, 2025 1:44pm

Copy link

vercel bot commented Mar 26, 2025

@kade-robertson is attempting to deploy a commit to the Vercel Team on Vercel.

A member of the Team first needs to authorize it.

@chris-olszewski chris-olszewski self-assigned this Mar 31, 2025
Copy link
Member

@chris-olszewski chris-olszewski left a comment

Choose a reason for hiding this comment

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

Thank you so much for the contribution. Everything looks good aside from the removing of the inputs.execution_args reference in opts.

@chris-olszewski
Copy link
Member

If you could rebase, I'll work on getting this merged and released in the next canary. Thank you for the contribution!

@kade-robertson
Copy link
Contributor Author

If you could rebase, I'll work on getting this merged and released in the next canary. Thank you for the contribution!

Should be good to go!

@chris-olszewski chris-olszewski merged commit 248a41e into vercel:main Apr 14, 2025
46 of 54 checks passed
chris-olszewski pushed a commit that referenced this pull request Apr 25, 2025
### Description

This is a follow-up fix to:
#10236

As it turns out, this change presented a regression in how the
`--concurrency` flag behaves in watch mode. Previously, since this flag
was read from the `execution_args` directly, it worked as expected.
After switching it to read from `config`, it no longer worked in `watch`
mode, as `Args` would only extract correctly from the `Run` command.

This change lets the `Args::execution_args()` getter return the
execution args from the watch command that has been run, if present.
This _is_ a pretty significant change, as previously _none_ of the run
mode execution args would be respected in watch mode. I'm not totally
confident this is desired.

The alternative is to bring back the special case for `concurrency`, and
try to read from execution_args directly when parsing it, and falling
back to `config` otherwise.

### Testing Instructions

1. Clone `main` and `pnpm build:turbo`
2. Run `./path/to/turbo watch <some-cmd>` in a repository where more
than 10 tasks (the default) are persistent
3. Observe that even specifying `--concurrency=<task-count>` does not
override this setting
4. Checkout the v2.5.0 commit and rebuild
5. Run the same test, and observe that the concurrency flag works as
expected
6. Finally, clone this branch and rebuild
7. Run the same test, and observe that the concurrency flag works as
expected
chris-olszewski pushed a commit that referenced this pull request Apr 25, 2025
### Description

This is a follow-up fix to:
#10236

Unfortunately I didn't notice `turbo-types` is where the schema actually
lives and is generated from, so the configuration schema never got
updated to support this option.

### Testing Instructions

1. Install turborepo 2.5.1
2. Add a "concurrency" option to your `turbo.json`
3. Observe that using the public schema URL in `$schema` flags the
concurrency option as an unknown property.
4. Clone this branch
5. Change the path in `$schema` to point to the schema in this branch
6. Observe the previous warning goes away.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: docs Improvements or additions to documentation needs: triage New issues get this label. Remove it after triage
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants