Azure的云服务:在缩放网站(Web角色)实例临危请求之前IIS已准备就绪 [英] Azure Cloud Service : Scaled in web site (web role) instance recieves requests before iis is ready

查看:180
本文介绍了Azure的云服务:在缩放网站(Web角色)实例临危请求之前IIS已准备就绪的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

说明

我得到了这是一个网站,云服务托管Web角色。
有迹象表明,我们有一个自定义监视(辅助角色),这将定期缩放或向外扩展取决于predicted负荷曲线处理predictible负荷尖峰。
这部分工作。

问题

在网站的新实例安装了监控,我们只是要求将达到新的实例之前,新的实例是完全加载用户的情况。它导致了在网络浏览器的不可访问的网站空白页。鉴于我们典型的目标客户是非常不利的。
当测试器大致在过程的规模时连接(首次)到网站这种情况发生。

难道我的问题是,有没有办法来确保Web角色完全加载IIS7,开始了apppools并完成了所有的网站预热过程中的任何请求定向到它之前?
或者在更一般的方式,我们可以manualy决定至极实例可用到负载平衡器?我的意思是,我假设有一个以上的云服务automaticaly分配请求一个内置的负载均衡。

先谢谢了。


解决方案

请参阅http://blogs.msdn.com/b/kwill/archive/2012/09/19/role-instance-restarts-due-to-os-upgrades.aspx,特别是常见问题#5和相关的code。


  

如果您的网站需要几分钟的时间预热(标准
  precompilation和模块加载,或回暖的IIS / ASP.NET热身
  高速缓存或其他应用程序特定的任务),那么你的客户可能会遇到
  停电或随机超时。经过角色实例重新启动,你的
  的OnStart code完成那么你的角色实例将在被放回
  负载均衡器和旋转将开始接收传入的请求。如果
  你的网站还在升温那么所有这些传入请求
  将排队和超时。如果你只有你的网页的两个实例
  然后角色IN_0,这仍然是升温,将采取的100%
  而IN_1传入的请求被重新启动客户操作系统
  更新。这可能会导致你的服务的完整停运,直到你
  网站完成上两个实例热身。建议
  让您的实例的OnStart,这将保持在繁忙状态
  其中,它将不会接收从负载平衡器传入请求,直到
  您的热身完毕。您可以使用下面的code完成
  这样的:


 公共类WebRole:RoleEntryPoint
{
    公众覆盖布尔的OnStart()
    {
        //有关处理配置更改信息
        //看到http://go.microsoft.com/fwlink/?LinkId=166357 MSDN主题。
        IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
        串IP = NULL;
        的foreach(在ipEntry.AddressList ip地址ip地址)
        {
            如果(ipaddress.AddressFamily.ToString()==网间)
            {
                IP = ipaddress.ToString();
            }
        }        字符串urlToPing =HTTP://+ IP;
        HttpWebRequest的REQ = HttpWebRequest.Create(urlToPing)为HttpWebRequest的;
        WebResponse类RESP = req.GetResponse();
        返回base.OnStart();
    }
}

Description

I got a web role hosted in a cloud service that is a web site. There are predictible load spikes that we handle with a custom monitoring (a worker role) that will periodically scale in or scale out depending on the predicted load profile. That part is working.

Issue

After a new instance of the web site is mounted by the monitoring, we just had a case of a user whose request reach that new instance before the new instance was fully load. It resulted in an unaccessible web site blank page on the web browser. Given our typical target client it is very bad. This happen when a tester connected (for the first time) to the web site approximately during the scale in process.

Do my question is, is there a way to ensure that a web role has fully loaded IIS7, started the apppools and finished all the web site warmup process before any request is directed to it? Or in a more general way, can we manualy decide wich instance is available to the load balancer ? by that I mean that I assume there is a built-in load balancer over a cloud service automaticaly distributing requests.

Thanks in advance.

解决方案

See http://blogs.msdn.com/b/kwill/archive/2012/09/19/role-instance-restarts-due-to-os-upgrades.aspx, specifically the Common Issues #5 and associated code.

If your website takes several minutes to warmup (either standard IIS/ASP.NET warmup of precompilation and module loading, or warming up a cache or other app specific tasks) then your clients may experience an outage or random timeouts. After a role instance restarts and your OnStart code completes then your role instance will be put back in the load balancer rotation and will begin receiving incoming requests. If your website is still warming up then all of those incoming requests will queue up and time out. If you only have 2 instances of your web role then IN_0, which is still warming up, will be taking 100% of the incoming requests while IN_1 is being restarted for the Guest OS update. This can lead to a complete outage of your service until your website is finished warming up on both instances. It is recommended to keep your instance in OnStart, which will keep it in the Busy state where it won't receive incoming requests from the load balancer, until your warmup is complete. You can use the following code to accomplish this:

public class WebRole : RoleEntryPoint
{
    public override bool OnStart()
    {
        // For information on handling configuration changes
        // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
        IPHostEntry ipEntry = Dns.GetHostEntry(Dns.GetHostName());
        string ip = null;
        foreach (IPAddress ipaddress in ipEntry.AddressList)
        {
            if (ipaddress.AddressFamily.ToString() == "InterNetwork")
            {
                ip = ipaddress.ToString();
            }
        }

        string urlToPing = "http://" + ip;
        HttpWebRequest req = HttpWebRequest.Create(urlToPing) as HttpWebRequest;
        WebResponse resp = req.GetResponse();
        return base.OnStart();
    }
}

这篇关于Azure的云服务:在缩放网站(Web角色)实例临危请求之前IIS已准备就绪的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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