Home > Net >  CPU spikes higher as time progresses, while doing the same work
CPU spikes higher as time progresses, while doing the same work

Time:10-20

I have an ASP.NET Core project, that consists of a server and a client project. The server uses ASP.NET Core 6.0.9 and the client is an ASP.NET Core WebAssembly project, using the same runtime.

In the Startup.cs class of the server, I've registered Cpu usage over time

The big spikes are when I've re-deployed the app. As you can see, the CPU spikes higher and higher with every execution, then returns to normal, idle level before spiking even higher with the next execution. Here's a more zoomed in visualization:

Cpu usage over time (zoomed)

The job is doing pretty much the same work every run. Sure, there might be some minor increase in load every 10th execution or so, but then why does the CPU usage drop so drastically after a rebuild? RAM usage stays at about 40% and doesn't change.

Just to be clear, this doesn't happen because the job has more work with time progressing. I can confirm this because the job ran for a long time with the same exact workload, and still the spikes increased.

If this happened to the memory, then I'd say it's some kind of memory leak, but how can this happen to the CPU?

The fact that only the spikes increase, while the idle usage stays the same, makes me wonder if this is some sort of issue with the Quartz.Net framework?

Has anyone ever encountered an issue like this?

CodePudding user response:

After some days of observing the cpu usage, it seems like I solved the issue.

It had nothing to do with Quartz.Net, but with the logging.

I use Serilog for the logging, with a MariaDB database as storage for the logs. Every run logs about 700 rows, which meant that the table quickly grew to a substantial size. Since the database runs on the same server, the CPU increase probably doesn't have anything to do with my application at all.

I fixed this by decreasing the LogRecordsExpiration parameter from 7 to 2 days. After clearing the table, the CPU increase is still there, but much smaller, and it seems to flatten out after those 2 days.

  • Related