question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TimestampedFileLogger is eating a lot of CPU

See original GitHub issue

dotnet 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:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
kevingossecommented, Sep 20, 2021

Is this causing #21028 too?

I see the TimestampedFileLogger flush thread in your memory dump, so that seems very likely.

0reactions
marcpopMSFTcommented, Oct 6, 2021

PR got merged so closing.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found