实体框架加载首次非常缓慢 [英] Entity framework very slow to load for first time

查看:427
本文介绍了实体框架加载首次非常缓慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用EF 4在我的网站,发现一个非常令人不安的问题 - 在第一次运行负荷时间是极其缓慢。 (约20-30秒)。
后第一次运行 - 它会工作真快

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.

我的第一跑的意思是经过一些长期没有活动的时间运行(10分钟左右)。

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.

由于该网站还暴露了一个API - 同样的情况出现。第一称之为 - 会在他的身边超时

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

我的DB是SQL Server 2008 R2的。

My DB is SQL Server 2008 R2.

任何想法,为什么发生这种情况?如何解决?

Any ideas why this is happening? How to resolve?

谢谢!

推荐答案

可能是EF,但同样可能可能是您的应用程序池越做越IIS或组合循环。

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

如果有要上你的网站使用的淡季,并希望每个页面快速加载这种情况发生一起客,在过去,我已经建立了定时作业打我的网站在特定的时间间隔(约对我来说5分钟工作),并且确信,它随时准备去当访客来了。

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.

这篇关于实体框架加载首次非常缓慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