Using Cloud Foundry App Autoscaler with IBM® Cloud Private Cloud Foundry

You can integrate your IBM® Cloud Private Cloud Foundry application with App Autoscaler.

App Autoscaler is a marketplace service that you can use to control the cost of running apps while you maintain app performance.

To balance app performance and cost, space developers can use App Autoscaler to perform the following tasks:

App Autoscaler uses five releases:

The cfp-cf-release and unbound releases are provided with IBM Cloud Private Cloud Foundry. You must download and move the postgres and cf-routing-release releases into directories on the inception container. The App Autoscaler release is included in the app-autoscaler-release/src directory.

Note: These instructions assume that you do not already have a database set up for autoscaling. If you already have a database set up, make sure that you configure the manifests/db-stub-override.yml file to map the addresses and tables to the correct database. In addition, make sure that your default_db value in the manifests/property-overrides.yml file is linked to the correct database.

Prerequisites for installing App Autoscaler

  1. Install the Bosh and IBM Cloud Private Cloud Foundry command line interfaces. For more information on these command line interfaces, see Command line interfaces for IBM® Cloud Private Cloud Foundry.
  2. Ensure that you have internet access when you make the extension so that you can download the postgres and cf-routing-release releases.
  3. Configure the static IP address for your database (customization is required to support multiple databases).
    1. Determine the static IP addresses to use.
    2. Open the cloud-config.yml and add the static IP addresses to it.
    3. Adjust the networks.subnets.reserved array to include the new static IP address, as well as seven additional addresses for the other autoscale jobs that are required. A total of eight IP addresses are required.
    4. Redeploy the cloud-config.yml file to include the updated IP addresses by running the following command:
      bosh -e ENVIRONMENT_NAME update-cloud-config /data/CloudFoundry/cloud-config.yml
      

Installing App Autoscaler

You deploy the App Autoscaler through the Platform Configuration Manager as an extension. For more information about extensions, see Using extensions in IBM® Cloud Private Cloud Foundry

  1. Clone the Git repository that contains the App Autoscaler source code in the inception container host. Run the following command to clone the Git repository:

    git clone https://github.com/jnpacker/app-autoscaler-release.git
    
  2. From a terminal, change to the app-autoscaler-release folder in the cloned files:

    cd app-autoscaler-release
    
  3. Review the manifest/property-override.yml file and customize all required property values. Confirm that the ports, user names, and passwords are correct. Review and update the following properties:

    • cf_properties.api
    • default_db.address
    • service_broker_properties.uri
    • service_broker_properties.port
    • service_broker_properties.username
    • service_broker_properties.password
    • default_db.password
  4. Create the extension by running the following command in your terminal:

    make extension
    
  5. Copy the app-autoscaler-extension.zip file to the server that is running the installation container for IBM Cloud Private Cloud Foundry.

  6. Open an interactive bash shell on the server.
  7. From the bash shell, register the extension. You must be in the same directory as install.sh. Register the extension by running the following command:

    ./cm extension -e app-autoscaler register -p ./app-autoscaler-extension.zip
    
  8. From the bash shell, deploy the extension by running the following command:

    ./cm extension -e app-autoscaler deploy
    
  9. Confirm that all the steps have the SUCCEEDED status. Run the following command and review the output:

    ./cm states -e app-autoscaler
    

Registering App Autoscaler

  1. Register the App Autoscaler service. Log in to {{site.data.keyword.cf_notm}} as the admin user and run the following command:

    cf create-service-broker autoscaler <brokerUserName> <brokerPassword> <brokerURL>
    

    In this command:

    • The <brokerUserName> is the user name to authenticate with the service broker.
    • The <brokerPassword> is the password to authenticate with the service broker.
    • The <brokerURL> is the URL of the service broker.

    The default <brokerUserName> value is username, the default <brokerPassword> value is password, and the default <brokerURL> value is http://autoscalerservicebroker.YOUR_DOMAIN.

    If you used the default values, run the following command:

    cf create-service-broker autoscaler username password http://autoscalerservicebroker.YOUR_DOMAIN
    
  2. To use the service to auto-scale your applications, log in to {{site.data.keyword.cf_notm}} as the admin user, and enable access to the service for your orgs. Run the following command to enable service access to all or specific orgs.

    cf enable-service-access autoscaler -o <org>
    

    Where <org> is the org or orgs whose members can use the service.

  3. As a user with the space developer role, create the service instance.

    cf create-service autoscaler  autoscaler-free-plan  <service_instance_name>
    

    Where <service_instance_name> is the name that you assign to the service instance.

