实体框架MVC页面加载缓慢 [英] Entity Framework MVC Slow Page Loads

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

问题描述

我在Windows Azure上运行的Web应用程序。
它是建立与ASP.Net 4.0,MVC 3,实体框架4.1,使用存储库模式的SQL Server 2008。

I have a web application running on Windows Azure. It is built with ASP.Net 4.0, MVC 3, Entity Framework 4.1, SQL Server 2008 using the Repository pattern.

该应用程序正在执行非常好,直到最近。我们的大多数客户都有数据的几百行,但其中一人开始达到2000+。这极大地减缓了页面加载时间。(15 - 在一些网页上20秒)

The app was performing very well until recently. Most of our customers have a few hundred rows of data but one of them is starting to reach 2000+. This has dramatically slowed their page load times (15 - 20 secs on some pages).

我们刚开始使用MiniProfiler这表明我们有重复的SQL调用一个非常健谈的APP-

We just started using MiniProfiler which indicates we have a very chatty app- with duplicate SQL calls.

在努力,得到尽可能详细,并弄清楚如何才能把事情做得更好,我将解释一些东西,在做什么。

In an effort to give as much detail as possible and to figure out how we can do things better, I'll explain some of the stuff are doing.

我们有一个有两个受保护对象(的currentUser和CurrentCompany)基地控制器。我们在操作中使用这些颇有几分,但它击中DB各一次。所以,我假设我们需要存储在会话这些对象的第一次。是否有结块围绕这些对象的一笔大开销?什么后访问它们之间的关系(CurrentCompany.Offices.First(),等)?

We have a base controller that has two protected objects (CurrentUser and CurrentCompany). We use these quite a bit in our Actions, but it hits the DB each time. So, I am assuming we need to store these objects in session the first time. Is there a big overhead in lumping around these objects? What about accessing their relationships later (CurrentCompany.Offices.First(), etc)?

我们得到基于这些对象的每个页面中的数据:选择,排序,过滤他们的关系,例如:

We get the data for each page based on these objects: selecting, ordering, filtering their relationships, for instance:

CurrentCompany.Employees.Where(r => r.StatusId = Enums.Statuses.Active);

下面'CurrentCompany.Employees返回EntityCollection但如果改变它的IEnumerable。我听说的IQueryable是要走的路?

Here 'CurrentCompany.Employees' returns an EntityCollection but the Where changes it to IEnumerable. I heard that IQueryable is the way to go?

我也读到EF是伟大的事情并迅速运行,但你必须做一些调整,以确保它有大量的数据表现良好。从我已阅读,它会带回的整个行,即使你只要求2列?

I have also read that EF is great to get things up and running quickly but you must do some tweaking to make sure it performs well with lots of data. From what I have read, it will bring back the entire row even if you only asked for 2 columns?

因此​​,所有在mind-能有人指出我应该做的,使这个规模更大的客户。 2000+行不算多毕竟。我们应该使用视图/存储的特效?

So, with all that in mind- can someone point out what I should be doing to make this scale for bigger clients. 2000+ rows is not that much after all. Should we be using views/stored procs?

有资源在那里解释如何获得EF设置基本的选择,etc-但没有实际上是一个scalling的plently一次数据集变得更大。

There are plently of resources out there explaining how to get EF setup with basic selects, etc- but nothing really one scalling it once the data set gets bigger.

任何帮助将大大AP preciated。
布赖恩

Any help would be greatly appreciated. Brian

推荐答案

多少预先加载你在干什么?这是一件事,我们发现是一个重大的性能损失,要解决这个问题,我们开始使用的 Entlib缓存应用程序块
然后将它们合并到对象从缓存中VS从DB

How much eager loading are you doing? That was one thing we found to be a major performance hit, to solve it we started caching the properties using Entlib Caching Application Block and then merging them into the object from cache vs getting them from the DB

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

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