Spets
Spets

Reputation: 2431

MVC 5 using EF6: Initial page load super slow

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 www.techiejs.com

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!

Upvotes: 1

Views: 1057

Answers (2)

TomTom
TomTom

Reputation: 62093

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.

Upvotes: 0

Rob Angelier
Rob Angelier

Reputation: 2333

I have the same experience with EF. You could use the following library to optimize startup performance:

https://www.nuget.org/packages/EFInteractiveViews/

This library takes a snapshot of your model, so it doesn't have to rebuild completely when nothing has changed (in a nutshell).

EF is known to be slow, especially with big applications (80+ models).

If you have acces to IIS, you can also set the "preload" setting to enabled and "auto start" to on. You could also minimize the recycle period of your app pool.

In your case, if high performance is a critical requirement, I would advice not to use EF, but some other library like Dapper.NET or ADO.NET.

Upvotes: 1

Related Questions