orleans icon indicating copy to clipboard operation
orleans copied to clipboard

【please help】Unmanaged memory only increases but does not decrease

Open lfzm opened this issue 6 years ago • 38 comments

Orleans version:v3.1.7 .NET Core : v3.1

image

Can provide DotMemory snapshot。

lfzm avatar May 27 '20 07:05 lfzm

Perhaps the GC is not releasing that memory back to Windows. What are your GC settings, is ServerGC on?

ReubenBond avatar May 27 '20 13:05 ReubenBond

@ReubenBond Yes, turn on ServerGC

lfzm avatar May 28 '20 01:05 lfzm

Turn off the ServerGC,maybe solve the issue.

HermesNew avatar May 28 '20 08:05 HermesNew

It can be solved by shutting down ServerGC. Does Orleans plan memory space in advance for performance?

lfzm avatar May 28 '20 13:05 lfzm

Orleans does not perform any special unmanaged memory allocations in order to reserve space. There are some buffer pools, but those are managed and grow dynamically.

ReubenBond avatar May 30 '20 00:05 ReubenBond

I may be having this same issue, though I am on Orleans v3.1.6. I had upgraded from Orleans v.3.1.0 ...

image

I'll let you guess where the deploy and the rollback were... 😂

pipermatt avatar Jun 02 '20 21:06 pipermatt

@pipermatt What's the deployment environment here - Windows/Linux, .NET Core/Full Framework, which version?

I don't see anything in the fixes between 3.1.0 and 3.1.6 that could obviously change memory allocation profile. Did you upgrade anything else at the same time by chance?

Have you tried taking and analyzing memory dumps to see what the memory is used by?

sergeybykov avatar Jun 02 '20 22:06 sergeybykov

Linux, .NET Core 3.1... On average memory utilization seems to increase at a rate of about 15MB/hr... and there's just SO much allocated it's difficult to wade through it all via command line in Linux. I'm not an expert in the profiling tools, that's for sure.

I seem to be able to reproduce the behavior locally on my MBP as well... but dotnet-dump doesn't support Mac OS X. 😏 So I've been ssh'ing into a test Linux instance to try to diagnose. Tomorrow I may grab a Windows machine so I have the full benefit of PerfView, dotTrace, etc... but first, since I can reproduce locally, I'm methodically stripping down our configuration to as barebones as possible one feature at a time.

We did upgrade several other libraries that are called by our grain code, but the memory leak is apparent on an idle silo that isn't taking any traffic and doesn't have any of our grains instantiated yet.

We'll get it figured out... and will report back. 👍

pipermatt avatar Jun 03 '20 00:06 pipermatt

After stripping my silo of features until it was about as basic as possible, I came to the conclusion that what I was seeing locally was a red herring and not indicative of the problem I saw in production. On a whim, I rolled forward to the release that deployed just before the available memory tanked...

image

You can see a dip where the deploy happened for each silo node, but it is humming along just fine. So now without a real reproduction case, I'm going to have to shelve this investigation unless it rears it's head again.

pipermatt avatar Jun 03 '20 17:06 pipermatt

Interesting. Did you also upgrade to 3.1.7?

sergeybykov avatar Jun 03 '20 20:06 sergeybykov

I have not yet, tho I think I also spoke too soon... memory is going down again steadily... which matches the rate it did before (the first graph was zoomed out to a much larger time range)... image

pipermatt avatar Jun 03 '20 21:06 pipermatt

If memory does indeed leak over time, need to look at the memory dumps or GC profiles. @ReubenBond might have suggestion how to do that in an non-invasive manner.

sergeybykov avatar Jun 03 '20 21:06 sergeybykov

Yeah, I'm working that angle now, though not on the production servers (yet). I think I'm seeing the exact same behavior with this build in my TEST environment, so I'm working on memory dumps there.

pipermatt avatar Jun 03 '20 21:06 pipermatt

Update: there was another difference discovered. ;)

The version that appeared to be leaking memory had its LogLevel set to Debug... we had been running at LogLevel.Information previously. We weren't actually seeing a memory leak... we were seeing Linux allocate more and more memory to disk caching to buffer the writes to the system journal. This memory was always reclaimed when the Silo needed it, though this process itself was slow enough that we would see a spike of errors while it happened.

The tidbit that we didn't understand was why on redeploy, not ALL the memory that had been used was freed. Now, it makes perfect sense... because the silo process wasn't the one using it at all... Linux itself was. Eventually the OS decreased the cache allocation when we rolled back to the version that had LogLevel.Info and it no longer needed so much memory caching to keep up with the journal writes.

Mystery solved!

pipermatt avatar Jun 05 '20 23:06 pipermatt

Thank you for the update, @pipermatt! Makes perfect sense. This reminds me again how often misconfigured logging may cause non-obvious issues.

@lfzm Have you resolved your problem? Can we close this issue now?

sergeybykov avatar Jun 08 '20 21:06 sergeybykov

@pipermatt Haha,Mystery has not been solved. My LogLevel is Warn.Before turn off ServerGC, the memory is between 1.1G and 1.5G.After turn off ServerGC, the memory is between 320M and 350M. At present, I solve the problem of consuming a lot of memory by turn off ServiceGC. This problem has been around for a long time.

HermesNew avatar Jun 09 '20 01:06 HermesNew

@HermesNew I believe this is most likely a ServerGC (.NET Core) concern, rather than something specific to Orleans. It might be worth looking at the various GC settings in the documentation here: https://docs.microsoft.com/en-us/dotnet/core/run-time-config/garbage-collector#systemgcretainvmcomplus_gcretainvm, in particular, RetainVM might be of interest

ReubenBond avatar Jun 09 '20 01:06 ReubenBond

@ReubenBond Start a simple Orleans, use JetBrains dotMemory to detect that there will be Unmanaged memory. So I suspect Orleans’ problem

lfzm avatar Jun 09 '20 03:06 lfzm

Not necessarily. The GC deals with unmanaged memory, Orleans does not

ReubenBond avatar Jun 09 '20 03:06 ReubenBond

@ReubenBond Maybe this GC setting is the best setting. <ServerGarbageCollection>false</ServerGarbageCollection> <ConcurrentGarbageCollection>true</ConcurrentGarbageCollection>

HermesNew avatar Jun 09 '20 04:06 HermesNew