TimestampedFileLogger is eating a lot of CPU
See original GitHub issuedotnet sdk 6.0.100-rc.1.21458.32
I have a case where a test is getting stuck (I believe this is unrelated to the SDK). However, while waiting for it, the parent dotnet.exe
process is using a full CPU core.
Digging further, it seems like there is a tight loop in TimestampedFileLogger
:
private void WriteLog(object flushThreshold)
{
int writeCount = 0;
int threshold = (int)flushThreshold;
while (!Done)
{
if (_messageQueue.TryDequeue(out string message))
{
_stream.WriteLine($"{TimeStamp} {message}");
writeCount = (writeCount + 1) % threshold;
if (writeCount == 0)
{
_stream.Flush();
}
}
}
Because of that, it will keep using a full core until the test run is finished. I believe some synchronization around the queue would be needed here (just switching to a BlockingCollection
would help a lot).
Issue Analytics
- State:
- Created 2 years ago
- Comments:5 (4 by maintainers)
Top Results From Across the Web
windows - Log %CPU by Process over time
Is there any easy way on Windows to log %CPU time per process over time to a file for later analysis? As far...
Read more >Python datetime.strptime() Eating lots of CPU Time
I am using datetime.strptime but this function is using a lot of cputime according to cProfile's cumtime column. The timestamps are in the ......
Read more >High CPU usage for updating notification timestamps #1102
I've been running today with the "fix" (not a fix) above, and it helps a lot, got at most 5% CPU usage, but...
Read more >How do I collect data for troubleshooting high CPU ...
The purpose of this article is to provide troubleshooting guidance if you are experiencing consistently high CPU utilization on the IG ...
Read more >How to log CPU load? - command line
Here's a logging script I wrote and use: cpu_logger.py. It logs continuously to a set of rotating log files. It allows me to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I see the TimestampedFileLogger flush thread in your memory dump, so that seems very likely.
PR got merged so closing.