10

I have this MVC view that has a list of images, these images are dynamic so they come from a controller. To simplify things this controller has only this code:

    [OutputCache(Duration = 0, NoStore = true, Location = OutputCacheLocation.None)]
    public ActionResult RenderImage(int id)
    {
    return File(@"C:\Users\Pictures\myimage.png", "image/png");
    }

I'm not caching things to prove my point.

My view requests 8 images all with a different id, and the timings are horrible:

timings

Sometimes it's fast for some images (which are all the same) and on each refresh it's different, can't find a pattern in it.

The app is hosted in IIS and the timetaken in the server logs shows it's the server that is eating up the time:

enter image description here

Has anyone a clue why this happens? If I request the images individually (not in the page) it's always fast.

tereško
  • 58,060
  • 25
  • 98
  • 150
Flores
  • 8,226
  • 5
  • 49
  • 81
  • 1
    A typical problem - which doesn't explain everything here - is that the browser uses two or four parallel connections to retrieve the images but ASP.NET will block all but one since the access to the session state requires an exclusive lock. If you don't need access to the session state for the images, there's a way to declare it and get rid of the exclusive lock. – Codo Oct 25 '12 at 08:58
  • It could be I/O on the disk. You could try loading the contents of C:\Users\Pictures\myimage.png into a byte[], storing that in memory, and returning that, to see if that's the problem (obviously not a 'production' fix, but it may help debugging) – Alex Oct 29 '12 at 15:36
  • A possible reason can be the method being locked up. Try to make it multi threaded and see if it helps you? – Nipun Ambastha Oct 30 '12 at 04:51

1 Answers1

3

Turns out this is the solution in my case:

[SessionState(System.Web.SessionState.SessionStateBehavior.Disabled)]

user1394965 suggested this as the answer.. but his answer is gone?!

Flores
  • 8,226
  • 5
  • 49
  • 81