X

Using Compute Autoscaling with the Load Balancing Service

Lawrence Gabriel
Solutions Architect

This post is the final post in the four-part series on Autoscaling a load balanced web application. You can find links for the entire series at the end of this post.

In Part 1, we set up the scenario of TheSmithStore, a fictional online retailer who needs their web application to respond to variable levels of customer traffic. TheSmithStore is harnessing the scalability of Oracle Cloud Infrastructure to ensure the availability of their web application, even during unexpected traffic spikes. In Part 2, we set up the load balancer. In Part 3, we set up a custom Compute image.

In this final part, we create an Oracle Cloud Infrastructure Compute autoscaling configuration for TheSmithStore. The following diagram was introduced in Part 1, but here it highlights the instance configuration, instance pool, and autoscaling components. Note that only the relationship between autoscaling and the instance pool is depicted as directional. The autoscaling service actively modifies an instance pool. All of the other relationships are purely resource references to each other.

Before You Get Started

In this post, the Oracle Cloud Infrastructure CLI uses prepared JSON files for input. The CLI is set up with an AUTOSCALE profile for this example. The profile includes user, fingerprint, key_file, tenancy, and region in the CLI config file, and compartment-id in the oci_cli_rc file.

If you haven’t used the CLI, read the Use the CLI with Restricted Object Storage Buckets blog post or visit the CLI documentation.

In this final post in the series, we’re joining all of the earlier components of the configuration for TheSmithStore. The following resource references are required:

  • Instance configuration: Custom Image OCID from Part 3
  • Instance pool:
    • Load balancer OCID from Part 2
    • Load balancer backend set name from Part 2

Additionally, instance configurations require references to subnets and availability domains, for instance provisioning.

Autoscaling TheSmithStore

Compute autoscaling works by modifying the number of compute instances in an instance pool based on the aggregated performance metrics of the pool. Before creating an autoscaling configuration, we need to create the instance configuration and instance pool resources. In the case of TheSmithStore, we use one instance configuration that references the custom web server compute image created in Part 3 of this series.

Create the Instance Configuration

To focus more on the autoscaling part of this solution, the following JSON file contains the minimal values required to create a valid instance configuration. In addition to the image OCID created in Part 3, a compartment OCID is a required resource reference. The compartment OCID, in this case, is the compartment where you want to launch instances.

thesmithstore-instance-configuration.json

{
  "display-name": "thesmithstore-webserver",
  "instance-details": {
    "instance-type": "compute",
    "launch-details": {
      "compartment-id": "ocid1.compartment.oc1..aaaaaaaam5onfkwnvelxft5och4u323i53yjpon7wwl",
      "create-vnic-details": {
      },
      "metadata": {
        "ssh_authorized_keys": "ssh-rsa AAAAB3NzaCzh72+7QGDPgpP36F5WotZ/OYeYe1YDWmJIDjVBHCj8Q6T7Oa/uVbecoyrmr0NGesES5RXljiyYcXDioPIXSAZRMWjheeAL admin@localhost"
      },
      "shape": "VM.Standard2.1",
      "source-details": {
        "image-id": "ocid1.image.oc1.iad.aaaaaaaaas2uz4snqbk2fp2hipk3euk3sfdzidxl",
        "source-type": "image"
      }
    }
  }
}

After you have the JSON file, you run the following CLI command to create the instance configuration:

$ oci --profile AUTOSCALE compute-management instance-configuration create --instance-details file://thesmithstore-instance-configuration.json

For more information about instance configurations and instance pools, see the Enhanced Compute Instance Management on Oracle Cloud Infrastructure blog post.

Create the Instance Pool

Again, to focus more on the autoscaling part of this solution, the following JSON file contains the minimal values required to create a valid instance pool.

The two resources that need to exist before creating the instance pool for TheSmithStore are a load balancer and subnets for web server instances. The instance pool references the load balancer OCID created in Part 2 of this series. The web server instances launch in a private regional subnet, so the OCID of that subnet is referenced in the configuration. Security list rules need to be in place to allow traffic from the load balancer to the private subnet. One final thing to note is that the initial size of the pool is zero, intentionally.

Required resource references:

  • instance-configuration-id: Use the OCID output from the previous instance-configuration create command.
  • load-balancers:load-balancer-id: Use the load balancer OCID created in Part 3 of this series.
  • load-balancers:backend-set-name: Use the load balancer backend set name created in Part 3.
  • placement-configurations:availability-domain: The availability domains where instances launch. When creating an instance pool, include only availability domains that have similar compute limits. An availability domain that has reached is a resource limit could prevent an instance pool from scaling out.
  • placement-configurations:primary-subnet-id: Because we’re using a private regional subnet, we can use the same OCID for both availability domain placement configurations.

thesmithstore-instance-pool.json

