MVC 5 using EF6: Initial page load super slow

c# entity-framework-6 model-view-controller razor


I'm trying to figure out what the problem is and I think its related to me not caching any of the DB calls. Essentially what I have is an MVC5 application using EF and plenty of LINQ to make DB calls.

The site is

The first load seems AWFULLY slow(I mean over 30 seconds). When I do a pagespeed evaluation it seems like mostly everything is good. Yeah I don't have all of the CSS and JS minified but we're talking about kilobytes here not MB's and I'm on a broadband connection. The minification would be a few seconds(at best) and not 30+ seconds like it takes now.

What I noticed is if I visit the site on my computer to get the application to return all the DB queries, then if I whip out my phone and access the site, its REALLY fast(<2 seconds). But, if I wait about 1-5 mins and access the site from any device, we're back in 14.4k modem load times.

Anyone have any advice? That awesome performance I get after initially loading the page, I want that to persist until I make some DB change(like a new Post?)

Maybe something in web.config?

Maybe create some code where it does some kind of useless "logging" that keeps the application and application pool workers alive indefinitely? Maybe every 3 minutes the application does some random query to the Db? Hmmm...I know this seems retarded but I'm out of ideas lol.

Thanks again!

3/1/2015 3:38:07 AM

Popular Answer

This is totally not an "EF" problem as in "EF being slow".

It is startup time, which is bad in EF but made a lot worse by a bad IIS configuration that does not automatically compile and load the whole website. Stnadard is that the first request starts the website application. Which has to first compile all pages, then perform all initialization steps then execute the page - at which part EF will start adding some seconds initialization.

But the majority of your startup time is likely the whole "ASP.NET precompilation" phase.

5/23/2016 6:00:40 AM

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow