简体   繁体   English

部署 Azure Web 应用程序时最小化停机时间的最佳实践

[英]Best practice for minimizing downtime when deploying Azure Web Apps

I have an App Service Plan, and in this plan I have deployed 5 components of my solution as Web Apps.我有一个应用服务计划,在这个计划中,我将解决方案的 5 个组件部署为 Web 应用程序。 I use 'Release Management' in Azure DevOps to deploy code to these apps.我在 Azure DevOps 中使用“发布管理”将代码部署到这些应用程序。

To minimise downtime during deployment, I deploy to staging slots first, and then swop the staging slots into production slots to complete deployment.为了最大限度地减少部署期间的停机时间,我先部署到暂存槽,然后将暂存槽换成生产槽以完成部署。

I have configured App Service Warmup (as detailed here ) to call an endpoint that will 'warm up' the application during the slot swapping process.我已配置应用服务预热(详见此处)以调用一个端点,该端点将在插槽交换过程中“预热”应用程序。

This seems to work, but I have two issues:这似乎有效,但我有两个问题:

  1. Even though the warmup has run, the first request made to the app after slot swapping takes a long time.即使预热已经运行,在插槽交换后向应用程序发出的第一个请求也需要很长时间。 I suspect that this is due to the production slot having a 'sticky / slot settings', which as I understand it necessitates an app restart.我怀疑这是由于生产插槽具有“粘性/插槽设置”,据我所知,这需要重新启动应用程序。 To test this, I removed the slot settings, but the delay is still there.为了测试这一点,我删除了插槽设置,但延迟仍然存在。

  2. The applications are dependent on each other, and the slot swapping (even though kicked off in parallel in Azure DevOps), is not guaranteed to complete at the same time, which means that it is possible for newer code to be interacting with old code.应用程序相互依赖,并且插槽交换(即使在 Azure DevOps 中并行启动)不能保证同时完成,这意味着新代码可能与旧代码交互。 While we can engineer around this, this is not optimal.虽然我们可以围绕这个进行设计,但这并不是最优的。

From my investigations so far, the only way I can think of to work around these issues is to spin up a second app service plan, and configure traffic manager to sit in front of the two service plans.从我目前的调查来看,我能想到的解决这些问题的唯一方法是启动第二个应用服务计划,并将流量管理器配置为位于这两个服务计划的前面。 When deploying, I will prioritise one of the service plans while I deploy to the other service plan, and once that is complete divert traffic to the newly deployed service plan while upgrading the other, and then balancing the traffic between the two again once both are on the same code level.部署时,我会优先考虑其中一个服务计划,同时部署到另一个服务计划,一旦完成,将流量转移到新部署的服务计划,同时升级另一个服务计划,然后在两者都完成后再次平衡两者之间的流量在相同的代码级别。

What is the current 'best practice' for zero downtime deployments when using WebApps in Azure?在 Azure 中使用 WebApps 时,当前零停机部署的“最佳实践”是什么?

Is the duplicated service plan with traffic manager a viable option, and if not, what would you suggest?使用流量管理器的重复服务计划是一个可行的选择吗?如果不是,您有什么建议?

Follow these more best practice recommendation.遵循这些更多的最佳实践建议。

SWAP BASED ON THE STATUS CODE根据状态码交换

During the swap operation the site in the staging slot is warmed up by making an HTTP request to its root directory.在交换操作期间,暂存槽中的站点通过向其根目录发出 HTTP 请求来预热。 More detailed explanation of that process is available at How to warm up Azure Web App during deployment slots swap .有关该过程的更详细说明,请参阅如何在部署插槽交换期间预热 Azure Web 应用程序

By default the swap will proceed as long as the site responds with any status code.默认情况下,只要站点以任何状态代码响应,交换就会继续进行。 However, if you prefer the swap to not proceed if the application fails to warm up then you can configure it by using these app settings:但是,如果您希望在应用程序无法预热时不继续进行交换,则可以使用以下应用程序设置对其进行配置:

  • WEBSITE_SWAP_WARMUP_PING_PATH: The path to make the warm up request to. WEBSITE_SWAP_WARMUP_PING_PATH:发出预热请求的路径。 Set this to a URL path that begins with a slash as the value.将此设置为以斜杠作为值开头的 URL 路径。 For example, “/warmup.php”.例如,“/warmup.php”。 The default value is /.默认值为 /。

  • WEBSITE_SWAP_WARMUP_PING_STATUSES:Expected HTTP response codes for the warm-up operation. WEBSITE_SWAP_WARMUP_PING_STATUSES:预热操作的预期 HTTP 响应代码。 Set this to a comma-separated list of HTTP status codes.将此设置为以逗号分隔的 HTTP 状态代码列表。 For example: “200,202”.例如:“200,202”。 If the returned status code is not in the list, the swap operation will not complete.如果返回的状态码不在列表中,则交换操作不会完成。 By default, all response codes are valid.默认情况下,所有响应代码都有效。

MINIMIZE RANDOM COLD STARTS尽量减少随机冷启动

  • WEBSITE_ADD_SITENAME_BINDINGS_IN_APPHOST_CONFIG: setting this to “1” will prevent web app's worker process and app domain from recycling when the App Service's storage infrastructure gets reconfigured. WEBSITE_ADD_SITENAME_BINDINGS_IN_APPHOST_CONFIG:将此设置为“1”将阻止 web 应用程序的工作进程和应用程序域在应用程序服务的存储基础架构重新配置时回收。

