cloudfoundry-samples/cf-autoscaler

Name: cf-autoscaler

Owner: Cloud Foundry Sample Applications

Description: Demonstration of autoscaling workers in a producer-consumer scenario on Cloud Foundry

Created: 2013-09-17 06:23:44.0

Updated: 2017-11-25 00:02:22.0

Pushed: 2014-07-07 14:34:23.0

Homepage: null

Size: 563

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Cloud Foundry Autoscaler

This project demonstrates the autoscaling of worker processes in a tradtional producer-consumer setting using RabbitMQ as the message queue. Workers are artifically throttled to create a queuing scenario.

Running on Pivotal Web Services

This section will assume that you have a Pivotal Web Services account. If not, create one at http://console.run.pivotal.io/register.

Building

The autoscaler component depends on the Cloud Foundry Java Client Library (https://github.com/cloudfoundry/cf-java-client/tree/master/cloudfoundry-client-lib). The cf-java-client currently depends on Spring 3.2. The cf-autoscaler applications are written using Spring 4.0. A branch of cf-java-client that works with Spring 4.0 has been created. First we'll need to build that from source.

  1. git clone git@github.com:cloudfoundry/cf-java-client.git
  2. cd cf-java-client
  3. git checkout spring4
  4. mvn install (You'll need a recent version of Apache Maven. You'll also need a protocol buffer compiler.)

Now that we have this in our local Maven repository, we can build the cf-autoscaler components. Before building, we'll make some minor changes to the code:

Now we're ready to build the component jars:

  1. cd cf-autoscaler
  2. ./gradlew assemble (The gradlew Gradle wrapper will download the appropriate version of Gradle and then build the project artifacts.)
Deploying

The project includes a manifest-pws.yml file that includes the necessary metadata to deploy the four components:

It will also bind to these applications a RabbitMQ service provided by CloudAMQP via the Pivotal Web Services Marketplace.

You will need to create this service in advance via cf create-service cloudamqp bunny cloudamqp-autoscale. It uses the Big Bunny plan, which is $99 per month, but represents the smallest plan that can provide the necessary connections for this demo (One connection each for the producer-process and autoscaler-process, plus n connections for the worker-process instances. With the current throttling settings, instances usually cycle between one and six instances. By tweaking the settings, you may be able to get away with a Tough Tiger plan at $19/month.). You can learn more about CloudAMQP plans here.

Assuming you've installed the CF CLI, from the cf-autoscaler directory:

  1. cf api https://api.run.pivotal.io
  2. cf login (Provide your credentials and choose an appropriate organization and space. You'll need a memory quota of around 4 GB.)
  3. cf push -f manifest-pws.yml

This will deploy all of the components in the order shown above.

The web UI will be available at a URL with a random word appended to the hostname. You'll see it as one of the last output lines from the cf push command:

: autoscale-monitor-f2840.cfapps.io

You can visit this URL to see the gauges working:

Dashboard

Another useful way to monitor the application is via the CF CLI, which supports tailing of application logs via the Cloud Foundry Loggregator.

Example:

logs autoscaler-process
ected, tailing logs for app autoscaler-process in org jwatters-org / space autoscale as mstine@gopivotal.com...

-01-10T10:43:13.00-0600 [API]     OUT Created app with guid 0186722f-0843-4111-a96f-8d145195b276
-01-10T10:43:42.41-0600 [API]     OUT Updated app with guid 0186722f-0843-4111-a96f-8d145195b276 ({"console"=>true, "state"=>"STARTED"})
-01-10T10:53:24.73-0600 [App/0]   OUT 2014-01-10 16:53:24.730  INFO 31 --- [ask-scheduler-7] com.gopivotal.cf.autoscaling.Autoscaler  : { workers : 1}
-01-10T10:53:26.68-0600 [App/0]   OUT 2014-01-10 16:53:26.681  INFO 31 --- [ask-scheduler-7] com.gopivotal.cf.autoscaling.Autoscaler  : { workers : 1}
-01-10T10:53:27.29-0600 [App/0]   OUT 2014-01-10 16:53:27.292  INFO 31 --- [ask-scheduler-1] com.gopivotal.cf.autoscaling.Autoscaler  : { msgs : 53 consumers : 1}
-01-10T10:53:27.36-0600 [App/0]   OUT 2014-01-10 16:53:27.362  INFO 31 --- [ask-scheduler-6] com.gopivotal.cf.autoscaling.Autoscaler  : { msgs : 53 consumers : 1}
-01-10T10:53:29.36-0600 [App/0]   OUT 2014-01-10 16:53:29.360  INFO 31 --- [ask-scheduler-6] com.gopivotal.cf.autoscaling.Autoscaler  : { msgs : 54 consumers : 1}
-01-10T10:53:31.35-0600 [App/0]   OUT 2014-01-10 16:53:31.359  INFO 31 --- [ask-scheduler-6] com.gopivotal.cf.autoscaling.Autoscaler  : { msgs : 55 consumers : 1}
-01-10T10:53:32.14-0600 [App/0]   OUT 2014-01-10 16:53:32.146  INFO 31 --- [ask-scheduler-9] com.gopivotal.cf.autoscaling.Autoscaler  : { workers : 1}
-01-10T10:53:32.71-0600 [App/0]   OUT 2014-01-10 16:53:32.710  INFO 31 --- [ask-scheduler-9] com.gopivotal.cf.autoscaling.Autoscaler  : { workers : 2}
Running on Pivotal CF Elastic Runtime

This section will assume that you have an account on an existing Pivotal CF Elastic Runtime environment.

Building

The autoscaler component depends on the Cloud Foundry Java Client Library (https://github.com/cloudfoundry/cf-java-client/tree/master/cloudfoundry-client-lib). The cf-java-client currently depends on Spring 3.2. The cf-autoscaler applications are written using Spring 4.0. A branch of cf-java-client that works with Spring 4.0 has been created. First we'll need to build that from source.

  1. git clone git@github.com:cloudfoundry/cf-java-client.git
  2. cd cf-java-client
  3. git checkout spring4
  4. mvn install (You'll need a recent version of Apache Maven. You'll also need a protocol buffer compiler.)

Now that we have this in our local Maven repository, we can build the cf-autoscaler components. Before building, we'll make some minor changes to the code:

Now we're ready to build the component jars:

  1. cd cf-autoscaler
  2. ./gradlew assemble (The gradlew Gradle wrapper will download the appropriate version of Gradle and then build the project artifacts.)
Deploying

The project includes a manifest-pcf.yml file that includes the necessary metadata to deploy the four components:

It will also bind to these applications a Pivotal RabbitMQ for Pivotal CF service instance. This service must be installed in your Pivotal CF environment.

You will need to create this service in advance via cf create-service p-rabbitmq standard rmq-autoscale.

Assuming you've installed the CF CLI, from the cf-autoscaler directory:

  1. cf api https://api.yourpcfsystemdomain.com
  2. cf login (Provide your credentials and choose an appropriate organization and space. You'll need a memory quota of around 4 GB.)
  3. cf push -f manifest-pcf.yml

This will deploy all of the components in the order shown above.

The web UI will be available at a URL with a random word appended to the hostname. You'll see it as the last output from the cf push command:

: autoscale-monitor-f2840.yourpcfappdomain.com

You can visit this URL to see the gauges working:

Dashboard

Another useful way to monitor the application is via the CF CLI, which supports tailing of application logs via the Cloud Foundry Loggregator.

Example:

logs autoscaler-process
ected, tailing logs for app autoscaler-process in org jwatters-org / space autoscale as mstine@gopivotal.com...

-01-10T10:43:13.00-0600 [API]     OUT Created app with guid 0186722f-0843-4111-a96f-8d145195b276
-01-10T10:43:42.41-0600 [API]     OUT Updated app with guid 0186722f-0843-4111-a96f-8d145195b276 ({"console"=>true, "state"=>"STARTED"})
-01-10T10:53:24.73-0600 [App/0]   OUT 2014-01-10 16:53:24.730  INFO 31 --- [ask-scheduler-7] com.gopivotal.cf.autoscaling.Autoscaler  : { workers : 1}
-01-10T10:53:26.68-0600 [App/0]   OUT 2014-01-10 16:53:26.681  INFO 31 --- [ask-scheduler-7] com.gopivotal.cf.autoscaling.Autoscaler  : { workers : 1}
-01-10T10:53:27.29-0600 [App/0]   OUT 2014-01-10 16:53:27.292  INFO 31 --- [ask-scheduler-1] com.gopivotal.cf.autoscaling.Autoscaler  : { msgs : 53 consumers : 1}
-01-10T10:53:27.36-0600 [App/0]   OUT 2014-01-10 16:53:27.362  INFO 31 --- [ask-scheduler-6] com.gopivotal.cf.autoscaling.Autoscaler  : { msgs : 53 consumers : 1}
-01-10T10:53:29.36-0600 [App/0]   OUT 2014-01-10 16:53:29.360  INFO 31 --- [ask-scheduler-6] com.gopivotal.cf.autoscaling.Autoscaler  : { msgs : 54 consumers : 1}
-01-10T10:53:31.35-0600 [App/0]   OUT 2014-01-10 16:53:31.359  INFO 31 --- [ask-scheduler-6] com.gopivotal.cf.autoscaling.Autoscaler  : { msgs : 55 consumers : 1}
-01-10T10:53:32.14-0600 [App/0]   OUT 2014-01-10 16:53:32.146  INFO 31 --- [ask-scheduler-9] com.gopivotal.cf.autoscaling.Autoscaler  : { workers : 1}
-01-10T10:53:32.71-0600 [App/0]   OUT 2014-01-10 16:53:32.710  INFO 31 --- [ask-scheduler-9] com.gopivotal.cf.autoscaling.Autoscaler  : { workers : 2}

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.