Creating the autoscaling policy.

  1. Create the autoscaling policy file. The autoscaling policy file is a JSON formatted file that contains the parameters that define the autoscaling rules. The JSON file resembles the following code:

    {
     "instance_min_count": 1,
     "instance_max_count": 5,
     "scaling_rules": [{
       "metric_type": "memoryutil",
       "stat_window_secs": 300,
       "breach_duration_secs": 600,
       "threshold": 30,
       "operator": "<",
       "cool_down_secs": 300,
       "adjustment": "-1"
     }, {
       "metric_type": "memoryutil",
       "stat_window_secs": 300,
       "breach_duration_secs": 600,
       "threshold": 55,
       "operator": ">=",
       "cool_down_secs": 300,
       "adjustment": "+1"
     }],
     "schedules": {
       "timezone": "America/Los_Angeles",
       "recurring_schedule": [{
         "start_time": "01:00",
         "end_time": "23:00",
         "days_of_week": [
           1,
           2,
           3,
           4,
           5,
           6,
           7
         ],
         "instance_min_count": 1,
         "instance_max_count": 5,
         "initial_min_instance_count": 5
       }],
       "specific_date": [{
         "start_date_time": "2016-06-02T10:00",
         "end_date_time": "2018-06-15T13:59",
         "instance_min_count": 1,
         "instance_max_count": 4,
         "initial_min_instance_count": 1
       }]
     }
    }
    

    This file contains several sections. In it, you define the instance_min_count value, which is the minimum number of instances, and the instance_max_count, which is the maximum number of instances. In the scaling_rules section, you can define multiple scaling criteria. In the schedules section, you can define recurring schedules based on the day of the week or single schedules for a particular day or time range. While you can provide multiple scaling rules or schedules, each of these definitions must contain all of the specified parameters. The following table provides more information about these parameters:

Table 1. Autoscaling policy parameters
Parameter Description Value
instance_min_count The minimum number of application instances. Positive integer
instance_max_count The maximum number of application instances. Positive integer
scaling_rules The set of rules that define when new applications are created or removed. Array
metric_type
  • memoryused
  • memoryutil
  • responsetime
  • throughput
stat_window_secs Positive integer (in seconds)
breach_duration_secs Positive integer (in seconds)
threshold The limit for when to change the number of application instances. Positive integer
operator
  • <
  • >
cool_down_secs Positive integer (in seconds)
adjustment The amount of change to the number of instances. You can increase and decrease by a number of instances or a percent of instances.
  • Integers from -99 to -1 and 1 to 99
  • Positive or negative percentage
schedules The set of rules that define how new applications are created or removed at different times. Array
timezone The time zone of the server.
recurring_schedule
start_time The time of day that the rules start to be applied. 24-hour time, such as 01:00
end_time The time of day that the rules are no longer applied. 24-hour time, such as 023:00
days_of_week The days of the week to which the schedule applies. Here, Sunday is represented as 1. 1-7
initial_min_instance_count The minimum number of instances at the start of the time period. Positive integer
specific_date The autoscaling policy to apply for a specific time range. Array
start_date_time The time to start to apply this policy. Date and time in the following format: <four_digit_year>-<two_digit_month>-<two_digit_day>T<hour>:<minute>, eg 2018-06-15T13:59
end_date_time The time to end this policy. Date and time in the following format: <four_digit_year>-<two_digit_month>-<two_digit_day>T<hour>:<minute>, eg 2018-06-15T13:59
  1. As a user with the space developer role, bind an existing application to the service instance.

    cf bind-service <app_name> <service_instance_name> -c <policy>
    

    In this command:

    • The <app_name> is the name of the application to autoscale.
    • The <service_instance_name> is the name of the service instance for the App Autoscaler.
    • The <policy> is the path to the policy file to apply, such as /data/extension/custom/app-autoscaler/example/example-policy.json.

    Now, your service is bound to your application, and it automatically scales to the requirements that are defined in the policy.json file.

Removing the service

Complete the following steps to remove the service.

  1. Log in to {{site.data.keyword.cf_notm}} as the admin user.
  2. Run the following commands:
    cf purge-service-offering autoscaler ; \
    cf delete-service-broker autoscaler
    

Troubleshooting the App Autoscaler

Failure in creating a release

Symptoms

When you deploy the App Autoscaler, the following error message is displayed:

Building a release from directory '/data/extensions/custom/app-autoscaler':
  Compressing staging directory:
    Shelling out to tar:
      Running command: 'tar czf /data/home/.bosh/tmp/bosh-platform-disk-TarballCompressor-CompressSpecificFilesInDir114079115 -C /data/home/.bosh/tmp/bosh-resource-archive204470236 .', stdout: '', stderr: '
gzip: stdout: No space left on device
':
        signal: broken pipe

Exit code 1
state:Create Release

Causes

Your /data/home/.bosh/tmp directory is full.

Resolving the problem

Clear the BOSH temporary directory by running the following command:

rm -rf /data/home/.bosh/tmp

Failure to access a URL during release creation

Symptoms

When you deploy the App Autoscaler, the following error message is displayed: org.apache.maven.wagon.providers.http.httpclient.impl.execchain.RetryExec execute INFO: Retrying request to {s}->https://repo.spring.io:443

Causes

The inception container has trouble connecting to some secure repositories.

Resolving the problem

  1. Open the pom.xml file in the /data/extensions/custom/app-autoscaler/src/app-autoscaler/scheduler/ folder.
  2. Change all https references to http.
  3. Run the deployment command again:
    /opt/ibm/cloud/bin/cm extension -e app-autoscaler deploy