MVC ASP.NET is using a lot of memory

前端 未结 6 2089
谎友^
谎友^ 2021-02-14 09:53

If I just browse some pages on the app, it sits at around 500MB. Many of these pages access the database but at this point in time, I only have roughly a couple of rows each for

6条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-14 10:28

    Apparently, that consists of System.Web and all it's children taking up around 200MB. This is quoted as the absolute minimum for your application pool.

    Our web application using EF 6, with a model consisting of 220+ entities in .Net 4.0 starts up at around 480MB idle. We perform some AutoMapper operations at startup. Memory consumption peaks and then returns to around 500MB in daily use. We've just accepted this as the norm.

    Now, for your file download spikes. The issue under web forms when using an ashx handler or the like was explored in this question: ASP.net memory usage during download

    I don't know how that relates to the FileActionResult in MVC, but you can see that the buffer size needed to be controlled manually to minimise the memory spike. Try to apply the principles behind the answer from that question by:

    Response.BufferOutput = false;
    var stream = new MemoryStream(file);
    stream.Position = 0;
    return new FileStreamResult(stream, type); // Or just pass the "file" parameter as a stream
    

    After applying this change, what does the memory behaviour look like?

    See 'Debugging memory problems (MSDN)' for more details.

提交回复
热议问题