https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/#prevent-cold-start https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/#prevent-cold-start

CONTROL SLOT-STICKY CONFIGURATION控制槽粘性配置

If however for any reason you need to revert to the old behavior of swapping these settings then you can add the app setting WEBSITE_OVERRIDE_PRESERVE_DEFAULT_STICKY_SLOT_SETTINGS to every slot of the app and set its value to “0” or “false”.但是,如果出于任何原因您需要恢复到交换这些设置的旧行为,则可以将应用程序设置 WEBSITE_OVERRIDE_PRESERVE_DEFAULT_STICKY_SLOT_SETTINGS 添加到应用程序的每个插槽并将其值设置为“0”或“false”。

https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/#slot-sticky-config https://ruslany.net/2019/06/azure-app-service-deployment-slots-tips-and-tricks/#slot-sticky-config

I would suggest to use Local cache in conjunction with Deployment Slots to prevent any downtime.我建议将本地缓存部署槽结合使用,以防止任何停机。

Add the sticky app setting WEBSITE_LOCAL_CACHE_OPTION with the value Always to your Production slot .将值为 Always 的粘性应用设置WEBSITE_LOCAL_CACHE_OPTION添加到您的Production slot If you're using WEBSITE_LOCAL_CACHE_SIZEINMB , also add it as a sticky setting to your Production slot .如果您使用的是WEBSITE_LOCAL_CACHE_SIZEINMB ,请将其作为粘性设置添加到您的Production slot

• Create a Staging slot and publish to your Staging slot. • 创建一个暂存槽并发布到您的暂存槽。 You typically don't set the staging slot to use Local Cache to enable a seamless build-deploy-test life-cycle for staging if you get the benefits of Local Cache for the production slot.如果您获得生产槽的本地缓存的好处,您通常不会将暂存槽设置为使用本地缓存来为暂存启用无缝的构建-部署-测试生命周期。

• Test your site against your Staging slot . • 根据您的暂存槽测试您的站点。

• When you are ready, issue a swap operation between your Staging and Production slots. • 准备好后,在暂存槽和生产槽之间发出交换操作

• Sticky settings include name and sticky to a slot. • 粘性设置包括名称和对插槽的粘性。 So when the Staging slot gets swapped into Production , it inherits the Local Cache app settings .因此,当Staging 插槽被交换到Production时,它会继承 Local Cache 应用程序设置 The newly swapped Production slot will run against the local cache after a few minutes and will be warmed up as part of slot warmup after swap.新交换的生产槽将在几分钟后针对本地缓存运行,并将作为交换后槽预热的一部分进行预热。 So when the slot swap is complete, your Production slot is running against the local cache .因此,当插槽交换完成时,您的生产插槽将针对本地缓存运行

Refer the Azure Best Practice Document:请参阅 Azure 最佳实践文档:

https://docs.microsoft.com/en-us/azure/app-service/deploy-best-practices https://docs.microsoft.com/en-us/azure/app-service/deploy-best-practices

https://docs.microsoft.com/en-us/azure/app-service/overview-local-cache https://docs.microsoft.com/en-us/azure/app-service/overview-local-cache

I utilise the "Swap with Preview" feature before warming the sites.在加热站点之前,我使用了“预览交换”功能。

The main problem with swapping slots is that the worker processes are restarted when you swap.交换槽的主要问题是交换时工作进程会重新启动。 This means the sites need to be re-warmed.这意味着需要重新加热这些站点。

When you use Swap with Preview the worker processes are restarted but the swap does not complete, meaning you can warm the sites accordingly.当您将 Swap 与 Preview 一起使用时,工作进程会重新启动,但交换不会完成,这意味着您可以相应地预热站点。 Once you are happy with your testing and performance you simply "Complete Swap" and the sites will respond the same.一旦您对测试和性能感到满意,您只需“完成交换”,站点就会做出相同的响应。

暂无
暂无

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

相关问题 将 Mkdocs 部署到 Azure web 应用 - Deploying Mkdocs to Azure web apps 将Web应用程序部署到Azure时,将覆盖web.config的其他部分,而不是appSettings和connectionString - Overriding other parts of the web.config rather than the appSettings and connectionString when deploying web apps to Azure Azure最佳实践-静态Web内容 - Azure best practice - static web content nodejs + azure 函数应用程序 - 处理数据库连接的最佳实践? - nodejs + azure function apps - best practice for handling db connections? 将 Azure Application Insights 添加到多个 .net 应用的最佳实践 - Best practice for adding Azure Application Insights to multiple .net apps 在Azure Web应用程序站点上使用msnodesql部署节点应用程序失败 - Deploying a node app using msnodesql fails on azure Web apps site 部署到Azure Web应用后,某些模块不会自动安装 - After deploying to Azure Web apps, some modules are not automatically installed 在 Azure App Service 上部署多个 web 应用程序.. 这有什么影响吗 - Deploying multiple web Apps on Azure App Service.. Is there any implications of this 通过 Terraform 将容器部署到 Azure - 构建自定义映像并在 azure 容器组中使用它的最佳实践 - deploying containers to Azure via Terraform - best practice to build custom image and use it in azure container group Azure Devops 部署到 Web APP 可能导致停机 - Possible Downtime with Azure Devops Deploy to Web APP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM