简体   繁体   English

需要帮助分析ASP.Net Core 3.1 memory dump

[英]Need help analyzing ASP.Net Core 3.1 memory dump

I'm prepared to pay for help on this!!我准备为此付费!

My ASP.Net Core 3.1 application starts at around 450MB, and gradually runs up to around 4.5GB (and I suspect it would grow even more if more memory were available to it).我的 ASP.Net Core 3.1 应用程序从大约 450MB 开始,逐渐运行到大约 4.5GB(我怀疑如果有更多的 memory 可用,它会增长得更多)。

I have taken memory dumps at various stages, and analyzing them with dotMemory seems to show that JsonSerialiserOptions is a prime suspect:我在各个阶段采取了 memory 转储,并用dotMemory分析它们似乎表明 JsonSerialiserOptions 是主要嫌疑人:

最大保留尺寸

Drilling to JsonSerializerOptions shows the 3 instances.钻取到JsonSerializerOptions显示了 3 个实例。 Two have negligible numbers, and if I further drill into the one of the 3 with the highest memory use, it's Key Retention Path shows this:两个的数字可以忽略不计,如果我进一步深入研究 memory 使用率最高的三个中的一个,它的密钥保留路径显示: 密钥保留路径

And this is where I need help.这就是我需要帮助的地方。 I really don't know what to make of these retention paths.我真的不知道如何处理这些保留路径。 I'm expecting that if the problem is in my code, I should find some class of my app at the bottom of a retention path?我期待如果问题出在我的代码中,我应该在保留路径的底部找到我的应用程序的一些 class? I need help trying to figure out from these retention paths where in my code the problem may be.我需要帮助试图从这些保留路径中找出问题可能在我的代码中的位置。

I suspect your problem relates to the reload change token.我怀疑您的问题与重新加载更改令牌有关。 A memory leak reported way back in .NET 2.1 - for more details follow: https://github.com/dotnet/aspnetcore/issues/6102 memory 泄漏报告早在 .NET 2.1 - 有关更多详细信息,请遵循: https://github.com/dotnet/aspnetcore/issues/6102

but

if you're targeting a newer version of the.Net I'd recommend inspecting your ConfigureServices() method ( Startup.cs ) and eliminating misconfigured services lifetimes and/or captive dependencies .如果您的目标是较新版本的.Net,我建议您检查您的ConfigureServices()方法 ( Startup.cs ) 并消除错误配置的服务生命周期和/或强制依赖项。

It turns out the problem was due to a bug in which a flexible, run-time-defined database query was retuning instances of type Object , instead of instances of type dynamic .事实证明,问题是由于一个灵活的、运行时定义的数据库查询正在重新调整Object类型的实例而不是dynamic类型的实例的错误。 The JsonSerializer correctly does NOT cache dynamic types, but it DOES cache Object types. JsonSerializer 正确地不缓存dynamic类型,但它确实缓存Object类型。

So each time the query ran, the JsonSerializer was caching the Object structure.所以每次查询运行时,JsonSerializer 都会缓存Object结构。 The fix was to ensure the the database query returned dynamic types instead of Object types.修复是为了确保数据库查询返回dynamic类型而不是Object类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM