Skip to content

fix(core): reduce daemon idle cpu usage - #36500

Open
rapaglaz wants to merge 7 commits into
nrwl:masterfrom
rapaglaz:fix/daemon-idle-cpu-36467
Open

fix(core): reduce daemon idle cpu usage#36500
rapaglaz wants to merge 7 commits into
nrwl:masterfrom
rapaglaz:fix/daemon-idle-cpu-36467

Conversation

@rapaglaz

Copy link
Copy Markdown

Current Behavior

Nx daemon uses 6-10% CPU even when the workspace is completely idle
(no file changes, no tasks running, no editor open).

Root cause is in startServer() (packages/nx/src/daemon/server/server.ts):
setInterval(..., 20) runs for the whole daemon lifetime, i.e. 50 ticks/sec
regardless of whether anything is happening.

#32618 already fixed the interval's missing delay (previously fired as
fast as the event loop allowed), but the 20ms tick rate itself is still
unnecessarily aggressive.

What changed

Bumped the interval to 500ms.

Testing

Tested locally on a fresh workspace (npx create-nx-workspace@latest --preset=angular-standalone):

interval idle CPU
20ms (current) 6-10%
500ms ~1%
700ms ~0.5%
1000ms ~0.3%

Went with 500ms as a reasonable middle ground — didn't notice any
change in daemon responsiveness or correctness across normal usage
(builds, cache hits, file watching).

Happy to adjust the value or make it configurable if that's preferred.

Closes #36467

@rapaglaz
rapaglaz requested a review from a team as a code owner July 29, 2026 11:09
@rapaglaz
rapaglaz requested a review from leosvelperez July 29, 2026 11:09
@netlify

netlify Bot commented Jul 29, 2026

Copy link
Copy Markdown

👷 Deploy request for nx-docs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 3a2244d

@netlify

netlify Bot commented Jul 29, 2026

Copy link
Copy Markdown

👷 Deploy request for nx-dev pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 3a2244d

@rapaglaz
rapaglaz force-pushed the fix/daemon-idle-cpu-36467 branch 2 times, most recently from c3b878f to 832f8f6 Compare July 29, 2026 11:24
@AgentEnder

Copy link
Copy Markdown
Member

@copilot please fix the merge conflicts in this pull request.

@AgentEnder AgentEnder self-assigned this Aug 27, 2026
@nx-cloud

nx-cloud Bot commented Aug 27, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit e80207f

Command Status Duration Result
nx affected --targets=lint,test,build,e2e,e2e-c... ❌ Failed 47m 27s View ↗
nx run-many -t check-imports check-lock-files c... ✅ Succeeded 2s View ↗
nx-cloud record -- pnpm nx-cloud conformance:check ✅ Succeeded 32s View ↗
nx build workspace-plugin ✅ Succeeded 2m 40s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 17s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 3s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-27 13:55:40 UTC

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud has identified a possible root cause for your failed CI:

We reviewed the three failing tasks and confirmed they are pre-existing failures also present on master, unrelated to this PR's change. The e2e-web failures stem from a webpack@5.110.0 internal incompatibility, and the e2e-remix timeout is a pre-existing CI environment slowness — neither has any connection to the daemon setInterval adjustment from 20ms to 500ms.

No code changes were suggested for this issue.

You can trigger a rerun by pushing an empty commit:

git commit --allow-empty -m "chore: trigger rerun"
git push

Nx Cloud View detailed reasoning on Nx Cloud ↗

🔔 Heads up, your workspace has pending recommendations ↗ to auto-apply fixes for similar failures.


🎓 Learn more about Self-Healing CI on nx.dev

@rapaglaz
rapaglaz force-pushed the fix/daemon-idle-cpu-36467 branch from e80207f to e1ea1c5 Compare August 29, 2026 04:51
startServer() runs setInterval(..., 20) for the entire daemon
lifetime, ticking 50x/sec even when the workspace is completely
idle. PR nrwl#32618 fixed the missing delay (it used to fire as fast
as the event loop allowed) but the tick rate itself is still way
higher than needed.

Bumped the interval from 20ms to 500ms. Tested locally on a fresh
angular-standalone workspace, idle daemon CPU dropped from 6-10%
to ~1%. No correctness issues observed in manual testing.

Closes nrwl#36467
@rapaglaz
rapaglaz force-pushed the fix/daemon-idle-cpu-36467 branch from e1ea1c5 to 1830df8 Compare August 29, 2026 05:09
@rapaglaz
rapaglaz requested a review from AgentEnder September 10, 2026 07:54
…LLING_INTERVAL

Falls back to 500ms if the env var is unset or non-numeric.
@rapaglaz
rapaglaz force-pushed the fix/daemon-idle-cpu-36467 branch from 224c001 to 29244cc Compare September 10, 2026 07:56
@rapaglaz

rapaglaz commented Sep 10, 2026

Copy link
Copy Markdown
Author

Added NX_DAEMON_POLLING_INTERVAL env var to make the daemon's outdated-check interval configurable (falls back to 500ms if unset or non-numeric) - builds on the idle-CPU fix above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nx daemon uses 6-10% CPU at idle

2 participants