## 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
```js
//@ts-check
const { spawn } = require('child_process');
let alive = new Set();
let start = Date.now();
let iterations = 30;
for (let i = 0; i < iterations; i++) {
const cp = spawn('npx nx show projects', [], {
shell: true,
env: {
...process.env,
NX_DAEMON: 'false',
NX_VERBOSE_LOGGING: 'true',
},
});
alive.add(i);
// cp.stdout.on('data', (data) => {
// console.log(`stdout [${i}]: ${data}`);
// });
cp.stderr.on('data', (data) => {
console.error(`stderr [${i}]: ${data}`);
});
cp.on('exit', (code) => {
console.log(`child process ${i} exited with code ${code}`);
alive.delete(i);
});
}
const i = setInterval(() => {
if (alive.size > 0) {
} else {
clearInterval(i);
console.log(
`${iterations} processes exited within ${Date.now() - start}ms`
);
}
}, 1);
```
2.4 KiB
2.4 KiB
Class: StaleProjectGraphCacheError
Hierarchy
-
Error↳
StaleProjectGraphCacheError
Table of contents
Constructors
Properties
- cause: unknown
- message: string
- name: string
- stack: string
- prepareStackTrace: Function
- stackTraceLimit: number
Methods
Constructors
constructor
• new StaleProjectGraphCacheError(): StaleProjectGraphCacheError
Returns
Overrides
Error.constructor
Properties
cause
• Optional cause: unknown
Inherited from
Error.cause
message
• message: string
Inherited from
Error.message
name
• name: string
Inherited from
Error.name
stack
• Optional stack: string
Inherited from
Error.stack
prepareStackTrace
▪ Static Optional prepareStackTrace: (err: Error, stackTraces: CallSite[]) => any
Optional override for formatting stack traces
See
https://v8.dev/docs/stack-trace-api#customizing-stack-traces
Type declaration
▸ (err, stackTraces): any
Parameters
| Name | Type |
|---|---|
err |
Error |
stackTraces |
CallSite[] |
Returns
any
Inherited from
Error.prepareStackTrace
stackTraceLimit
▪ Static stackTraceLimit: number
Inherited from
Error.stackTraceLimit
Methods
captureStackTrace
▸ captureStackTrace(targetObject, constructorOpt?): void
Create .stack property on a target object
Parameters
| Name | Type |
|---|---|
targetObject |
object |
constructorOpt? |
Function |
Returns
void
Inherited from
Error.captureStackTrace