Azure的Web角色"预热"策略 [英] Azure Web Role "warm up" strategies

查看:288
本文介绍了Azure的Web角色"预热"策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现,待用期间后发出请求到我们的作用将导致一个非常缓慢的请求(最长30秒)。初始请求后,角色将执行,因为它应该。

I found that making requests to our web role after periods on inactivity would result in a very slow request (up to 30 seconds). After that initial request, the role would perform as it should.

多的谷歌搜索后,我在四个不同的策略(如下所示)来

(一)禁用IIS闲置超时,以 RoleEntryPoint.OnStart()

After much Googling, I came across four different strategies (listed below):

public override bool OnStart()
{
    using (var server = new ServerManager())
    {
        server.ApplicationPoolDefaults.ProcessModel.IdleTimeout = TimeSpan.Zero;
        server.CommitChanges();
    }

    return base.OnStart();
}

这也要求角色在较高的水平上运行。

This also requires that the role runs at an elevated level.

public override void Run()
{
    var localuri = new Uri(string.Format("https://{0}/Help", RoleEnvironment.CurrentRoleInstance.InstanceEndpoints["HttpsIn"].IPEndpoint));

    while (true)
    {
        try
        {
            var request = (HttpWebRequest)WebRequest.Create(localuri);
            request.Method = "GET";
            var response = request.GetResponse();
        }
        catch { }
        System.Threading.Thread.Sleep(3000);
    }
}

(c)设置 preloadEnabled STARTMODE RoleEntryPoint.OnStart ()

public override void OnStart()
{
    using (var serverManager = new ServerManager())
    {
        foreach (var application in serverManager.Sites.SelectMany(x => x.Applications))
        {
            application["preloadEnabled"] = true;
        }

        foreach (var applicationPool in serverManager.ApplicationPools)
        {
            applicationPool["startMode"] = "AlwaysRunning";
        }

        serverManager.CommitChanges();
    }

    return base.OnStart();
}

(四)最后,使用天青的永远在线(编辑:!这仅仅是不幸的Azure网站)

(d) And lastly, using Azure's "Always On" ( This is only for Azure websites unfortunately!)

我应该执行哪这些策略的?

Which of these strategies should I perform?

推荐答案

我们使用一对夫妇这些答案的组合,它完美的作品很适合我们,他们是非常快的改变和测试然而,这似乎覆盖所有基地。

We use a combination of a couple of those answers and it works perfectly well for us, they're very quick to change and test however, it seems to cover all bases.

public override bool OnStart()
{
    ServicePointManager.DefaultConnectionLimit = 12;
    if(!RoleEnvironment.IsEmulated)
    {
        using(ServerManager serverManager = new ServerManager())
        {
            foreach (var app in serverManager.Sites.SelectMany(x => x.Applications))
            {
                app["preloadEnabled"] = true;
            }
            foreach (var appPool in serverManager.ApplicationPools)
            {
                    appPool.AutoStart = true;
                    appPool["startMode"] = "AlwaysRunning";
                    appPool.ProcessModel.IdleTimeout = TimeSpan.Zero;
                    appPool.Recycling.PeriodicRestart.Time = TimeSpan.Zero;
            }
            serverManager.CommitChanges();
        }
    }
    return base.OnStart();
}

这篇关于Azure的Web角色"预热"策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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