gpt4 book ai didi

asp.net-mvc - Azure 是否会阻止同时回收角色实例?

转载 作者:行者123 更新时间:2023-12-03 03:15:15 25 4
gpt4 key购买 nike

我有一个 Web 角色部署到两个实例,应用程序池回收超时设置为默认值 29 小时,应用程序池空闲超时设置为零。我希望保持此应用程序池回收超时,以确保我的应用程序随着时间的推移保持健康。但是,我不希望我的两个实例(意外地)同时回收,以确保我的应用程序保持对用户的响应。

azure是否会注意多个实例的应用程序池不会同时回收?或者:我怎样才能防止这种情况发生?

最佳答案

Azure 不监视 w3wp 或您的应用程序池,也不协调不同实例之间的回收时间。为了防止应用程序池在多个实例之间同时回收,您应该修改每个实例的时间,例如 <29 小时 + IN_# * 1 小时> 这样 IN_0 将设置为 29 小时,IN_1 设置为 30, IN_2 31 岁等。

我的一位同事提供了这段代码:

using System;
using System.Threading.Tasks;
using Microsoft.WindowsAzure;
using Microsoft.WindowsAzure.ServiceRuntime;
using Microsoft.Web.Administration;

namespace RoleEntry
{
public class Role : RoleEntryPoint
{
public override bool OnStart()
{
// For information on handling configuration changes
// see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
int instanceScheduleTime = 0;

int.TryParse(RoleEnvironment.CurrentRoleInstance.Id.Substring(RoleEnvironment.CurrentRoleInstance.Id.LastIndexOf("_") + 1),out instanceScheduleTime);

string roleId = string.Format("{0:D2}",(instanceScheduleTime % 24));
TimeSpan scheduledTime = TimeSpan.Parse(roleId + ":00:00");

using (ServerManager serverManager = new ServerManager())
{
Configuration config = serverManager.GetApplicationHostConfiguration();

ConfigurationSection applicationPoolsSection = config.GetSection("system.applicationHost/applicationPools");
ConfigurationElement applicationPoolDefaultsElement = applicationPoolsSection.GetChildElement("applicationPoolDefaults");
ConfigurationElement recyclingElement = applicationPoolDefaultsElement.GetChildElement("recycling");
ConfigurationElement periodicRestartElement = recyclingElement.GetChildElement("periodicRestart");
ConfigurationElementCollection scheduleCollection = periodicRestartElement.GetCollection("schedule");

bool alreadyScheduled = false;
foreach (ConfigurationElement innerSchedule in scheduleCollection)
{
if ((TimeSpan)innerSchedule["value"] == scheduledTime)
alreadyScheduled = true;
}

if (!alreadyScheduled)
{
ConfigurationElement addElement1 = scheduleCollection.CreateElement("add");
addElement1["value"] = scheduledTime;
scheduleCollection.Add(addElement1);
serverManager.CommitChanges();
}
}

return base.OnStart();
}
}
}

关于asp.net-mvc - Azure 是否会阻止同时回收角色实例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28674888/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com