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

fix(dep-graph): set the number of workers with environment variables #8671

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ function buildExplicitDependencies(
// files we need to process is >= 100 and there are more than 2 CPUs
// to be able to use at least 2 workers (1 worker per CPU and
// 1 CPU for the main thread)
if (totalNumOfFilesToProcess < 100 || os.cpus().length < 3) {
if (totalNumOfFilesToProcess < 100 || getNumberOfWorkers() <= 2) {
return buildExplicitDependenciesWithoutWorkers(
jsPluginConfig,
ctx,
Expand Down Expand Up @@ -296,7 +296,7 @@ function buildExplicitDependenciesUsingWorkers(
totalNumOfFilesToProcess: number,
builder: ProjectGraphBuilder
) {
const numberOfWorkers = os.cpus().length - 1;
const numberOfWorkers = getNumberOfWorkers();
const bins = splitFilesIntoBins(
ctx,
totalNumOfFilesToProcess,
Expand Down Expand Up @@ -349,6 +349,10 @@ function buildExplicitDependenciesUsingWorkers(
});
}

function getNumberOfWorkers(): number {
return +process.env.NX_PROJECT_GRAPH_MAX_WORKERS ?? os.cpus().length - 1;
}

function createContext(
workspaceJson: WorkspaceJsonConfiguration,
nxJson: NxJsonConfiguration,
Expand Down