When running scripts in parallel, you have control over how many concurrent scripts can run at the same time.
You can pass a number value, a percentage value (e.g. 50%), or one of the keywords "auto", "default", or "unbounded"
to the parallel max option.
A plain number sets the limit to the exact number of concurrent scripts. Setting the max to 2 then only allows two scripts to run at the same time.
A value of "auto" sets the limit to os.availableParallelism(), which generally corresponds to the number of available logical CPUs.
A value of "unbounded" allows all scripts to run in parallel, but use this with caution, as it can overwhelm a machine and cause instability.
A percentage value sets the limit to the percentage of os.availableParallelism(). Setting the max to 50% then sets the limit to roughly half of the available logical CPUs. Note that the limit is floored to the nearest integer.
A value of "default" explicitly references the default limit.
When the environment variable BW_PARALLEL_MAX_DEFAULT is not set, it is equal to "auto". You can set BW_PARALLEL_MAX_DEFAULT to any of the valid values listed above.
# Run in parallel (default is "auto" or value of BW_PARALLEL_MAX_DEFAULT env var)
bw run my-script --parallel
# Same as the above command
bw run my-script --parallel=default
# Run in parallel with a max of the available logical CPUs
bw run my-script --parallel=auto
# Run in parallel with a max of 2 concurrent scripts
bw run my-script --parallel=2
# Run in parallel with a max of 50% of the available logical CPUs
bw run my-script --parallel=50%
# Run every script in parallel (use with caution)
bw run my-script --parallel=unbounded
// Run in parallel with the default limit
// Equal to "auto" or value of process.env.BW_PARALLEL_MAX_DEFAULT
project.runScriptAcrossWorkspaces({
workspacePatterns: ["*"],
script: "my-script",
parallel: true,
});
// Same result as above
project.runScriptAcrossWorkspaces({
workspacePatterns: ["*"],
script: "my-script",
parallel: { max: "default" },
});
// Run in parallel with the number of available logical CPUs
project.runScriptAcrossWorkspaces({
workspacePatterns: ["*"],
script: "my-script",
parallel: { max: "auto" },
});
// Run in parallel with a max of 50% of the available logical CPUs
project.runScriptAcrossWorkspaces({
workspacePatterns: ["*"],
script: "my-script",
parallel: { max: "50%" },
});
// Run in parallel with no concurrency limit (use with caution)
project.runScriptAcrossWorkspaces({
workspacePatterns: ["*"],
script: "my-script",
parallel: { max: "unbounded" },
});
// Run in parallel with a max of 2 concurrent scripts
project.runScriptAcrossWorkspaces({
workspacePatterns: ["*"],
script: "my-script",
parallel: { max: 2 },
});