如何确保新的自动缩放的 Azure 应用服务实例在处理流量之前处于预热状态?
How can I make sure a new autoscaled Azure App Service instance is warm before it handles traffic?
在应用服务上启用自动缩放后,Azure 将根据设置的规则按需添加实例。我总是从最少 2 个实例开始。我想确保在应用程序代码完全初始化之前,流量不会定向到新的应用程序服务实例。我怎样才能做到这一点?是否可以添加超时?还是以某种方式自动完成?
How can I do this? IS it possible to add a timeout? Or is it done automatically somehow?
如果您使用水平缩放,也称为向外和向内缩放,Azure 将使您的应用程序继续运行 运行 而不会中断,因为会提供新资源。
Azure 将自动预热新实例的应用程序并添加负载平衡以自动在它们之间分配请求。您不需要自己单独配置负载均衡。
关于 azure auto scale 如何工作的更多细节,你可以参考这个article and this article。
"Azure will automatically warm up the new instance's application" - the links you provided do not say this - can you provide other references? I essentially don't want the instance added to a load balancer until a specific URL is accessible with 200 OK or after a hard timeout of 2 minutes.
Web 应用扩展到 2 实例后,如果新请求发送到默认实例网站,Azure 将预热新实例的 Web 应用。
您可以编写如下测试:
在web.config的网络服务器标签中添加以下配置代码以跟踪所有请求:
<tracing>
<traceFailedRequests>
<clear/>
<add path="*">
<traceAreas>
<add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,Rewrite,iisnode" verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="200-600" />
</add>
</traceFailedRequests>
</tracing>
然后,如果您的站点扩展到 2 个实例,则在您访问 Web 应用程序之后。负载平衡不会将请求重定向到第二个实例,因为该实例的进程未启动。 Azure 将自动预热第二个实例的 Web 应用程序。
您可以找到如下图所示的日志:
日志结果:
fr00030.xml(可以发现进程是5860老实例):
fr00031.xml(你会发现进程是 8164 个新实例,耗时 4015 毫秒)
此外,正如Byron Tardif所说,如果你想启用自定义预热(预热所有页面),你可以使用Application Initialization Module。
它也会在新请求访问您的第二个 Web 应用程序实例之前被调用。
您想在应用程序的 web.config 文件中使用应用程序初始化。
您需要添加如下内容:
<system.webServer>
<applicationInitialization >
<add initializationPage="/page-you-want-to-warm-up.php" hostName="your-app.azurewebsites.net"/>
</applicationInitialization>
<system.webServer>
每次您的应用程序启动时,这可能是因为有新的工作人员上线(水平扩展),或者甚至只是由于新部署、配置更改等引起的冷启动...将执行 ApplicationInitialization 以预热在接受该工作人员的请求之前先启动站点。
您可以在此处阅读更多相关信息:http://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/
尽管 post 谈论的是在执行交换操作时使用它来预热站点,但它也适用于冷启动和横向扩展。
在应用服务上启用自动缩放后,Azure 将根据设置的规则按需添加实例。我总是从最少 2 个实例开始。我想确保在应用程序代码完全初始化之前,流量不会定向到新的应用程序服务实例。我怎样才能做到这一点?是否可以添加超时?还是以某种方式自动完成?
How can I do this? IS it possible to add a timeout? Or is it done automatically somehow?
如果您使用水平缩放,也称为向外和向内缩放,Azure 将使您的应用程序继续运行 运行 而不会中断,因为会提供新资源。
Azure 将自动预热新实例的应用程序并添加负载平衡以自动在它们之间分配请求。您不需要自己单独配置负载均衡。
关于 azure auto scale 如何工作的更多细节,你可以参考这个article and this article。
"Azure will automatically warm up the new instance's application" - the links you provided do not say this - can you provide other references? I essentially don't want the instance added to a load balancer until a specific URL is accessible with 200 OK or after a hard timeout of 2 minutes.
Web 应用扩展到 2 实例后,如果新请求发送到默认实例网站,Azure 将预热新实例的 Web 应用。
您可以编写如下测试:
在web.config的网络服务器标签中添加以下配置代码以跟踪所有请求:
<tracing>
<traceFailedRequests>
<clear/>
<add path="*">
<traceAreas>
<add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,Rewrite,iisnode" verbosity="Verbose" />
</traceAreas>
<failureDefinitions statusCodes="200-600" />
</add>
</traceFailedRequests>
</tracing>
然后,如果您的站点扩展到 2 个实例,则在您访问 Web 应用程序之后。负载平衡不会将请求重定向到第二个实例,因为该实例的进程未启动。 Azure 将自动预热第二个实例的 Web 应用程序。
您可以找到如下图所示的日志:
日志结果:
fr00030.xml(可以发现进程是5860老实例):
fr00031.xml(你会发现进程是 8164 个新实例,耗时 4015 毫秒)
此外,正如Byron Tardif所说,如果你想启用自定义预热(预热所有页面),你可以使用Application Initialization Module。
它也会在新请求访问您的第二个 Web 应用程序实例之前被调用。
您想在应用程序的 web.config 文件中使用应用程序初始化。
您需要添加如下内容:
<system.webServer>
<applicationInitialization >
<add initializationPage="/page-you-want-to-warm-up.php" hostName="your-app.azurewebsites.net"/>
</applicationInitialization>
<system.webServer>
每次您的应用程序启动时,这可能是因为有新的工作人员上线(水平扩展),或者甚至只是由于新部署、配置更改等引起的冷启动...将执行 ApplicationInitialization 以预热在接受该工作人员的请求之前先启动站点。
您可以在此处阅读更多相关信息:http://ruslany.net/2015/09/how-to-warm-up-azure-web-app-during-deployment-slots-swap/
尽管 post 谈论的是在执行交换操作时使用它来预热站点,但它也适用于冷启动和横向扩展。