Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is my MVC controller slow when serving images

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.

like image 608
Flores Avatar asked Oct 25 '12 08:10

Flores


People also ask

How to speed up ASP NET MVC?

10 Ways to Speed Up Your ASP.NET MVC Application. 1 1. Application Caching. Caching is one of those programming techniques that should be used as a last resort, but it definitely accelerates your ... 2 2. Optimize Your Images. 3 3. Use Sprites. 4 4. ETags. 5 5. Bundle/Minify JavaScript/CSS. More items

How to reduce the load time of a MVC website?

So, you should prefer to use small file which can be loaded faster or single file which load faster rather than multiple file. In MVC there are two concepts behind this Bundling and Minification. This will help your site to make it faster and decrease the load time.

How to improve the performance of a website in MVC?

As we know that performance is an important part for every application on production. If any website is facing issue of performance then the users do not prefer to use that website. There are many ways to improve the performance of a website in ASP.NET MVC. I am going to demonstrate one by one. You should always use the debug build on production.

Why is my website loading so slow?

Loading images on the web can be a pain, especially if you are doing a website mainly for mobile devices. Because wireless connection is used in such cases, the transfer speed is often slower compared to a wired connection and therefore the content loads slower.


1 Answers

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?!

like image 129
Flores Avatar answered Sep 28 '22 00:09

Flores