The lifecycle of Windows Azure Cloud Service role

Source: Internet
Author: User
Tags hosting

Windows Azure Platform Family of articles Catalog

In the previous chapter, we mentioned that Windows Azure calls the OnStart () method and the Run () method of the role instance in turn.

In this section we will take a closer look at the life cycle of role. First, let's go behind the scenes and see how a role instance is posted to the virtual machine and started up.

  

Role the process of deploying and running on a virtual machine

  The following is a brief procedure for the release and launch of Role instances (roles Instance).

    1. Windows Azure chooses a host server with enough CPU cores in the server pool, or starts a new host server that meets the requirements
    2. Windows Azure copies the cloud service pack and configuration files to the host server. A hosting agent (host agent) on the host server initiates the virtual operating system.
    3. There is an agent named Waappagent on the virtual operating system. This agent is responsible for configuring the virtual operating system and initiating a process called wahostbootstrapper.
    4. If a startup task is defined on the role, Wahostbootstrapper runs these startup tasks and waits for all startup tasks marked as simple to execute correctly
    5. If the role is a Web role (web roles), Wahostbootstrapper starts iisconfigurator to configure IIS
    6. If the role is a worker role, Wahostbootstrapper starts a process named Waworkerhost, and if the role is a web role, Wahostbootstrapper initiates a process called Waiishost
    7. In the above process, load the assembly of the role and search for its implemented Roleentrypoint subclass
    8. Call the OnStart () method
    9. Call the Run () method. At the same time, the instance is marked as "ready" and added to the load balancer
    10. If the run () method exits, the OnStop () method is called. Waworkerhost/waiishost End Run, instance restart
    11. Wahostbootstrapper start cycle monitoring of the running state of the instance

Web role does not necessarily need to implement the Roleentrypoint class, because Web role is ultimately deployed on IIS and is the request of IIS to accept and forward users.

That's why if we remove WebRole.cs from a Web project, it doesn't affect the reason why the site is running.

However, if your web role implements the Roleentrypoint class, you want to make sure that the run () method does not exit or the instance restarts.

  

Status of Role instances (roles Instance)

  Role instance can be in a different state: Busy or ready.

The allocation of load balancing tasks is only available when role is in the ready state.

If you want to temporarily change the state of role instance in your code, you can respond to Statuscheck (state check) events defined by the Roleenvironment class. The instance is marked as busy by the Setbusy () method Roleinstancestatuscheckeventargs in the event arguments. This way, the load balancer does not assign the task to the current instance until the next Wahostbootstrapper checks the status of the instance.

If your role Instance code exits the Run () method while it is running, or if an unhandled exception (Unhandledexceptions) is thrown, Wahostbootstrapper will restart your role Instance. This mechanism of automatic recovery can help improve the usability of the system. Of course, during a reboot, this instance cannot be accepted by the user in a non-ready state. If wahostbootstrapper itself crashes or the virtual machine goes down, Windows Azure restarts the virtual machine and role Instance. If the hosting server is down, Windows Azure will redeploy role instance to a healthy server after several recovery retries.

During Windows Azure shutdown role instance, the stopping event is triggered and the OnStop () method of the role is called. Here you can implement the processing that is required during the instance shutdown process, such as releasing the resources used by role.

Finally, if you want to force a restart of your instance, you can use the Roleenvironment.requestrecycle () method to notify Windows Azure to restart the instance.

  

The lifecycle of Windows Azure Cloud Service role

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.