Exercise - Autoscaling rules
In this exercise, we look at exercises for setting up and triggering autoscaling of your sample application.
Rule exercise
In your sample Azure Spring Apps application, your application triggered a scale-out action on the customer service microservice when it was created.
The customers-service app scales out when the tomcat request count exceeds 10 sessions, per minute, on average. After the autoscale is triggered, it then scales in if the request count is less than or equal to 10 sessions per minute, on average.
View Autoscale setup in the Azure portal
- In a new web browser tab, open the Azure portal.
- From the top search box, search for Azure Spring Apps.
- From the Azure Spring Apps Overview page, select your Azure Spring Apps instance from the results.
- Select the Apps tab under Settings in the menu on the left navigation pane.
- Select the customers-service application. You should then see the application's Overview page.
- Go to the Scale-out tab under Settings in the menu on the left side of the page.
There are two options for Autoscale demand management:
- Manual scale: Maintains a fixed instance count. In the Standard tier, you can scale out to a maximum of 500 instances. This value changes the number of separate running instances of the microservice application.
- Custom autoscale: Scales on any schedule, based on any metrics.
In the Azure portal, view the presetup configuration for your application. The following figure shows a Custom autoscale configured to scale on the tomcat request count.
Viewing the finished autoscale events
In the Scale out setting screen, go to the Run history tab to see the most recent scale actions. The tab shows the change in Observed Capacity over time graphically, and a log of every autoscale action.
Trigger the scale-out action with a script
You can also trigger autoscaling manually via a web browser or a shell script.
To test the autoscale rules, we generate some load on the instances. This simulated load causes the autoscale rules to scale out and increase the number of instances. As the simulated load is then stopped, the autoscale rules scale-in and reduce the number of instances.
To allow you to trigger the autoscale, we provided a shell script in the same GIT repo you used to create your Azure Spring Apps application.
Set the instance name of your Spring Apps service, by running the following command in your https://shell.azure.com bash window. Use the same Azure spring Apps service name you used in the previous exercise:
export SPRING_APPS_SERVICE=<spring-apps-instance-name>
Next, in the bash window, run the following commands to execute transactions against your Spring Apps customers-service microservice:
cd mslearn-autoscale-java sh loadTest.sh
You should see the output of the customers-service load test that sends 100 requests to your instance.
Trigger the scale-out action manually via a web browser (Optional)
To manually trigger the scale-out condition in the autoscale setting created, the customers-service microservice must have more than 10 requests in less than one minute.
Open a new browser window and navigate to the customers-service microservice:
https://<your-spring-apps-service>-api-gateway.azuremicroservices.io/api/customer/owners
In quick succession, reload the page more than 10 times.
Viewing the scale-out action
Back in the original browser window, on the autoscale setting, select the Run history tab.
You should see a chart reflecting the instance count.
In a few minutes, the instance count should rise from 1 to 2.
Under the chart, you should have the activity log entries for each scale action taken by this autoscale setting.
Scale-in action
The scale-in condition in the autoscale setting triggers if there are fewer than or equal to 10 requests to the customers-service microservice over a period of one minute.
Ensure that no requests are being sent to your customers-service microservice and the browser window to your app/service is closed.
Observe the instance count. In a few minutes, the instance count could fall from 2 to 1 (see the following important point).
Important
Your Azure Spring Apps might not scale, because autoscale will try to estimate what the final state will be after it's scaled. This means autoscale would have to immediately scale again, if the average tomcat request count remains the same or even falls only a small amount.