-
Notifications
You must be signed in to change notification settings - Fork 27.5k
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
Update static build workers #46705
Merged
Merged
Update static build workers #46705
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
import { ChildProcess } from 'child_process' | ||
import { Worker as JestWorker } from 'next/dist/compiled/jest-worker' | ||
|
||
type FarmOptions = ConstructorParameters<typeof JestWorker>[1] | ||
|
||
const RESTARTED = Symbol('restarted') | ||
|
@@ -24,11 +24,36 @@ export class Worker { | |
this._worker = undefined | ||
|
||
const createWorker = () => { | ||
this._worker = new JestWorker(workerPath, farmOptions) as JestWorker | ||
this._worker = new JestWorker(workerPath, { | ||
...farmOptions, | ||
forkOptions: { | ||
...farmOptions.forkOptions, | ||
env: { | ||
...((farmOptions.forkOptions?.env || {}) as any), | ||
...process.env, | ||
// we don't pass down NODE_OPTIONS as it can | ||
// extra memory usage | ||
NODE_OPTIONS: '', | ||
} as any, | ||
}, | ||
}) as JestWorker | ||
restartPromise = new Promise( | ||
(resolve) => (resolveRestartPromise = resolve) | ||
) | ||
|
||
for (const worker of ((this._worker as any)._workerPool?._workers || | ||
[]) as { | ||
_child: ChildProcess | ||
}[]) { | ||
worker._child.on('exit', (code, signal) => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you have docs handy for this lib/event? I'm going to look now, just curious for my own edification. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
if (code || signal) { | ||
console.error( | ||
`Static worker unexpectedly exited with code: ${code} and signal: ${signal}` | ||
) | ||
} | ||
}) | ||
} | ||
|
||
this._worker.getStdout().pipe(process.stdout) | ||
this._worker.getStderr().pipe(process.stderr) | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Does this mean that we're going to be stuck w/ node defaults? Is that enough for the child processes?
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.
It should be plenty as we span a worker for each CPU by default and the workers are supposed to retry as well.
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.
@ijjk if configured with
experimental.cpus = 1
and if there are hundreds of thousands of pages in a site, could the main worker exit due to Out of Memory when it can't spawn multiple workers?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.
more info on this from @ijjk:
We have a site that generates 208,630 pages, and we've set the env var
--max_old_space_size=12288
on the main call tonext build
because its running on a kubernetes pod limited to 16GB memory (we need some overhead for the parent process).We just upgraded to
v13.2.4
which includes this PR, we wanted to see what effect this release had on memory usage, and now we're seeing a slightly different but interesting behavior in the workers:but despite these errors the build ended up completing successfully.
next build
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.