DeveryDay
DeveryDay

Reputation: 161

Random Occurances of System.StackOverflow exception on very large MVC view

I am having an issue that I am finding incredibly hard to address. I have an MVC application which contains a view with a fairly large amount in it. To be exact, it has about 2200 TextBoxFor controls in it. I don't encounter any exceptions locally but when I deploy my application to an IIS server (version 10) I am getting a stackoverflow exception. I believe this to be related to the rending of this large view but I am not sure. I have looked and I see no infinite loops, as I my controller method for this view is simply a "return View(ModelInstance);" and I see nothing in the view that could be causing any sort of infinite loop. I suspect that it is simply being overloaded by so many TextBoxFor controls that are being rendered. Any help is appreciated.

Upvotes: 0

Views: 115

Answers (1)

Chris Pratt
Chris Pratt

Reputation: 239290

Honestly, it's probably going to be impossible to answer this without being able to literally sit in front of your server. However, a few things are worth noting:

  1. It's not surprising that this would occur only in production. In development, it's just you. In production, 100s or 100s of clients could be accessing the website at the same exact moment. That's why you're supposed to do load testing on your production server. Just because your application runs fine locally doesn't mean it won't fall down all over itself once you deploy it.

  2. It's not clear whether you're deploying as 32-bit or 64-bit, but if for some reason you are deploying as 32-bit, there is a hard 4GB limit of memory utilization by each process, and it can actually be lower than that, if you haven't configured IIS to allow it to use all of the addressable space. The only limit of the addressable space of a 64-bit application, on the other hand, would pretty much be the constraint of the total RAM available to the system (not including of course RAM devoted to the OS, itself, and any other running applications. If you've got a virtualized server, the first thing I would try is simply throwing more RAM at it and see if the exceptions go away. Now, that's not necessarily the best solution to the problem, as the application is still bloated and inefficient, but it at least gets you some breathing room.

  3. 2200 controls on a single page is just ridiculous. Each one of those is going to result in some amount of RAM being consumed and likely is the problem you're encountering. However, even if your server was beefy enough to churn out a 1000 simultaneous requests that were all loading 2200 controls, the resulting HTML document would be very large and would likely put great strain on the client machine to render. Simply, you should investigate ways to reduce that amount of information being collected all at once. I'm not even sure who in their right mind would complete a form with 2200 inputs. Collect the data in parts or simply break it up into steps. Not only will it reduce the load on your server, but it'll also reduce the load on the client, and provide a much better UX to the user to boot.

Upvotes: 1

Related Questions