fix(core): establish cpu baseline when possible to improve measurement accuracy#34120
fix(core): establish cpu baseline when possible to improve measurement accuracy#34120FrozenPandaz merged 1 commit intomasterfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
✅ Deploy Preview for nx-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
View your CI Pipeline Execution ↗ for commit 2b0cfa5
☁️ Nx Cloud last updated this comment at |
2c3dc74 to
2b0cfa5
Compare
There was a problem hiding this comment.
Important
At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.
Nx Cloud is proposing a fix for your failed CI:
We removed the pre-loop baseline logic that was interfering with process initialization. The original code ran a baseline refresh immediately at startup (T=0ms), then performed the first collection only 250ms later, which disrupted normal task process startup and caused the Playwright webserver readiness check to timeout. By letting the first collection happen immediately (as before the PR) and moving baseline establishment to occur after the first collection, we maintain backward compatibility with existing process startup expectations while preserving the PR's intent of accurate CPU measurements through strategic baseline timing.
We could not verify this fix.
diff --git a/packages/nx/src/native/metrics/collector.rs b/packages/nx/src/native/metrics/collector.rs
index 01c5288b44..4d2671092e 100644
--- a/packages/nx/src/native/metrics/collector.rs
+++ b/packages/nx/src/native/metrics/collector.rs
@@ -145,13 +145,7 @@ impl CollectionRunner {
let interval = Duration::from_millis(self.config.collection_interval_ms);
// sysinfo's MINIMUM_CPU_UPDATE_INTERVAL + 50ms safety buffer
let baseline_offset = sysinfo::MINIMUM_CPU_UPDATE_INTERVAL + Duration::from_millis(50);
- let post_collection_sleep = interval - baseline_offset;
-
- // First iteration: baseline if needed, then wait before first collection
- if self.should_collect.load(Ordering::Acquire) && self.run_baseline_if_needed() {
- // Sleep to allow CPU to be calculated correctly for the baselined processes
- self.sleep_with_early_exit(baseline_offset);
- }
+ let post_collection_sleep = interval.saturating_sub(baseline_offset);
while self.should_collect.load(Ordering::Acquire) {
// Collect current metrics and send to main collector thread
@@ -166,6 +160,7 @@ impl CollectionRunner {
break;
}
+ // Establish baselines for newly registered processes if any
self.run_baseline_if_needed();
// Sleep until next collection (offset)
self.sleep_with_early_exit(baseline_offset);
Or Apply changes locally with:
npx nx-cloud apply-locally rcTg-vkDQ
Apply fix locally with your editor ↗ View interactive diff ↗
🎓 Learn more about Self-Healing CI on nx.dev
|
This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request. |
Current Behavior
New task processes show 0% CPU on their first measurement because no baseline exists. Accurate readings only appear on the second collection cycle (~1s later).
Expected Behavior
New task processes get accurate CPU readings on their first measurement. The collector establishes CPU baselines for newly registered processes ~250ms before collection, giving
sysinfoenough time to calculate accurate CPU deltas.Technical Details: Baselining & Collection Flow
The collection loop runs in 4 phases: