简体   繁体   English

如何在本地Azure模拟器上重新启动实例?

[英]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? 如何在本地Azure模拟器上重新启动或关闭特定实例? I'm using the 1.7 SDK 我正在使用1.7 SDK

Thanks, 谢谢,

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: 在模拟器中运行应用程序时,它会为每个实例启动1个Web角色(WaIISHost.exe)/辅助角色(WaWorkerHost.exe)进程:

在此输入图像描述

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: 切换回模拟器后,您将看到您杀死的特定实例的图标改变了颜色,日志将显示实例的状态为Unknown / Destroyed:

在此输入图像描述

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). 如果没有附加调试器,这将全部发生得非常快,实例将立即重启(在Visual Studio中,您可以选择在没有调试的情况下启动)。

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. 使用csrun.exe (通常位于C:\\ Program Files \\ Microsoft SDKs \\ Windows Azure \\ Emulator中 ),您可以在模拟器中更新服务的配置,包括实例数。 Let's say I want to add 6 instances to the 4 instances I have at the moment. 假设我想在我目前的4个实例中添加6个实例。

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: 我打开位于Azure项目的Debug文件夹中的ServiceConfiguration.cscfg文件(.. \\ Some \\ Path \\ MultipleInstancesDemo \\ MultipleInstancesDemo \\ bin \\ Debug)并将实例数更改为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. 然后,通过向csrun.exe提供部署ID和配置文件的路径,可以将其推送到模拟器。 You'll find the deployment ID in the emulator. 您将在模拟器中找到部署ID。 In the previous screenshot you'll see deployment17(20) , this means that the deployment ID is 20 . 在上一个屏幕截图中,您将看到deployment17(20) ,这意味着部署ID为20 This is how you would call csrun.exe: csrun /update:20;"..\\Some\\Path\\MultipleInstancesDemo\\MultipleInstancesDemo\\bin\\Debug\\SeviceConfiguration.cscfg" 这就是你如何调用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: 几秒钟后,您将在模拟器中看到新实例:

在此输入图像描述

Note!: Also here it seems that this only works when you start the project without debugging. 注意!:此处似乎只有在没有调试的情况下启动项目时才会起作用。

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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何连接到本地计算机上的Azure Compute模拟器 - How do I connect to a Azure Compute Emulator on my local machine 如何在Azure中监视Webrole实例 - How do I monitor webrole instances in Azure 如何配置在Compute Emulator中运行的Azure应用程序? - How do I profile an Azure app running in the Compute Emulator? 如何设置Azure存储模拟器以侦听所有接口? - How do I setup the Azure Storage Emulator to listen on all interfaces? 如何使用HTTP将CORS规则添加到Azure存储模拟器? - How do i add a CORS rule to the Azure Storage Emulator with HTTP? 如何连接到用于MongoDB的Azure CosmosDB仿真器? - How do I connect to the Azure CosmosDB Emulator for MongoDB? 本地调试azure仿真器 - Local debugging azure emulator 如何针对我的本地 CosmosDB 模拟器运行 Azure CLI 命令? - How can I run Azure CLI commands against my local CosmosDB Emulator? 如何使用Visual Studio但不使用Azure模拟器将现有的Web应用程序项目部署到Azure? - How do I deploy an existing web app project to Azure using Visual Studio but no Azure Emulator? 如何使用自定义端口配置 Azure 角色以连接到 Windows Azure 存储仿真器? - How do I configure an Azure role to connect to Windows Azure Storage Emulator using custom ports?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM