ASP.NET应用程序的高内存使用率 [英] High memory usage by ASP.NET applications

查看:151
本文介绍了ASP.NET应用程序的高内存使用率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们的一些ASP.Net应用程序存在问题。我们的一些应用程序从一开始就声称拥有大量内存作为其工作集。

We have an issue with some of our ASP.Net applications. Some of our apps claim a large amount of memory from start as their working set.

在我们的2个webfarm服务器(每个4GB的RAM)上运行多个应用程序。我们有一个稳定的环境,大约1.2gb的内存空闲。

On our 2 webfarm-servers (4gb of RAM each) run multiple applications. We have a stable environment with about 1.2gb of memory free.

然后我们添加一个MVC5 + WebApi v2 +实体框架应用程序,立即声称1 + gb作为工作集内存,虽然实际上只使用了约300mb。这导致其他应用程序抱怨没有足够的内存。

Then we add an MVC5 + WebApi v2 + Entity Framework app that instantly claims 1+gb as working set memory, while only actually using about 300mb. This causes other applications to complain that there is not enough memory left.

我们已经尝试设置虚拟内存限制和私有内存限制,没有任何效果。如果我们将其设置为大约500mb,那么应用程序仍然使用或多或少相同的内存量(超过500),并且似乎不尊重已实施的限制。

We already tried setting limit for virtual memory and the limit for private memory, without any avail. If we set this to about 500mb, the app still uses more or less the same amount of memory (way over 500) and does not seem to respect the limits put in place.

作为参考,我用一个空的MVC5项目(VS2013模板)测试了这个,这已经声称300mb的内存,而只使用大约10mb。

For reference, I tested this with an empty MVC5 project (VS2013 template) and this already claims 300mb of memory, while only using about 10mb.

将应用程序设置为一个32位应用程序似乎对减小工作集的大小有一些影响。

Setting the app as a 32-bit app seems to have some impact in reducing the size of the working set.

有没有办法减少工作集的大小,或强制执行它的大小有严格的限制吗?

Is there any way to reduce the size of the working set, or to enforce a hard limit on the size of it?

编辑:
如果使用Web Api v2和Entity Framework对项目进行大量内存使用,我的API控制器将如下所示:

In the case of the huge memory use for the project using Web Api v2 and Entity Framework, my API controllers look like this:

namespace Foo.Api
{
public class BarController : ApiController
{
    private FooContext db = new FooContext(); 

    public IQueryable<Bar> GetBar(string bla)
    {
        return db.Bar.Where(f => f.Category.Equals(bla)).OrderBy(f => f.Year);
    }
}

因为他们看到我能找到的大多数教程(包括来自微软的那些)。使用使用此处不起作用,因为LINQ延迟加载。如果我在任何地方添加了ToList(未测试),它可以工作,但是这会产生任何其他影响吗?

as they look in most tutorials I could find (including the ones from microsoft). Using using here does not work because of LINQ deferred loading. It could work if I added a ToList (not tested) everywhere, but does this have any other impact?

edit2:
如果我这样做的话

edit2: It works if I do

namespace Foo.Api
{
public class BarController : ApiController
{
    public List<Bar> GetBar(string bla)
    {
        using(FooContext db = new FooContext){
           return db.Bar.Where(f => f.Category.Equals(bla)).OrderBy(f => f.Year).ToList();
        }
    }
}

ToList()是否有对api的性能有什么影响? (我知道我不能像IQueryable一样便宜地继续查询)

Does the ToList() have any implications on the performance of the api? (I know I can not continue querying cheaply as with an IQueryable)

Edit3:
我注意到它的应用程序的私有工作集非常高。有没有办法限制这个? (不会导致不断回收)

I notice that its the private working set of the app that is quite high. Is there a way to limit this? (Without causing constant recycles)

Edit4:
据我所知,我在每个APIController上都有一个Dispose。我的前端只是一些简单的MVC控制器,但是对于大部分.cshtml和javascript(角度)文件。

As far as I know I have a Dispose on each and every APIController. My front-end is just some simple MVC controllers but for the large part .cshtml and javascript (angular) files.

我们有另一个应用程序,只是常规mvc,有两个模型和一些简单的视图(没有数据库,或其他可能泄露的外部资源),这也消耗了4-500mb的内存。如果我对它进行分析,我看不到任何指示内存泄漏的内容,我确实看到实际上只使用了10或20 mb,其余的是未分配的非托管内存(但是私有内存工作集的一部分,因此声称这个应用程序,并且不能被任何其他人使用。)

We have another app, just regular mvc, with two models and some simple views (no database, or other external resources that could be leaked) and this also consumes up to 4-500mb of memory. If I profile it, I can't see anything that indicates memory leaks, I do see that only 10 or 20 mb is actually used, the rest is unmanaged memory that is unassigned (but part of the private memory working set, so claimed by this app and unusable by any other).

推荐答案

删除所有Telerik Kendo MVC引用(dll等)修复了我们的问题。如果我们没有运行应用程序,我们所有的内存问题都消失了,我们看到正常的内存使用。

Removing all Telerik Kendo MVC references (dll and such) fixed our problems. If we run the application without, all our memory problems are gone and we see normal memory use.

基本上:它是一个导致高内存使用的外部库。

Basically: it was an external library causing high memory use.

这篇关于ASP.NET应用程序的高内存使用率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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