天蓝色会阻止角色实例同时被回收吗? [英] Does azure prevent that role instances are recycled at the same time?

查看:59
本文介绍了天蓝色会阻止角色实例同时被回收吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I have a web role deployed to two instances with the app pool recycle time-out set to the default of 29 hours, and the app pool idle timeout set to zero. I want to keep this app pool recycle time out to make sure that my application remains healthy over time. However I do not want that my two instances (accidentally) recycle at the same time to make sure that my application remains responsive to users.

Azure是否注意不要同时回收多个实例的应用程序池?否则:如何预防这种情况?

Does azure take care that the application pools of multiple instances are not recycled at that same time? Or else: how can I prevent this situation?

推荐答案

Azure不监视w3wp或您的应用程序池,也不协调不同实例之间的回收时间.为了防止应用程序池一次在多个实例之间回收,您应该修改每个实例的时间,例如< 29小时+ IN_#* 1小时>之类的内容,以使IN_0的赌注设置为29小时,IN_1的赌注设置为30小时,31岁的IN_2等.

Azure does not monitor w3wp or your application pool, nor does it coordinate recycle times between the different instances. In order to prevent the application pool recycling between multiple instances at once you should modify the time for each instance, for example something like <29 hours + IN_# * 1 hour> such that IN_0 would bet set at 29 hours, IN_1 at 30, IN_2 at 31, etc.

我的一位同事提供了以下代码:

A colleague of mine provided this code:

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();
        }
    }
}

这篇关于天蓝色会阻止角色实例同时被回收吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