简体   繁体   English

EF6 慢第一次查询对部署的影响

[英]EF6 slow first query implications on deployment

Knowing that Entity Framework is slow on a cold query (first query after model compilation), I am doing some of the standard work around methods to speed it up.知道实体框架在冷查询(模型编译后的第一次查询)上很慢,我正在做一些标准的解决方法来加速它。 Mainly pre-compiled views as well as making a dummy http request on the client side as soon as the application loads to trigger a query to start the model process.主要是预编译的视图以及在应用程序加载后立即在客户端发出虚拟 http 请求以触发查询以启动模型过程。

My question here is specifically around how this works for a deployed application.我在这里的问题特别是关于这如何适用于已部署的应用程序。 For example, if I deploy this on Azure, is it the first cold query for the entire application that will trigger the model compilation, or will this slow cold query happen for each individual user that uses the application?例如,如果我在 Azure 上部署它,是整个应用程序的第一个冷查询将触发模型编译,还是每个使用该应用程序的单个用户都会发生这种缓慢的冷查询? In simple terms, does it happen once and only once, or every time a user hits the site for a new session?简单来说,它是只发生一次,还是每次用户点击网站进行新会话?

The EF slow start is triggered from the first request/s coming into the web server that requires database services. EF 慢启动是从第一个请求进入需要数据库服务的 Web 服务器时触发的。

A couple points to note,有几点需要注意,

  • If you deploy to an Azure web app, ensure that the 'AlwaysOn' application setting is enabled.如果部署到 Azure Web 应用程序,请确保启用“AlwaysOn”应用程序设置。 If not, after a given time period the web app will be suspended and the next request will trigger another cold start.如果没有,在给定的时间段后,Web 应用程序将被挂起,下一个请求将触发另一个冷启动。
  • Similarly if you deploy to a VM with IIS you'll need to check the application recycling settings.同样,如果您使用 IIS 部署到 VM,则需要检查应用程序回收设置。
  • When you deploy a new version of the application code, the process will need to be restarted which will cause another slow start.当您部署应用程序代码的新版本时,该进程将需要重新启动,这将导致另一个缓慢启动。

A good approach to mitigate such slow starts is by using deployment slots and pre-warming slots before sending actual user traffic to it.缓解这种缓慢启动的一个好方法是在向其发送实际用户流量之前使用部署槽和预热槽。 This is straightforward to achieve using Azure Web App deployment slots.使用 Azure Web App 部署槽可以直接实现这一点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM