实体框架 - 不同环境下的不同行为 [英] Entity Framework - Different behavior on different environments

查看:97
本文介绍了实体框架 - 不同环境下的不同行为的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近我开始使用Entity Framework(4.1版)和WCF。
我试图制作一个n层asp.net应用程序(.Net Framework 4.0),其中数据层由内部使用实体框架的wcf服务组成。实体框架采用的方法是模型化的。



在我的开发环境中,我同时拥有ASP.NET应用程序和运行在IIS 7.5上的wcf服务,并且在同一个应用程序池下伟大,但它的作品)。在任何wcf服务的第一次访问时,性能相当差,但是在后续访问中可以。第一次访问的性能不佳的原因如下:这里 - 例如与视图生成相关的开销,查询的准备等,



完成开发后,我已经设置了一个包含2个虚拟机的测试环境 - 一个服务器(IIS 7.5),承载应用程序前端,另一个(再次是IIS 7.5)托管wcf服务 - 在不同的机器上运行,在不同的网站和不同的应用程序池下运行。



我期待着相同的行为,即缓慢的第一次访问服务和随后的访问执行得更快,但对服务的所有访问运行缓慢。



问题不在于查询过重,网络不成问题。我已经执行了一个实体框架分析工具,显然在每次调用wcf服务时都会产生生成视图和查询准备的开销。查询的执行速度很快。



本质上我试图找出为什么我注意到不同环境中的不同行为。



从我所看到的,每次创建一个AppDomain,实体框架执行与初始开销相关的操作。但是这是否意味着每次调用WCF服务时都会创建一个新的AppDomain?

解决方案

我想到了。显然,开发机器的设置安装了2011年6月的.Net框架的CTP,测试环境机器具有标准的.Net Framework 4.0。我已经在所有的机器上升级到了.Net Framework 4.5,现在所有的工作都按照预期的方式工作。



显然,.NET 4.0上的实体框架,每一个请求都会介绍生成视图和编译查询的开销。在4.2版本的Framework及其以上版本中,行为更像文献中描述的内容:开销只发生在第一次访问。



WCF AppDomain是由IIS应用程序池创建并在多个请求中重用。



感谢您的输入Narayana


I've recently started working with Entity Framework (version 4.1) and WCF. I'm trying to make an n-tier asp.net application (.Net Framework 4.0), in which the data-layer consists of wcf services that internally use the entity-framework. The approach taken with the entity framework is model-first.

On my development environment i have both the asp.net application and the wcf services running on the IIS 7.5 under the same web site and under the same application pool (It's not great but it works). On the first access of any of the wcf services, the performance is quite poor, but on subsequent accesses it's OK. The reasons for the bad performance on the first access, are explained here - e.g. the overhead associated with the view generation, preparation of the queries, etc,

After completing the development, I've set up a testing environment with 2 virtual machines - one server (IIS 7.5) that hosts the application front-end and another one (again IIS 7.5) that hosts wcf services - running in different machines, under different websites and different application pools.

I was expecting the same behavior, namely a slow first access to the services and subsequent accesses executing a lot faster, but all accesses to the services run slow.

The problem is not with the queries being heavy and it's not a problem with the network . I have executed an entity framework profiling tool, and apparently the overhead of generating the views and the preparation of queries exists on every call to the wcf service. The execution of the queries runs fast.

Essentially I'm trying to figure out why I am noticing different behaviors on different environments.

From what I've read, every time an AppDomain is created, the entity-framework executes the operations that are associated with the initial overhead. But does this mean for every call to a WCF service a new AppDomain is created?

解决方案

I figured it out. Apparently the setup of the development machine had the June 2011 CTP of the .Net Framework installed, and the test environment machines had the standard .Net Framework 4.0. I have upgraded to .Net Framework 4.5 on all of the machines, and everything now works as expected.

Apparently the Entity Framework on .Net 4.0, on every request introduces the overhead of generating the views and compiling the queries. On the 4.2 version of the Framework and above, the behavior is more like what is described on the literature: the overhead only occurs on the first access.

The WCF AppDomain is created by the IIS Application Pool and is reused on several requests.

I appreciate your input Narayana

这篇关于实体框架 - 不同环境下的不同行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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