SAMonitor icon indicating copy to clipboard operation
SAMonitor copied to clipboard

Investigate memory leak

Open markski1 opened this issue 2 years ago • 6 comments

In ~12 days of uptime, SAMonitor ballooned up to consuming 1Gb of system memory. This is not a crazy amount, and RAM is only cheap, but considering it's previously ran for over a month using below 400Mb this must've been introduced by a somewhat recent change.

I imagine I can find the reason by reviewing my last 15 commits or so. Can't do that now, so writing this as a reminder to self.

markski1 avatar Dec 22 '23 03:12 markski1

Issue has not reproduced since. Assuming a fluke.

markski1 avatar Jan 07 '24 15:01 markski1

Over the course of the last 46 days of continuous SAMonitor runtime, it ballooned up to ~2Gb of system memory usage.

It was not an issue but it's well above it's usual 200Mb. I must investigate if this is .NET Runtime resource caching or a genuine leak. I'll have to implement ways to track allocations.

markski1 avatar Mar 28 '24 21:03 markski1

Timer assemblies seem to be sticking around after execution. image

markski1 avatar Apr 21 '24 20:04 markski1

After ~15 hours in production, GC Heap size seems sane, but working set has grown to ~250Mb (still reasonable) image

markski1 avatar Apr 22 '24 14:04 markski1

After 4 days of uptime, GC Heap remains similar but the working set has ballooned up to 600Mb. Will investigate.

imagen

markski1 avatar Apr 26 '24 04:04 markski1

Addressing this again:

.NET provides a way to limit maximum WorkingSet allocation (or rather to report this maximum to the operating system). However, Linux, the host operating system for SAMonitor production does not allow this.

It seems to me the next best way to avoid working set ballooning is by decreasing allocations, so I've introduced a connection pool for MySQL, as otherwise every operation spawned a new connection and I'm not sure how .NET went along disposing of those. Furthermore there's a chance it improves performance some by skipping unnecesary handshakes with mariadb.

markski1 avatar May 22 '24 13:05 markski1

The connectionpool update definitely did something, since as expected, less allocations means less working set growth. (after around 4-5 days, we're well below 600mb)

imagen

This still seems excessive, however, so I'll continue checking about.

markski1 avatar May 27 '24 00:05 markski1

Largely solved.

markski1 avatar Jun 23 '24 04:06 markski1