Azure的云服务中运行的Web角色的内存问题(第2代)(Web应用程序) [英] Azure Cloud Service running Web Role (web application) memory issue (Gen2)

查看:124
本文介绍了Azure的云服务中运行的Web角色的内存问题(第2代)(Web应用程序)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个关于运行MVC应用程序的Web角色,用简单的注射器为DI,实体框架6 DAL的高内存使用率的问题。应用程序在Azure云服务运行与2个标准A2实例(2芯,3.5 GB RAM)Web角色,也与运行配置20%的内存使用率CachingService(协同定位的角色)。

I have a question regarding high memory usage of Web Role running MVC application, with Simple Injector as DI, Entity Framework 6 for DAL. Application is running on Azure Cloud Service as Web Role with 2 x Standard A2 Instances (2 Cores, 3.5 GB RAM) and is also running CachingService (Co-located Role) with 20% memory usage configured.

问题是,当实例启动或重启服务的w3wp.exe的内存使用量大约只有500-600 MB(与所有其他应用程序内存使用率在50%左右),但即使没有请求在它的到来启动并继续增长,直到1.7GB左右并停止(与所有其他应用程序的内存使用率在90%左右)。但我注意到的是,内存重启或重新发布之后,有时随意,当然还有下降。

Problem is that when instance is started or rebooted the memory usage of w3wp.exe service is only around 500-600 MB (with all other apps memory usage is around 50%), but even if there are no requests coming in it starts and continues growing until around 1.7GB and stops (with all other apps memory usage is around 90%). But what I noticed is that memory drops sometimes randomly and of course after reboot or republishing.

监视内存堆后,我发现,这是第二代堆的增长并保持大蚂蚁内存分析器本地调试后,我看到采取的是实体框架的第二代中用量最大的与类名TypeUsage对象和MetadataProperty对象(System.Data.Entity.Core.Metadata.Edm命名空间)。

After monitoring memory heaps I noticed that it is Gen2 Heap that grows and stays large and after debugging locally with ANTS Memory Profiler I saw that largest amount of Gen2 is taken by Entity Framework objects with class name "TypeUsage" and "MetadataProperty" objects ("System.Data.Entity.Core.Metadata.Edm" namespace).

现在我的问题是:


  • 这是我们code内存泄漏,我怎么能解决这个问题,如果是这样的话(我检查,并已经尝试过处置创建的每个请求的DbContext)?

  • 这是EF内存泄漏,如果是我能做些什么这一点,也许再有DAL框架?
  • 的情况下
  • 这是一种正常的行为,我应该离开,因为它是什么?

推荐答案

有一个非常低的机会,这是EF内存泄漏,这也不行,你不应该把它这样。您code存在内存泄漏问题。

There is a very low chance that this is a memory leak in EF and this is not OK and you shouldn't leave it like this. Your code leaks memory.

要找到泄漏的最好方法是使用一个内存分析器(蚂蚁是一个不错的选择,我用dotMemory)。探查会告诉你泄露的对象,它也应该表现出你另外两个重要的事情:

The best way to find the leak is to use a memory profiler (ANTS is a good option, I used dotMemory). The profiler will show you the leaked objects and it should also show you two other important things:


  • 创建该对象code位置的堆栈跟踪

  • 的对象树这使引用您的泄漏对象,并不允许它被收集。

这些应该帮助您了解如何创建对象,为什么他们不GC'ed。

These should help you understand how the objects were created and why they weren't GC'ed.

您提到,大部分内存是第二代。这意味着,你的泄漏对象被引用的东西长住。这可能是一个静态变量,ASP.Net应用程序,或者类似的东西。

You mentioned that most of the memory is in Gen2. That means that your leaked objects are referenced by something "long lived". This could be a static variable, ASP.Net Application, or something similar.

当IIS回收您的应用程序可能会出现内存不足的随机掉落。默认情况下发生这种情况每29个小时,但IIS可能不同配置或可能决定回收你的一些其他用途的应用程序。

The random drop of memory may occur when IIS recycles your application. By default that happens every 29 hours, but IIS may be configured differently or may decide to recycle your application for some other purpose.

这篇关于Azure的云服务中运行的Web角色的内存问题(第2代)(Web应用程序)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