本文介绍了Azure 应用服务网站在闲置一段时间后响应时间变慢的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在过去的几周里,我们一直在调查一些性能问题,其中我们的 MVC 应用程序对第​​一个请求的响应非常缓慢.第一个请求需要 30-45 秒,每个新视图需要 3 秒.我们的 MVC 应用程序使用位于同一服务器上的 OData API (Web API).除了与 MVC 应用程序相同的性能问题外,对实体框架版本 6 的第一个查询在 6 秒内执行,新查询的执行速度比后续查询慢 200 毫秒.

In the last couple of weeks we've been investigating some performance issues where our MVC application was responding very slow for the first request. We are talking like 30-45 seconds for the first request and 3 seconds for each new view. Our MVC application is using our OData API (Web API) which is located on the same server. Besides the same performance issues as the MVC application, the first query to entity framework version 6 is executing in 6 seconds and new queries is executing 200ms slower than subsequent queries.

为了满足我们的要求,我们选择执行所有已知的 Ef 查询,并从 Global.asax 中的 Application_Start 访问我们所有的 MVC/API 端点.这似乎可以正常工作至少几个小时,但在一段时间未使用后,对每个 MVC 视图的第一个请求会在 3-5 秒内响应.

In order to meet our requirements, we have chosen to execute all known Ef queries and hit all our MVC/API endpoints from Application_Start in Global.asax. This seems to work fine for at least a couple of hours, but after some time without use, the first request to every MVC view is responding in 3-5 seconds.

我们已将网站配置为始终在线",但在 IIS 日志或我们添加到 Application_Start 的日志中没有发现任何内容.所以看起来我们的应用程序至少不是回收的.我怀疑某种 IIS 缓存被清除或者某些 Ef 缓存?欢迎提出任何建议.

We have configured the websites to be "Always on" and we have not found anything in the IIS logs or the logging we've added to Application_Start. So it seems our applications are at least not recycling. I suspect some kind of IIS cache being cleared or maybe some Ef cache? Any suggestions are welcome.

推荐答案

您需要为您的网络应用启用始终开启"设置.

You'll want to enable the "Always On" setting for your web app.

您可以从 portal.azure.com -> 您网站的刀片 -> 所有设置 -> 应用程序设置 -> 始终开启

You can do that from portal.azure.com -> your site's blade -> All Settings -> Application Settings -> Always On

有关详细信息,请参见此处:https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/

See here for details: https://azure.microsoft.com/en-us/documentation/articles/web-sites-configure/

禁用 Always On 后,该站点会在 20 分钟不活动后关闭,以便为可能在同一应用服务计划上运行的任何其他站点释放资源.

When Always On is disabled, after 20 minutes of inactivity the site gets taken down in order to free up resources for any other sites that might be running on the same App Service Plan.

这篇关于Azure 应用服务网站在闲置一段时间后响应时间变慢的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 22:21