0

Here's my predicament. I have a page in an MVC app that's displaying a list of search results via a partial view using an ajax call. The model is a List<List<string>> representing a dynamic data set, i.e., the users choose which columns they want returned and what order they come back in. All the view is doing is a nested loop which builds out the results table.

One of the potential returned fields is an image of a barcode which is being rendered by another method returning a FileContentResult. Normally this works great, it's slick and performant, to the point where I don't really notice all of the barcodes being rendered and downloaded at all, even in a data set that's hundreds of rows long.

The problem arises when I set a session variable using HttpContext.Current.Session, even something as simple as Session["thingy"] = "thingy";. When that happens there is a drastic performance hit with the barcode images. Result sets that would take a second to load fully are now suffering from image "pop in" for up to 10 seconds after the search button is hit. A few times an image has failed to load, giving an error to the effect of "the server is too busy right now".

Does anyone out there in overflowland have any insight into what could be causing this behavior? I've found a kludgy workaround but it involves unnecessary ajax calls and extra trips to the database.

Dan S.
  • 173
  • 1
  • 14
  • Locking on access to SqlSessionState? – Alexei Levenkov Jun 26 '14 at 21:43
  • No. Sorry, I should have been more clear. I'm using the HttpContext.Current.Session object. I'll update. – Dan S. Jun 26 '14 at 21:47
  • Alexei was asking if your session state is stored on Sql Server or in-proc? – Erik Philips Jun 26 '14 at 21:50
  • It does not matter how you access `Session`, what matters if you use SqlSession or in-memory one for you site. Sql one will lock requests out till previous one completes with some timeout. Check this out - http://stackoverflow.com/questions/1464203/disable-session-state-per-request-in-asp-net-mvc – Alexei Levenkov Jun 26 '14 at 21:53
  • Got it. I'm using in-memory. My workplace hasn't set up SQL sessions yet. – Dan S. Jun 26 '14 at 21:55
  • That link led me to the right place. I had to create a new controller decorated with `[SessionState(SessionStateBehavior.Disabled)]`. That got it to treat the requests asynchronously. No more pop-in! Thanks @AlexeiLevenkov, this has been bugging me all day. – Dan S. Jun 26 '14 at 22:16
  • Please consider to write up your last comment as an answer (ok to do so, including accepting your own). – Alexei Levenkov Jun 26 '14 at 22:47

2 Answers2

0

So the issue was that IIS was treating requests synchronously whenever there was anything stored in the session. So all of my calls to the barcode action were waiting until the last one had finished before moving on, hence the pop-in.

The answer was in this link posted by Alexei. Oddly enough it was the most downvoted answer that provided the easiest solution. I created a new controller for my images and refactored the barcode rendering action into it, then decorated the controller with [SessionState(SessionStateBehavior.Disabled)], forcing IIS to treat any requests to the actions in the controller as asynchronous.

Community
  • 1
  • 1
Dan S.
  • 173
  • 1
  • 14
0

I was having the same issues a while ago. Fixed it by setting EnableSessionState to ReadOnly in my web.config.

I thought it might have some negative side effects but none so far. Even posted a question here in SO looking for comments.

See here: EnableSessionState = ReadOnly - possible side effects?

Community
  • 1
  • 1
HaukurHaf
  • 13,522
  • 5
  • 44
  • 59