0
votes

First off, this question has been covered a few times (I've done my research), and, for example, on the right side of the SO webpage is a list of related items... I have been through them all (or as many as I could find).

When I publish my pre-compiled .NET web application, it is very slow to load the first time.

I've read up on this, it's the JIT which I understand (sort of).

The problem is, after the home page loads (up to 20 seconds), many other pages load very fast.

However, it would appear that the only reason they load is because the resources have been loaded (or that they share the same compiled dlls). However, some pages still take a long time.

This indicates that maybe the JIT needs to compile different pages in different ways? If so, and using a contact form as an example (where the Thank You page needs to be compiled by the JIT and first time is slow), the user may hit the send button multiple times whilst waiting for the page to be shown.

After I load all these pages which use different models or different shared HTML content, the site loads quickly as expected. I assume this issue is a common problem?

Please note, I'm using .NET 4.0 but, there is no database, XML files etc. The only IO is if an email doesn't send and it writes the error to a log.

So, assuming my understanding is correct, what is the approach to not have to manually go through the website and load every page?

If the above is a little too broad, then can this be resolved in the settings/configuration in Visual Studio (2012) or the web.config file (excluding adding compilation debug=false)?

1
do you publish compiled site or use dynamic compilation?Alexan
Compiled sites @Alex.Dave
How many files/folders do you have in that website?rene
@rene Small, 25 shared .cshtml files (although a max of 2 are ever called from the other pages), 8 CSS, 50 images, 5 controllers and 20 Views (excluding the shared folder)... It's a small site, but I've experienced this issue with much less pages (and on a different server, although that was with the JIT compiling at run time)Dave
Can you check the ASP.NET counters as described here like: Application Restarts, Compilations Total, Errors During Preprocessing, Errors During Compilationrene

1 Answers

0
votes

In this case, there are 2 problems

  1. As per rene's comments, review this http://msdn.microsoft.com/en-us/library/ms972959.aspx... The helpful part was to add the following code to the global.asax file

    const string sourceName = ".NET Runtime"; const string serverName = "."; const string logName = "Application"; const string uriFormat = "\r\n\r\nURI: {0}\r\n\r\n"; const string exceptionFormat = "{0}: \"{1}\"\r\n{2}\r\n\r\n";

    void Application_Error(Object sender, EventArgs ea) { StringBuilder message = new StringBuilder();

    if (Request != null) {
        message.AppendFormat(uriFormat, Request.Path);
    }
    
    if (Server != null) {
        Exception e;
        for (e = Server.GetLastError(); e != null; e = e.InnerException) {
            message.AppendFormat(exceptionFormat, 
                                 e.GetType().Name, 
                                 e.Message,
                                 e.StackTrace);
        }
    }
    
    if (!EventLog.SourceExists(sourceName)) {
        EventLog.CreateEventSource(sourceName, logName);
    }
    
    EventLog Log = new EventLog(logName, serverName, sourceName);
    Log.WriteEntry(message.ToString(), EventLogEntryType.Error);
    
    //Server.ClearError(); // uncomment this to cancel the error
    

    }

  2. The server was maxing out during sending of the email! My code was fine, but, viewing Task Scheduler showed it was hitting 100% memory...

The solution was to monitor the errors shown by point 1 and fix it. Then, find out why the server was being throttled when sending an email!