4

I'm using EF 4 on my web site and have found a very disturbing problem - the first run load time is extremely slow. (about 20-30 seconds). After the first run - it will work really fast.

What I mean by "first run" is a run after some long time of no activity (10 minutes or so).

So, if there is a lot of traffic, the site is working just fine. If there are slow days - the first one to come to the site after a long traffic break, will get a very bad experience.

Because the web site also exposes an API - the same happens there. The first to call it - will get a timeout on his side.

My DB is SQL Server 2008 R2.

Any ideas why this is happening? How to resolve?

Thanks!

Roman
  • 4,443
  • 14
  • 56
  • 81
  • 2
    It's a known behaviour: http://stackoverflow.com/questions/10757019/entity-framework-initialization-is-slow-what-can-i-do-to-bootstrap-it-faster Two more references: http://stackoverflow.com/q/9261095/270591 and http://stackoverflow.com/q/11543990/270591 – Slauma Aug 16 '12 at 22:18

3 Answers3

3

Could be EF, but just as likely could be that your app pool is getting recycled on IIS or a combination.

If there are going to be slow periods of usage on your website, and you want each page to load fast for a visitor that happens along, in the past I have setup a timed job to hit my website at specific intervals (about 5 minutes worked for me), and that made sure that it was always ready to go when a visitor came along.

Very easy to do if you have access to a task scheduler.

E.J. Brennan
  • 45,870
  • 7
  • 88
  • 116
  • Well, got to use a task scheduler :) seems to fix the problem. – Roman Aug 17 '12 at 15:59
  • A lot of info about this problem of delayed start with ORM systems, so one must fix it creatively :) In IIS 7.5 and above there are some easier solutions. – Roman Aug 17 '12 at 16:00
1

I was having this problem as well, I found out that it had to do with a large number of views in my database.

Performance Considerations (Entity Framework) really helped and the steps for mitigating the impact of generating views brought down a 45-60 second initial load to 3-4 seconds.

Garrett
  • 81
  • 1
  • 3
0

I would do a little more research to identify that it is a EF, DB or IIS. I think IIS looks to be the likely culprit, as @E.J. Brennan stated.

In IIS I would ensure the IIS application pool has not recycled, while it is normal the frequency can be managed to make it less of an impact on end users. EF is probably not the problem, but the caching in the app or DB could hide an underlying SQL issue. Capture the query and analyze the execution plan to ensure it is optimal.

Hope this help pinpoint the issue.

Dustin Laine
  • 37,935
  • 10
  • 86
  • 125