-
Notifications
You must be signed in to change notification settings - Fork 10.3k
.Net Core 2.0 + 2.2 High Memory Usage On Startup #10515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Would you be willing to share the dump itself privately with us so we can examine it further? |
Yeah we can do that. How’s best to get that to you, and do you have a preferred zip format? |
You can send it to me at |
Thanks, I've send a share link over on OneDrive :) |
I'm not sure if its related but during general operation we are seeing some occurrences ofOutOfMemoryException being thrown on servers with multiple instances and there isn't a common stack trace among them. |
@anurse Using the recommended workaround on that issue, to switch the ServiceProviderMode to Runtime appears to have resolved this issue in our Staging environment. As there is no documentation on ServiceProviderMode (that I can find ...) can you offer some guidance on the difference between the two modes? I can see that the default Dynamic mode is compiled whereas runtime is resolved at request, am I correct in thinking we should only be expecting a small performance hit by switching mode until a fix is released? |
You'd have to measure in your scenario to know for sure. Here's a brief summary of the modes:
So I would expect some performance impact from switching modes. |
Hi Andrew, I can confirm this was the route cause of the high CPU on startup & the OutOfMemoryException's we were seeing throughout the day when the application was starting up again. We are now averaging a slightly higher CPU usage, but thankfully it's nothing Drastic. We'll keep an eye on #2737 relating to this - Thanks. |
Using the The fact that switching dramatically reduces CPU/Memory load indicates a very large number of DI services, all of which are used at startup, meaning we have to compile a lot of these dynamic methods. |
I’m going to reply on behalf of @AdamRiddick (same company). I believe Adam is on leave. No we do not have a large number of DI services. The application is quite small. It is a custom version of Identity Server 4. The more we look at it it looks like a bug/issue with the dynamic mode. Did you manage to look at the dump Adam sent? That shows the issue quite well. |
Interesting. I did look at the dump |
Yeah, I double checked the dump and it looks like it may be after the memory spike is cleaned up. For example, I see the total GC heap size reported as only about ~130MB:
I do see 4GB of Private Bytes recorded in the dump (the Did you find more relevant data in the dump? That might help point me in the right direction. Is it possible for you to share the application code at all? |
Ah ok - I'll go through the dump again and try and locate what I found interesting. But we saw 15000 items in a collection that I believe was related to the container and dynamic mode. I will dig it up. If we connect privately, we can share application code. I am in Sydney, Adam is in UK. So hopefully there should be crossover where we can jump on a call or something. |
Here is what I found in the dump file. To be honest, now that I look at it, I really don't know whether this is normal or not, but I thought I would enclose it anyway. |
Feel free to send me an email at Feel free to share additional data with me there. Probably the code I'm most interested in is where you register your services. The |
Email sent :-) |
I just wanted to provide an update here. @anurse has been very helpful over email, but I am still a little stuck without knowing the ins and outs of the framework. So hopefully someone else can point me in the right direction.
Here is a standard memory trace from both dotMemory and ANTS. The two spikes are very visible. The most success I have had is using DebugDiag which said the following:
The report is here: @anurse has said that this finding is in line with his thoughts that the dynamic code-gen process (Dynamic mode) is responsible for this. He said that in the memory dump, there were 16000 instances of the linq query to generate one particular class (DBContext). My questions are:
|
This would make sense if there are a lot of code-generation paths going on.
This is likely the root cause of 2. I'm not sure where to start yet either but it's something we can continue to dive in to (cc @davidfowl) |
I wonder if something is wrong with the EF configuration causing it to do weirdness (like making a bunch of internal service providers). |
@davidfowl What does the code that registers EF in D.I. look like? |
@AdamRiddick and @gregpakes shared some of the code with me offline, I can loop you both in on the thread. |
Thank you for contacting us. Due to a lack of activity on this discussion issue we're closing it in an effort to keep our backlog clean. If you believe there is a concern related to the ASP.NET Core framework, which hasn't been addressed yet, please file a new issue. This issue will be locked after 30 more days of inactivity. If you still wish to discuss this subject after then, please create a new issue! |
Uh oh!
There was an error while loading. Please reload this page.
Describe the issue
When spinning up an .Net Core Application after an application pool recycle in IIS, the process seems to go on a few memory grabbing runs but doesn't appear to be using it - This doesn't look like a memory leak as the memory is always reclaimed.
For example, the memory usage will cycle upwards to around 3-4GB, back down to about 400mb, then up and down between these a handful more times before settling down to ~200mb. The application starts as normal through this process, and can be accessed and used as normal.
Normal usage averages at around 200mb.
We've managed to take a dump at it's peak;
To Reproduce
We haven't been able to reproduce this outside of our production server environments.
Is there a way we can determine what is causing this high memory usage during startup?
Edit
I've also been able to reproduce this with;
The text was updated successfully, but these errors were encountered: