Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS Express localhost loads very slowly for the first request

Please check below the list of things I've tried before closing as duplicate.


The problem:

  • I create a brand new ASP.NET MVC application, I build the application and I run it --> The page takes between 20-30 seconds to load.
  • Every time I rebuild the application and then try to load the page, it takes 20-30 seconds even if I do so immediately after the previous build (i.e., not an idle-timeout issue, I guess?).

I've been struggling with this problem since yesterday, I read every post/article I could found about this with no luck. Though, I have to admit that I'm new to ASP.NET and web development in general and not familiar with the IIS configuration so I might've missed something.

The things I've tried:

  • Disabled antivirus and firewall.

  • Disabled IPv6 by commenting the ::1 localhost line in the hosts file. My hosts file looks like this:

    127.0.0.1       localhost
    # ::1             localhost
    
  • Tried different browsers.

  • Changed the port of the application URL.

  • Changed the application URL from localhost:port to 127.0.0.1:port but when I do so, I get:

    Bad Request - Invalid Hostname

  • Uninstalled and reinstalled IIS Express (tried multiple versions: 7.5, 8.0, and 10.0).

  • Tried installing the "Application Development Features" under Internet Information Services\World Wide Web Services.

  • Launched the VS installer and run a repair.

Environment information:

  • Windows 7 x64.
  • Visual Studio 2015.
  • .NET 4.5.2.
  • IIS currently enabled features: I'm using IIS Express so I'm not sure if this is related.

IIS enabled features

Any idea what could be causing this problem?


Update:

I just tried using Jexus Manager. Loaded the configuration from the .sln file as shown here, started the website and tried the following scenarios:

  • Browsing the website after restarting it (both actions in Jexus Manager) -> 15-20 seconds.
  • Browsing the website (using Jexus) after rebuilding the solution in VS --> 30+ seconds.
like image 231
41686d6564 stands w. Palestine Avatar asked Oct 15 '18 23:10

41686d6564 stands w. Palestine


2 Answers

There are lots of things happening when you fire up Asp.Net MVC app for the first time, so I cannot pinpoint exactly one thing that could be causing a bottleneck but try following suggestions which might help you to improve startup time for your web app:

  1. Always Run your web app from Visual Studio in Release mode (I know that you know it, but still gotta put it)
  2. Check your web.config file and make sure System.Web\compilation has debug=false
  3. Check Application_Start method in Global.asax.cs file to remove unnecessary calls
  4. Razor views are compiled at run-time by default so if you don't do any modification in your view at run-time make sure you are pre-compiling your razor views, better if you could use RazorGenerator to compile your views.
  5. Profile your application using a profiler, Glimpse for example.

I hope this will give your app some boost during start up.

like image 66
Dipen Shah Avatar answered Sep 20 '22 17:09

Dipen Shah


This can be for the following reasons:

  • The server has a heavy processing load.
  • Specific worker processes are consistently idle.
  • No new processing space is available.

There is a well disguised option called Idle Time-out Action which can be changed on the advanced settings of the application pool. The time-out operation is by default set to Terminate, which means that the Windows process hosting the site will be terminated. If this termination happens, the site must be built and the process started on the next visit, resulting in a very slow first-time load.

If you are running a dedicated server for just your service or a small number of sites, then its obviously cramping your style. Setting it to 0 is the way to go in those cases. Other argue that 1740 minutes. Why? it’s the smallest prime number (in hours) over 24.

for changing the Idle Time-out Action to 0 on a Microsoft Windows Server 2012 R2, Access the IIS and Select the Application Pool serving your site and select Advanced Settings in the menu to the right, Locate the Idle Time-Out (minutes) option, Change it to 0 and press OK.

Another possible solution: install the IIS feature Application Initialization. Then it should work with this configuration:

  • set the Start Mode to AlwaysRunning on the application pool
  • Preload Enabled to True on the website level.
like image 40
Amirhossein Mehrvarzi Avatar answered Sep 20 '22 17:09

Amirhossein Mehrvarzi