Skip to content
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

Reduce CPU while polling for console log changes #1354

Merged
merged 1 commit into from
Dec 12, 2023

Conversation

drewnoakes
Copy link
Member

@drewnoakes drewnoakes commented Dec 12, 2023

Fixes #760

The current implementation polls the file system for changes to stdout/stderr files on disk. This polling causes high CPU while logs are visible in the UI.

To reduce the problem, we introduce a small sleep that happens only when we are caught up with the contents of the file. The delay of 100ms is forever in computer time (i.e. it's a low duty cycle activity) while also being very fast for a human's perception.

Note that if logs start streaming in fast, we will not hit this sleep. It only occurs when we've read everything. If in the subsequent 100ms new logs arrive, they'll all be processed in the next iteration of the loop.

Longer term we hope to have a console log streaming API from DCP for this.

Microsoft Reviewers: Open in CodeFlow

The current implementation polls the file system for changes to stdout/stderr files on disk. This polling causes high CPU while logs are visible in the UI.

To reduce the problem, we introduce a small sleep that happens only when we are caught up with the contents of the file. The delay of 100ms is forever in computer time (i.e. it's a low duty cycle activity) while also being very fast for a human's perception.

Note that if logs start streaming in fast, we will not hit this sleep. It only occurs when we've read everything. If in the subsequent 100ms new logs arrive, they'll all be processed in the next iteration of the loop.

Longer term we hope to have a console log streaming API from DCP for this.
@drewnoakes drewnoakes added area-dashboard perf Issues pertaining to Perf labels Dec 12, 2023
@drewnoakes
Copy link
Member Author

While validating this fix, I found and filed #1355 which is a similar issue though cannot be solved with this technique.

@davidfowl
Copy link
Member

I was gonna suggest doing more backoff until there's changes again but this might be a good enough, low risk mitigation for p2

@drewnoakes drewnoakes merged commit 967fde3 into dotnet:main Dec 12, 2023
8 checks passed
@drewnoakes drewnoakes deleted the reduce-log-polling-cpu branch December 12, 2023 21:29
@drewnoakes
Copy link
Member Author

/backport to release/8.0-preview2

Copy link
Contributor

Started backporting to release/8.0-preview2: https://github.com/dotnet/aspire/actions/runs/7187493818

@github-actions github-actions bot locked and limited conversation to collaborators Apr 27, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-dashboard perf Issues pertaining to Perf
Projects
None yet
Development

Successfully merging this pull request may close these issues.

High CPU when showing the logs view for an executable on the dashboard
2 participants