I got a Cloud Service deployment with 4 worker roles, one of which got auto-scaling enabled. As soon as auto-scaling occurs, all instances of all roles are recycling.
Ideally, I'd like to stop the roles from recycling or at least terminate the work of all other roles in a controlled way.
I found out, that you can react to the RoleEnvironment.Changing event and cancel it to request a graceful shutdown (i.e. make OnStop being called). However, by adding tracing output to the Changing event handler, I noticed that the Changing event was obviously not even fired, so the cancellation was not being registered either.
private void RoleEnvironmentChanging(object sender, RoleEnvironmentChangingEventArgs e)
{
// This tracing output does not show up in the logs table.
Trace.TraceInformation("RoleEnvironmentChanging event fired.");
if ((e.Changes.Any(change => change is RoleEnvironmentConfigurationSettingChange)))
{
// This one neither.
Trace.TraceInformation("One of the changes is a RoleEnvironmentConfigurationSettingChange. Cancelling..");
e.Cancel = true;
}
if ((e.Changes.Any(change => change is RoleEnvironmentTopologyChange)))
{
// This one neither.
Trace.TraceInformation("One of the changes is a RoleEnvironmentTopologyChange. Cancelling.");
e.Cancel = true;
}
}
public override bool OnStart()
{
// Hook up to the changing event to prevent roles from unnecessarily restarting.
RoleEnvironment.Changing += RoleEnvironmentChanging;
// Set the maximum number of concurrent connections
ServicePointManager.DefaultConnectionLimit = 12;
bool result = base.OnStart();
return result;
}
Also adding an internal endpoint to each role did not bring the change. Here the configuration from the .csdef:
<WorkerRole name="MyRole" vmsize="Medium">
[...ConfigurationSettings...]
<Endpoints>
<InternalEndpoint name="Endpoint1" protocol="http" />
</Endpoints>
</WorkerRole>
Also changing the protocol to "any" wasn't successful.
How can I stop my role instances from recycling after a scaling operation?
EDIT:
» Included code snippets
» Fixed typos