veda
veda

Reputation: 6594

Windows Azure: Can I change the instances count of worker role while the application is running on the cloud

Can I be able to change the instances count of a worker role while the application is running.

I have created an application which executes a sequence of code parallely a number of times depending on the user's query. Say, If user request the result to be very accurate, then I will have to run the code for 1000 or more times parallely on different datasets. If user doesn't request the result to be accurate, then I will run the code for 5 times parallely. This sequence of code is executed by a worker role. I will start the my application with the instances count of a worker role to be 5. If the user request the result to be very accurate, then can I increment the instances count of the worker role to say 20. Once the request is finished, I will set the instances count back to 5.

Can I do this. How can I do this. Will the application gets restarted if I do this.

Upvotes: 3

Views: 1395

Answers (3)

Dragos Durlut
Dragos Durlut

Reputation: 8098

You could also use the information from this: http://blog.maartenballiauw.be/post/2011/03/21/Windows-Azure-and-scaling-how-(NET).aspx

Mainly:

var deployment = GetWindowsAzureDeployment();

            string configurationXml = ServiceManagementHelper.DecodeFromBase64String(deployment.Configuration);

            Log.Info("Updating configuration value...");

            var serviceConfiguration = XDocument.Parse(configurationXml);

            serviceConfiguration
                    .Descendants()
                    .Single(d => d.Name.LocalName == "Role" && d.Attributes().Single(a => a.Name.LocalName == "name").Value == RoleName)
                    .Elements()
                    .Single(e => e.Name.LocalName == "Instances")
                    .Attributes()
                    .Single(a => a.Name.LocalName == "count").Value = newInstanceCount.ToString();

            var changeConfigurationInput = new ChangeConfigurationInput();
            changeConfigurationInput.Configuration = ServiceManagementHelper.EncodeToBase64String(serviceConfiguration.ToString(SaveOptions.DisableFormatting));

            Log.Info("Uploading new configuration...");

            ManagementClient.ChangeConfigurationBySlot(SubscriptionId, ServiceName, Slot, changeConfigurationInput);

            Log.Info("Finished uploading new configuration.");

Upvotes: 0

Grigori Melnik
Grigori Melnik

Reputation: 4107

Yes, you can also configure the Autoscaling Application Block (Wasabi) to do that for you. For more info, see this reponse and http://aka.ms/autoscaling:

Upvotes: 1

Rinat Abdullin
Rinat Abdullin

Reputation: 23552

Yes, you can do this. Windows Azure exposes management API to perform tasks as provisioning and deprovisioning additional worker roles.

You could check out Auto-scaling interfaces of Lokad.Cloud project: http://code.google.com/p/lokad-cloud/wiki/AutoScaling

Within a QueueService or a ScheduledService, you can access the property CloudService.Providers.Provisioning which will grant you a programmatic access to cloud fabric in order to adjust the number of workers running for your application.

Upvotes: 3

Related Questions