Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 3 Site Loading Is Extremely Slow

I really don't know where to begin with this question, but the site I'm working on at times has some really slow page loads. Especially after doing a build, but not always. I usually have to refresh the page 5-10 times before it actually comes up. I guess I am trying to see where exactly I should begin to look.

ASP.NET MVC 3 Ninject AutoMapper Entity Framework Code First 4.1 SQL Server 2008 Razor

UPDATES

Concerning some of the questions, it can do this long loading on every page, but after it loads its fairly quick on all the pages.

After posting this and getting your replies I started the application and it is still loading and probably won't ever load unless I click reload on the browser.

No caching, and the EF models aren't huge.

I am using Razor and Visual Studio 2010 with 6 GB of memory and an I7 processor.

I am using IIS Express and the default web server when debugging. It also does this on IIS7 on the main server.

I may look into the MVC Profiler and Glimpse to see what I can find.

Below I have some code this runs when it hits the homepage. I would say it never loads when I first start up the server. I put a break point at var model which never gets hit. If I reload the page then it does.

public ActionResult Index()
        {
            var model = new HomeViewModel();

            model.RecentHeadlines = _headlineService.GetHeadlines(1, Config.RecentHeadlinesPageSize, string.Empty);

            return View(model);
        }

Below is my datacontext setup also.

public class DatabaseFactory : Disposable, IDatabaseFactory
    {
        private DataContext _dataContext;
        public DataContext Get()
        {
            return _dataContext ?? (_dataContext = new DataContext());
        }
        protected override void DisposeCore()
        {
            if (_dataContext != null)
                _dataContext.Dispose();
        }
    }

public class Disposable : IDisposable
    {
        private bool isDisposed;

        ~Disposable()
        {
            Dispose(false);
        }

        public void Dispose()
        {
            Dispose(true);
            GC.SuppressFinalize(this);
        }
        private void Dispose(bool disposing)
        {
            if (!isDisposed && disposing)
            {
                DisposeCore();
            }

            isDisposed = true;
        }

        protected virtual void DisposeCore()
        {
        }
    }

public class UnitOfWork : IUnitOfWork
    {
        private readonly IDatabaseFactory _databaseFactory;
        private DataContext _dataContext;

        public UnitOfWork(IDatabaseFactory databaseFactory)
        {
            _databaseFactory = databaseFactory;
        }

        protected DataContext DataContext
        {
            get { return _dataContext ?? (_dataContext = _databaseFactory.Get()); }
        }

        public void Commit()
        {
            DataContext.Commit();
        }
    }
like image 322
Mike Flynn Avatar asked Dec 15 '11 20:12

Mike Flynn


People also ask

Why is my asp net site so slow?

There can be numerous reasons why . NET applications can be slow. These include incorrect memory sizing, GC pauses, code-level errors, excessive logging of exceptions, high usage of synchronized blocks, IIS server bottlenecks, and so on.

What is lazy loading in MVC?

Lazy loading is a pattern to load the data on demand. It is useful when you have large amount of records and you need to display those. It loads the data step by step when the user scrolls down or needs it.

Why are ASP Net Applications slightly slower on first load?

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?


2 Answers

I'd start by checking what the timeouts are set to in IIS for the process to be recycling itself.

I'm also a very big fan of the MVC Mini-Profiler which could show you exactly how long various parts of your page load are taking, definitely take a look at it.

Edit:

It is worth noting that the Glimpse project is also great for this task these days.

like image 152
sclarson Avatar answered Oct 23 '22 09:10

sclarson


Sounds like it might be an issue with IIS AppPool recycling if you're experiencing it after builds or after periods of inactivity.

To help with AppPool timeouts you can utilize a batch file I created to help mitigate the issue.

That won't solve the problem for you after new builds because your ASP.NET MVC application needs to be JIT-compiled upon first run. If you're really eager to eliminate that issue, you can use ASP.NET precompliation.

like image 6
Aaronontheweb Avatar answered Oct 23 '22 07:10

Aaronontheweb