问题
Suppose I have an Azure role with three instances running. I ask Azure to change the role count to two either by Management Portal or via Management API.
How will Azure decide which role to take down?
回答1:
As British Developer mentioned, the Windows Azure Fabric Controller decides which instances to shut down. You cannot control this process. I don't think it is always the last number, because I am not sure whether the fabric controller does not rename the instances after shutting down. So even if it shuts down IN_1, at the end of the process we will still have IN_0 and IN_1, instated of IN_0 and IN_2 for example.
You can use the RoleEnvironment.Stopping event to handle the proper stopping (clean shutdown) of your Instance. This event is being raised after the VM was taken out of Load Balancer rotation and before the OnStop Method of your RoleEntryPoint class being called.
I am not sure where I noted, but I know that there is a hard time limit in which you have to complete your cleaning, i.e. I think the Instance will be shutdown after 5 minutes of waiting the OnStop or Stopping handler (I can't remember exactly, but the fabrci controller will not wait forever for you to clean up).
回答2:
It will usually be the last one to be spun up. So you have IN_0 IN_1 and IN_3. I've only ever see IN_3 go down when you remove one so that seems to be the one.
However, this is not documented anywhere by Microsoft so this isn't guaranteed to be the one that goes down... just seems to be in practice.
来源:https://stackoverflow.com/questions/9030706/which-instances-are-stopped-when-i-scale-my-azure-role-down