Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I restart instances on the local Azure Emulator?

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,

like image 941
Jonas Stawski Avatar asked Aug 24 '12 15:08

Jonas Stawski


1 Answers

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.

like image 183
Sandrino Di Mattia Avatar answered Oct 10 '22 23:10

Sandrino Di Mattia