Customers want their cloud to easily right size their compute fleet to handle the current application load and only pay for the compute resources they need at any given time. To address this need, Oracle Cloud Infrastructure has released autoscaling for the Compute service. Autoscaling leverages Compute instance pools and Oracle Cloud Infrastructure Monitoring. Instance pools let you pool VM instances together and keep all VM instances in your pool healthy and running. Monitoring lets you capture average CPU and memory utilization metrics from your pool. With autoscaling, you can now create and autoscaling config with policies and rules that will launch or terminate instances if thresholds are exceeded on the metrics coming from your pool of VM instances. Autoscaling is a free-to-use feature in Compute.
You can use autoscaling to scale web front-end, middleware, and backend workload tiers dynamically. Autoscaling can reduce your DevOps load for adding and removing instances manually. You can also save infrastructure costs with on-demand scaling of instances, instead of pre-provisioning instances for your peak demand.
The autoscaling configuration is used to control scaling actions on an Instance pool. We allow one autoscaling configuration per instance pool. Each autoscaling configuration defines a policy and contains two rules.
The autoscaling policy defines the minimum and maximum number of instances to scale to and the initial size of the instance pool. You also need to define the policy type, currently the only supported policy type is Threshold. The policy also defines a cooldown period for waiting before the next scaling event. You can set only one autoscaling policy in an autoscaling configuration.
Each autoscaling policy contains an autoscaling rule. An autoscaling rule defines which metric to use for scaling and the thresholds for scaling (either in or out). Currently you must use the same metric for scaling in and scaling out. The supported metrics are CPU_UTILIZATION and MEMORY_UTILIZATION. You also define the count of instances to scale-in and scale-out with each scaling action. You define one rule for scaling-in and one rule for scaling out.
Before you can set an autoscaling policy on an instance pool, you must first create the instance pool. For instructions, see the instance pools blog post. If you have an existing pool, you can use the CLI to create an autoscaling configuration for it by using the following command:
./oci autoscaling auto-scaling-configuration create --policies file://policies.json --resource instancePool.json --displayName MyTestAutoScalingConfiguration --is-enabled true
The following figure shows example policy.json and instancePool.json files.
The SDK and CLI is being provided to customers who are part of the autoscaling “Limited Availability” program and will be made public when autoscaling is launched.
The following example shows how to stress your CPU and trigger autoscaling. We started with the information in the instance pools blog post but made the following changes:
· We used a VM.Standard2.1 instance type with the latest Oracle Linux image.
· We passed in the following cloud-init script as a launch parameter to the instance:
- [sudo, yum, install, stress, -y]
- [stress, -c, 2]
The stress application launches two threads that consume 100 percent of the single CPU core on the VM.Standard2.1 instance.
· We used the newly launched instance to generate the instance configuration and then launch an instance pool of size 1 and select which availability domains to use. Note that you should ensure that you have available limits to launch new instances in the pool.
Then we performed the following steps:
1. On the Instance Pools Details page, click Create Auto Scaling Configuration.
2. In the Create Auto Scaling Configuration dialog box, enter the configuration details. For this example, we chose to scale on CPU metrics, set the scale-out rule threshold to 90 percent, set the scale-in threshold to 70 percent, and set the max pool size to 6. We already confirmed that we have enough limit to support launching an additional 6 instances.
3. Click Create. The configuration is set on the pool, and autoscaling will evaluate scaling actions on the pool every 300 seconds.
Optionally, you can navigate to the Monitoring console, select the new pool that you have created, and see the CPU metrics emit and get tracked. To monitor the pool from the monitoring console, edit your Query select the Metric Namespace as OCI-computeagent, select CpuUtilization for the Metric Name, select instancePoolid for the Dimension Name, then select your instancepool OCID in the Dimension value and select update chart to display metrics from the Instances in your pool.
You will then see metrics for all the instances in your pool. You can also choose to aggregate the metrics.
Please be sure to delete your autoscaling config and terminate your instance pool after this tutorial to avoid being charged.