How do I restart instances on the local Azure Emulator?
Asked Answered
I

2

8

I'm working on a worker role failover solution and I need to be able to test and debug the failover mechanism by shutting down or restarting instances as well as creating new ones.

How do I restart or shutdown specific instances on the local Azure Emulator? I'm using the 1.7 SDK

Thanks,

Imogeneimojean answered 24/8, 2012 at 15:55 Comment(0)
S
10

I have to disagree with David's answer here. There are a few things you can do to shut down instances or create new instances.

Shutting down / Killing instances

When you run your application in the emulator it starts 1 Web Role (WaIISHost.exe) / Worker Role (WaWorkerHost.exe) process per instance:

enter image description here

When you kill one of these processes it's as if you killed an instance. After switching back to the emulator you'll see that the icon of that specific instance you killed changed color and the logs will show that the state of the instance is Unknown/Destroyed:

enter image description here

When the debugger is attached you'll see this happen and the instance will never restart, allowing you to test scenarios where you suddenly loose one or more instances. If the debugger is not attached this will all happen very fast and the instance will restart right away (in Visual Studio you can choose to start without debugging).

Increasing or decreasing the number of instances

Using csrun.exe (usually located in C:\Program Files\Microsoft SDKs\Windows Azure\Emulator) you can update the configuration of your service in the emulator, including the number of instances. Let's say I want to add 6 instances to the 4 instances I have at the moment.

I open the ServiceConfiguration.cscfg file located in my Debug folder of your Azure project (..\Some\Path\MultipleInstancesDemo\MultipleInstancesDemo\bin\Debug) and change the number of instances to 10:

<ServiceConfiguration serviceName="MultipleInstancesDemo" xmlns="http://schemas.microsoft.com/ServiceHosting/2008/10/ServiceConfiguration" osFamily="1" osVersion="*" schemaVersion="2012-05.1.7">
  <Role name="MyWebRole">
    <Instances count="10" />
    <ConfigurationSettings>
      <Setting name="Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString" value="UseDevelopmentStorage=true" />
    </ConfigurationSettings>
  </Role>
</ServiceConfiguration>

Then it's possible to push this to the emulator by providing csrun.exe with the deployment ID and the path to the configuration file. You'll find the deployment ID in the emulator. In the previous screenshot you'll see deployment17(20), this means that the deployment ID is 20. This is how you would call csrun.exe: csrun /update:20;"..\Some\Path\MultipleInstancesDemo\MultipleInstancesDemo\bin\Debug\SeviceConfiguration.cscfg"

After a few seconds you'll see the new instances in the emulator:

enter image description here

Note!: Also here it seems that this only works when you start the project without debugging.

Sandstorm answered 24/8, 2012 at 20:26 Comment(1)
Great answer. Next version should allows to easily right click on the instance and perform actions like restart it or shut it down. That way we can test for unexpected events such as hardware failures or update patching.Imogeneimojean
P
0

You cannot shut down specific instances; you can only scale down the total number of running instances.

If you want to restart a running instance, you can call:

RoleEnvironment.RequestRecycle();
Philo answered 24/8, 2012 at 16:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.