Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC 4 IIS memory leak for each connection

I have an AsyncController set up to perform long-polling actions. This all works fine, however a colleague has noticed a memory leak on the server that appears to increase with every new connection.

I've created a little application to request from this page thousands of times and I'm monitoring the memory usage for the IIS process. Each connection increases the memory usage, but doesn't fall all the way back down when the client has disconnected.

After further investigation, I found that this still happens even when I replace my AsyncController with a standard Controller that does nothing but this:

public class WaitController : Controller
{
    public JsonResult Member(string oauth_token, int service_id, bool busy = false)
    {
        return Json(new
        {
            ready = false,
        }, JsonRequestBehavior.AllowGet);
    }
}

Although in this, there is not as much memory usage, the behaviour appears to be exactly the same.

I've ran a memory profiler to show the difference between 10,000 connections and there is barely anything there. The most memory is taken up by instances of ExpiresEntry[] from System.Web.Caching or System.Runtime.Caching, however these total to nothing in comparison to the memory increase I'm getting on the IIS worker process.

My question is, is IIS doing this by design? Perhaps this had been allocated for connection threads, which are hanging around just in-case they're needed later? Is this a bug with IIS, ASP.NET or MVC 4?

It was my decision to use MVC 4's WebAPI features for this because we want this to be flexible, maintainable, future-proof and to be accessed via AJAX. It also seemed to make sense from a development point of view, as we have built the website in MVC 4 too.

However, a colleague has now raised this as a critical problem with the system architecture as we will (in the future) need thousands of clients connected. He is suggesting we use WCF instead. So, bonus question - will using WCF resolve these problems?

like image 627
Connell Avatar asked Feb 27 '13 14:02

Connell


1 Answers

There's a great article from a MS Field Engineer about this subject. Might be of help.

like image 141
rusev Avatar answered Oct 03 '22 18:10

rusev