如何与QUOT;热身"实体框架?当它获得"冷QUOT ;? [英] How to "warm-up" Entity Framework? When does it get "cold"?

查看:274
本文介绍了如何与QUOT;热身"实体框架?当它获得"冷QUOT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

没有,回答我的第二个问题是不是冬天。

No, the answer to my second question is not the winter.

preface:

我已经做了很多关于实体框架最近研究的东西,一直困扰我的是它的性能时,查询不暖机,所谓的冷查询。

I've been doing a lot of research on Entity Framework recently and something that keeps bothering me is its performance when the queries are not warmed-up, so called cold queries.

我通过性能考虑文章实体框架5.0去了。笔者介绍的保暖查询,以及它们如何不同,这点我也注意到了我自己不知道他们的存在的概念。在这里,它可能是值得一提,我只有六个本月经验在我背后。

I went through the performance considerations article for Entity Framework 5.0. The authors introduced the concept of Warm and Cold queries and how they differ, which I also noticed myself without knowing of their existence. Here it's probably worth to mention I only have six month of experience behind my back.

现在我知道什么话题我可以研究到另外如果我想更好地了解该框架在性能方面。不幸的是大多数互联网上的信息是过时的或臃肿的主观性,因此,我无法找到任何其他信息的保暖的VS的的查询话题。

Now I know what topics I can research into additionally if I want to understand the framework better in terms of performance. Unfortunately most of the information on the Internet is outdated or bloated with subjectivity, hence my inability to find any additional information on the Warm vs Cold queries topic.

基本上我已经注意到到目前为止,每当我必须重新编译或回收在打,我最初的疑问越来越很慢。读取任何后续数据速度快(主观的),符合市场预期。

Basically what I've noticed so far is that whenever I have to recompile or the recycling hits in, my initial queries are getting very slow. Any subsequent data read is fast (subjective), as expected.

我们会被迁移到Windows Server 2012中,IIS8和SQL Server 2012作为一个少年我居然赢了自己的机会,其他部分之前对它们进行测试。我很高兴他们推出了热身模块,将让我的应用程序准备好了第一个请求。但是,我不知道如何与热身我的实体框架进行。

We'll be migrating to Windows Server 2012, IIS8 and SQL Server 2012 and as a Junior I actually won myself the opportunity to test them before the rest. I'm very happy they introduced a warming-up module that will get my application ready for that first request. However, I'm not sure how to proceed with warming up my Entity Framework.

我已经知道是值得做的:

What I already know is worth doing:


  • 生成我提前意见的建议。

  • 最终移动我的模型到一个单独的组件。

我认为这样做,用常识,可能是错误的做法会

What I consider doing, by going with common sense, probably wrong approach:


  • 做虚拟数据,以温暖的东西在申请开始读
    起来,生成和验证模式。

问题:


  • 什么是最好的方法在任何时候对我的实体框架的高可用性?

  • 在什么情况下不实体框架变冷了? (重新编译,回收,重新启动IIS等)

推荐答案


  • 什么是最好的方法在任何时候对我的实体框架的高可用性?

您可以去为pregenerated意见和静态编译查询的组合。

You can go for a mix of pregenerated views and static compiled queries.

CompiledQuerys因为他们是快速和容易编写,并有助于降低性能都不错。然而,随着EF5没有必要编译,因为EF您所有的疑问都会自动编译查询本身。唯一的问题是,当缓存被横扫这些查询可能会丢失。所以你还是要坚持对那些只发生非常罕见自己编译查询引用,但价格昂贵。如果你把这些查询到所需要的第一次时,他们就会被编译静态类。这可能是一些查询为时已晚,所以你可能希望在应用程序启动时,迫使这些查询的编译。

Static CompiledQuerys are good because they're quick and easy to write and help reduce performance. However with EF5 it isn't necessary to compile all your queries since EF will auto-compile queries itself. The only problem is that these queries can get lost when the cache is swept. So you still want to hold references to your own compiled queries for those that are occurring only very rare, but that are expensive. If you put those queries into static classes they will be compiled when they're first required. This may be too late for some queries, so you may want to force compilation of these queries during application startup.

pregenerating的观点是你提到的另一种可能性。尤其,对于那些需要很长的编译和不改变的查询。这样,你从运行时移动性能开销编译时间。这也将不会引入任何滞后。但是,当然,这种变化经历到数据库中,所以它不是那么容易对付。 code是更加灵活。

Pregenerating views is the other possibility as you mention. Especially, for those queries that take very long to compile and that don't change. That way you move the performance overhead from runtime to compile time. Also this won't introduce any lag. But of course this change goes through to the database, so it's not so easy to deal with. Code is more flexible.

切勿使用大量的TPT的继承(这是在EF一般的性能问题)。无论是建立自己的继承层次过深,也不能太宽。只有2-3特定于某些类的属性可能不够,要求一个自己的类型,但作为任选(可为空)的性能处理,以现有类型

Do not use a lot of TPT inheritance (that's a general performance issue in EF). Neither build your inheritance hierarchies too deep nor too wide. Only 2-3 properties specific to some class may not be enough to require an own type, but could be handled as optional (nullable) properties to an existing type.

不要坚持到了很长时间单一的环境中。每个上下文实例都有自己的一级缓存这会降低性能,因为它变大。上下文创建很便宜,但上下文的缓存的实体内的状态管理可能变得昂贵。其它高速缓存(查询计划和元数据)的上下文之间共享,将与AppDomain中同归于尽。

Don't hold on to a single context for a long time. Each context instance has its own first level cache which slows down the performance as it grows larger. Context creation is cheap, but the state management inside the cached entities of the context may become expensive. The other caches (query plan and metadata) are shared between contexts and will die together with the AppDomain.

所有的一切,你应该确保经常分配情况和使用它们只有很短的时间,你可以快速启动应用程序时,你编译很少使用查询和那些查询提供pregenerated意见性能关键和经常使用。

All in all you should make sure to allocate contexts frequently and use them only for a short time, that you can start your application quickly, that you compile queries that are rarely used and provide pregenerated views for queries that are performance critical and often used.


  • 在什么情况下不实体框架变冷了? (重新编译,回收,重新启动IIS等)

基本上,每次你失去了你的AppDomain。 IIS重新启动执行每<一个href=\"http://serverfault.com/questions/348493/why-does-the-iis-worker-process-recycle-every-29-hours-and-not-every-24-hours\">29小时,所以你永远无法保证你有你的周围情况。另外一段时间后没有活动的AppDomain中也关机。你应该尝试上来又迅速。也许你可以做一些初始化异步的(但多线程问题要小心)。您可以使用调用期间多次应用程序虚拟页面调度的任务时,有以prevent没有请求免于死亡的AppDomain中,但最终会。

Basically, every time you lose your AppDomain. IIS performs restarts every 29 hours, so you can never guarantee that you'll have your instances around. Also after some time without activity the AppDomain is also shut down. You should attempt to come up quickly again. Maybe you can do some of the initialization asynchronously (but beware of multi-threading issues). You can use scheduled tasks that call dummy pages in your application during times when there are no requests to prevent the AppDomain from dying, but it will eventually.

我当你改变你的配置文件或更改组件还有的将是一个重新开始也假设。

I also assume when you change your config file or change the assemblies there's going to be a restart.

这篇关于如何与QUOT;热身&QUOT;实体框架?当它获得&QUOT;冷QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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