{
  "display-name": "thesmithstore-webserver-pool",
  "instance-configuration-id": "ocid1.instanceconfiguration.oc1.iad.aaaaaaaarba73lx3hempves4xgsv3owdrhu73pjq",
  "load-balancers": [
    {
      "load-balancer-id": "ocid1.loadbalancer.oc1.iad.aaaaaaaaqmphpkkyvdefw5obapsijzawpckgkc5e4u2",     
      "backend-set-name": "thesmithstore-web-backend-set",
      "port": 80,
      "vnic-selection": "PrimaryVnic"
    }
  ],
  "placement-configurations": [
    {
      "availability-domain": "XXXX:US-PHOENIX-AD-1",
      "primary-subnet-id": "ocid1.subnet.oc1.iad.aaaaaaaamrpvh7fr4i7eampef7nakslftafxpqtdesya"
    },
    {
      "availability-domain": "XXXX:US-PHOENIX-AD-2",
      "primary-subnet-id": "ocid1.subnet.oc1.iad.aaaaaaaamrpvh7fr4i7eampef7nakslftafxpqtdesya"
    }
  ],
  "size": 0
}

Like the previous command, preparing the JSON file beforehand simplifies the CLI command:

$ oci --profile AUTOSCALE compute-management instance-pool create --from-json file://thesmithstore-instance-pool.json

Note: The instance pool must exist in the same compartment as the instance configuration.

Create the Autoscaling Configuration

As mentioned earlier, autoscaling works by modifying the number of compute instances in an instance pool based on the aggregated performance metrics of the pool. The autoscaling configuration for TheSmithStore is simple and starts with two compute instances. The pool scales out (add instances) when CPU utilization of the pool is above 80%, launching two instances at a time until a maximum of eight instances exists. The pool scales in (terminate instance) when CPU utilization of the pool is below 40%, terminating one instance at a time until the minimum of two is reached.

Required resource references:

  • resource:id: Use the OCID output from the previous instance-pool create command.

thesmithstore-instance-pool.json

{
  "display-name": "thesmithstore-autoscale-webserver-pool",
  "policies": [
    {
      "capacity": {
        "initial": 2,
        "max": 8,
        "min": 2
      },
      "display-name": "thesmithstore-cpu-80-40",
      "policy-type": "threshold",
      "rules": [
        {
          "action": {
            "type": "CHANGE_COUNT_BY",
            "value": 2
          },
          "display-name": "scale-out-rule",
          "metric": {
            "metric-type": "CPU_UTILIZATION",
            "threshold": {
              "operator": "GT",
              "value": 80
            }
          }
        },
        {
          "action": {
            "type": "CHANGE_COUNT_BY",
            "value": -1
          },
          "display-name": "scale-in-rule",
          "metric": {
            "metric-type": "CPU_UTILIZATION",
            "threshold": {
              "operator": "LT",
              "value": 40
            }
          }
        }
      ]
    }
  ],
  "resource": {
    "id": "ocid1.instancepool.oc1.iad.aaaaaaaawqw6t26kssqeerydb5awwquu7xgzk5",
    "type": "instancePool"
  }
}

All CLI commands allow input from a JSON file.

Note: The CLI options --generate-full-command-json-input and --generate-param-json-input are helpful in formatting the JSON input file.

$ oci --profile AUTOSCALE autoscaling configuration create --from-json file://thesmithstore-autoscale-configuration.json

To learn more about Compute autoscaling, visit the documentation or Right-Size Your Workloads with Oracle Cloud Infrastructure Autoscaling blog post.

Final Configuration

As soon as the autoscaling configuration appears in the tenancy, the instance pool size updates from 0 to 2, and two Compute instances launch. The instance pool has a SCALING status on the Instance Pool Details page in the Console.

Now that the configuration for TheSmithStore is complete, let's look back at the diagram from Part 1 and see how all of the Oracle Cloud Infrastructure components are configured:

  1. The instance pool is a backend set for the load balancer.
  2. The custom Compute instances publish metrics to the Monitoring service.
  3. The autoscaling configuration manages the instance pool based on aggregate metrics.

Wrapping Up

Load balancers, instance configurations, instance pools, and the Monitoring service have more settings than are covered by TheSmithStore scenario. If you want to revisit any post in this series or see related documentation, use the following links.

Be on the lookout for an upcoming white paper that covers all of the details of building a hyperscale web application on Oracle Cloud Infrastructure, including deploying in multiple regions, DNS traffic management, and DBaaS.

Everything discussed in this blog series is available with a trial account. If you don't have an Oracle Cloud Infrastructure account yet, go to https://www.oracle.com/cloud/free/ to sign up today.

Blog Series Links

Part 1: Autoscaling a Load Balanced Web Application

Part 2: Preparing a Load Balancer for Instance Pools and Autoscaling

Part 3: Designing Images for Compute Autoscaling

Part 4: You are here.

Be the first to comment

Comments ( 0 )
Please enter your name.Please provide a valid email address.Please enter a comment.CAPTCHA challenge response provided was incorrect. Please try again.