53

I've recently created an asp.net mvc web application and published it online.

When first loading the website you should find that it takes around 10-15 seconds for it to actually show, however after it's clicked once, it loads as quickly as I expect the second time round. I'm just wondering if anyone may have an idea of why the website is taking so long?

Jamie Mclaughlan
  • 845
  • 2
  • 10
  • 29
  • 1
    It could be because of several reasons. Primary being DNS servers do not have the IP address for the domain. Also, this does not seem to be a C#/asp.net question, for now. – Abhinav Jan 15 '14 at 23:18
  • Just found another thing, your main page has 2 really large images. You might want to resize them for the purpose. – Abhinav Jan 15 '14 at 23:20
  • What large images are you referring to? Do you mean the ones in the slider to the left of the page? Thanks – Jamie Mclaughlan Jan 15 '14 at 23:36
  • Yes, house4.jpg and office.jpg. Also, from what I see, slider takes a lot of time to load. – Abhinav Jan 15 '14 at 23:45
  • I having the exact same issue. I can see your website still takes ~10 seconds to load, did you make any progress on this issue? – Pedro Mar 04 '14 at 23:18
  • Possible duplicate of [Fixing slow initial load for IIS](http://stackoverflow.com/questions/13386471/fixing-slow-initial-load-for-iis) – Michael Freidgeim Mar 03 '17 at 01:28
  • 1
    I have this issue, I have noticed it be specifically worse when hosting on azure web apps? I have always available enabled. Which should keep the app in memory. – Zapnologica May 05 '17 at 04:49

6 Answers6

32

Typically an application will always take a little extra time to load as the application domain starts up.

Things helping exacerbate this could be anything from poorly written code (IE: Application_Start) to certain libraries you may be using (ORMs for example). How many modules do you have loaded?

For starters check your web.config for the infamous <compilation debug="true">. That can have significant performance ramifications in a production setup. Set it to "false"!

Recommend googling something along the lines of "improving application startup time" and looking for things that may relate to your particular application.

Update from your first comment:

If you're seeing the application start up again (hangs for a few seconds) after 30 minutes consistently this is likely related to your Application Pool Recycling settings in IIS.

Go into IIS Manager (this assumes v7+):

  1. Application Pools
  2. Right click the pool being used for your application(s)
  3. Select "Recycling", a window will come up labeled "Recycling Conditions"
  4. Inspect those settings since they will determine when to automatically kill your app pool and have it restart.

In terms of general performance you may want to try:

  1. Adding some debugging statements that spit out elapsed time in your Application_Start() method or any other applicable location to try to catch what's taking the longest.
  2. Create a completely clean demo project and deploy it. See if it suffers from the same problem. If it doesn't try introducing more and more of your real code until you detect a slowdown.

If you're really stumped #2 may be your best bet even though it will be probably be the slowest option.

Community
  • 1
  • 1
Timeout
  • 7,759
  • 26
  • 38
  • Thanks for the input. I've now set compilation debug to false but that doesn't seem to have fixed it. I'm not using an ORM's, the website is simply accessing an xml feed and displaying the raw data from it and. I don't think I'm using many (if any) modules either. It seems that when I firstly load the website, it takes 10+ seconds, but if I try to load it straight after a few times it takes just over 2 seconds a time which is normal. However, if I leave it for 30 mins and come back to it, it takes 10+ seconds again. Not really sure what would be causing this. – Jamie Mclaughlan Jan 16 '14 at 22:41
  • @JamieMclaughlan Made some additions to my post from your above comment. Hope that helps a bit more. – Timeout Jan 17 '14 at 17:44
  • 2
    This sounds like the default App Pool "Idle Timeout" setting, which after 20 minutes will shutdown your app pool and would cause it to load (which is taking the 15 seconds) again on your first time back. – VFein Mar 05 '15 at 14:07
  • @VFein I think this comment is redundant. My original post detailed app pool recycling and how to inspect/change those settings. – Timeout Mar 13 '15 at 21:39
  • So, I have to simply accept the fact that each first request after build will take 15 seconds to load(at least, without database calls etc.). Maybe there will be Instant Run feature one day like in Android Studio 2.0. – Vlado Pandžić Sep 06 '16 at 13:06
  • @Vlado If you're in a web farm environment you could also "prime" your server by sending an automated request or two before putting it back into the pool. – Timeout Sep 06 '16 at 15:36
  • I tried different solutions, changing different options on application pool, changing different options on compilatin tag inside web.config but it seems 15 seconds is "default" time to get first page after build. I usually change one file or two before building. It would be great if they possible to figure out changes and probably in that way reduce time to first byte after builds. I didn't figure out any way to make it below 15 sec without database calls but with few libraries installed. – Vlado Pandžić Sep 06 '16 at 15:43
31

I also had same problem, with slow first loading asp.net mvc sites, finally I found the best way for load a site, extremly fast in first load.

My solution is for windows server 2008 r2 and IIS 7.5, but in upper windows servers and upper iis versions also work, with some simple diferences.

First of all, you must set startMode of your application pool to always running, this will prevent your application pool from sleeping, after some time. (in my case just this step changes my sites first load from 45-55 seconds to about 8-12 seconds).

in step one, there is no first request for your website, for preloading your website, we need another step, that is by installing Application Initialization module for iis7.5 from here

in step two, you must set preloadEnabled=true for your website, this option is what application initialization added to site settings.

For more information and how you can set these option please refer to this blog post: http://blogs.iis.net/wadeh/application-initialization-part-2

after step two, my web site loads in just 1-3 seconds.

mesut
  • 2,099
  • 3
  • 23
  • 35
  • 1
    Could you please clarify what you mean by "startMode"? I could only see "Start Automatically" under Advanced Settings which is set to True by default. – usefulBee Jan 27 '16 at 18:04
  • 1
    find applicationHost.config in windows/system32/inetsrv/config; locate and find your application pool and add this attribute: startMode="AlwaysRunning" Ex: – mesut Jan 29 '16 at 07:27
  • 1
    Could you please consider adding your comment as an answer to a question I posted earlier and just clarify how to accomplish the same goal from the Web.Config file if possible, and I would be glad to accept it as the answer. http://stackoverflow.com/questions/35046455/how-to-manipulate-application-pool-configurations-in-an-mvc-application – usefulBee Jan 29 '16 at 15:15
  • This was helpful for us! Thank you for the details. – JonH Oct 06 '16 at 17:35
0

In addition to what Jay has said.. you should consider the memory usage of your app pool. This is especially true for Shared hosting environments, where your provider will generally recycle an app pool once a memory limit is hit (rather than time-based). This will again cause your site to "restart", causing an initial load perf issue.

Simon Whitehead
  • 63,300
  • 9
  • 114
  • 138
0

Comment in web.config section <system.codedom> First load from 8-14 sec to 1 sec.

The same problem on WebForms.

  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:1659;1699;1701"/>
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb"
        type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"
        warningLevel="4" compilerOptions="/langversion:default /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+"/>
    </compilers>
  </system.codedom>
-1

It looks the images which rotate are a bit large. In my browser this part loads the last. All the rest of the page loads pretty fast. You may think of resizing these images. Also, large JavaScript files may cause some slowdown during the initial loading.

feradz
  • 1,312
  • 1
  • 16
  • 29
  • Hi thanks for your input. Do you mean the images in the slider to the left of the main page? Thanks – Jamie Mclaughlan Jan 15 '14 at 23:38
  • Yes, the image slider on the left. I guess it appears after all the images which are displayed are loaded. One way to workaround is to change the java script for the slider to appear after the first image is loaded and/or reduce the size of the images. – feradz Jan 16 '14 at 08:55
-5

There are few steps to implement :

  1. Client Side Cache
  2. Bundling and Minification
  3. Server Side Cache
  4. Configuring Auto-Start with IIS Manager
Subhransu
  • 29
  • 2
  • 5