-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat(core): lock graph creation when running in another process #29408
base: master
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 1 Skipped Deployment
|
View your CI Pipeline Execution ↗ for commit 41b174c.
☁️ Nx Cloud last updated this comment at |
d1f6a60
to
8bb1c07
Compare
@@ -290,6 +316,7 @@ export async function createProjectGraphAndSourceMapsAsync( | |||
'create-project-graph-async:start', | |||
'create-project-graph-async:end' | |||
); | |||
lock.unlock(); |
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.
This should be in a finally
at least
packages/nx/src/utils/file-lock.ts
Outdated
import { existsSync, rmSync, watch, writeFileSync, mkdirSync } from 'fs'; | ||
import { dirname } from 'path'; | ||
|
||
export class FileLock { |
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.
Write this in rust
packages/nx/src/utils/file-lock.ts
Outdated
} | ||
|
||
wait(timeout?: number) { | ||
return new Promise<void>((res, rej) => { |
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.
Use polling
8bb1c07
to
d14b40b
Compare
} catch {} | ||
} | ||
|
||
process.on('exit', cleanupFileLock); |
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.
We might not need this
); | ||
} | ||
return { | ||
projectGraph: await readCachedGraphAndHydrateFileMap(), |
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.
This should throw an error if the graph is in a bad state
d14b40b
to
41b174c
Compare
Current Behavior
Running Nx in multiple processes at the same time with the daemon disabled can cripple a system due to excess memory usage when creating the graph. This is due to plugin workers being started per-parent process when there is no daemon. This change enables a file lock to prevent the simultaneous processing, and read from the cache when the first run completes.
Currently, running
nx show projects
30 times in parallel looks something like this:30 processes exited within 37535ms
Expected Behavior
30 processes exited within 6435ms
Test Script