ScottFoster1000
ScottFoster1000

Reputation: 617

Azure Autoscaling: Scale down after process ends on instance

I have an azure cloud service which scales instances out and in. This works fine using some app insights metrics to manage the auto-scaling rules.

The issue comes in when the scales in and azure eliminates hosts; is there a way for it to only scale in an instance once that instance is done processing its task?

Upvotes: 1

Views: 1317

Answers (3)

ScottFoster1000
ScottFoster1000

Reputation: 617

Kwill, thanks for the links/information, the top item in the second link was the best compromise.

The process work length was usually under 5 minutes and the service already had re-handling of failed processes, so after some research it was decided to track state of when the service was processing a queue item and use a while loop in the RoleEnvironment.Stopping event to delay restart and scale-in events until the process had a chance to finish.

App Insights was used to track custom events during the on stopping event to track how often it completes vs restarts during the delay cycles.

Upvotes: 0

Simon Bourdeau
Simon Bourdeau

Reputation: 449

Another solution but this one breaks an assumption that we are using Azure cloud service; if you use app services instead of the cloud service you will be able to setup auto scaling on the app service plan effectively taking care of the instance drop you are experiencing.

This is an infrastructure change so it's not a two click thing but I believe app services are better suited in many situations including this one.

You can look at some pros and cons but if your product is traffic managed this switch will not be painful.

Upvotes: 0

kwill
kwill

Reputation: 10998

There is no way to do this automatically. Azure will always scale in the highest number instance.

The ideal solution is to make the work idempotent and chunked so that if an instance that was doing some set of work is interrupted (scaling in, VM reboot, power loss, etc), then another instance can pick up the work where it left off. This lets you recover from a lot of possible scenarios such as power loss, instead of just trying to design something specific for scale in.

Having said that, you can manually create a scaling solution that only removes instances that are not doing work, but doing so will require a fair bit of code on your part. Essentially you will use a signaling mechanism running in each instance that will let some external service (a Logic app or WebJob or something like that) know when an instance is free or busy, and that external service can delete the free instances using the Delete Role Instances API (https://learn.microsoft.com/en-us/rest/api/compute/cloudservices/rest-delete-role-instances).

For more discussion on this topic see:

Upvotes: 1

Related Questions