Application Scaling

Application scaling enables your application to react to changes in traffic and automatically allocate the necessary resources to handle your current demand. The OpenShift Online infrastructure monitors incoming web traffic and can automatically add or remove application gears to handle changes in request volume.

All plans allow the creation and management of scalable applications on OpenShift, but the Free Plan is limited to three small gears. Premium plans and Dedicated Node Services allow applications to be scaled from 1 to 16 gears (and beyond), and offer you full control over the minimum and maximum gears available to an application.

Applications on premium plans will never idle.

In this section

Creating a Scalable Application

You must specify whether or not an application can scale when you create the application.

By default, applications created on OpenShift Online are not scalable.

If a scalable application is created, the scaling function of that application cannot be disabled. However, it is possible to clone a non-scaling application and all its associated data using the application clone command. See the OpenShift Online User Guide for more information on cloning an application.

Web Console

When creating an application, select Scale with web traffic from the Scaling dropdown:

Creating a Scalable Application

Command Line (rhc)

When creating an application, the -s flag instructs OpenShift to enable scaling.

For example:

rhc app create scaledappexample php-5.4 -s

Managing Application Scaling

A scalable application defaults to using one gear at a minimum and will use as many gears as you have available on your account. OpenShift allows you to set a minimum and maximum scale via the web console or the CLI.

Web Console

First, select the application you wish to scale from the list of existing applications. In the screen for the individual application, you can see what the current scaling settings are for each cartridge associated with the application. Click on the current scaling settings of a specific cartridge (in the following shot, 1-15 in the Scales section of the php-5.4 cartridge) to update the minimum and maximum number of gears:

Changing Scaling Settings Part 1

Next, define the new Minimum and Maximum gear amount for the cartridge:

Changing Scaling Settings Part 2
If your new minimum is different than you old minimum, the application cartridge will immediately scale up or down when you click Save.

Command Line (rhc)

You can change the default scaling settings with the following command:

$ rhc cartridge scale <your web cart> -a <app_name> --min <minimum> --max <maximum>

For example:

$ rhc cartridge scale php-5.4 -a scaledappexample --min 1 --max 3

If you set the minimum scale above the current minimum, OpenShift will begin scaling up your application, and the operation won’t finish until all of your gears are created.

If you specify -1 as the max you’ll scale up to your account limit.
Sometimes your scale up request will return a timeout error, but the operation will continue on the server.

Scaling Variables

Scaling environment variables let you control how many sessions are allowed per gear before your application scales.

Variable Name

Purpose

OPENSHIFT_MAX_SESSIONS_PER_GEAR

Configures the max sessions used for the scaling algorithm

The default for OPENSHIFT_MAX_SESSIONS_PER_GEAR is 16. To learn more about scaling visit the Application Scaling page.

Scalable Versus Non-scalable Applications

If you create a non-scalable application, which is the default, the web cartridge occupies only a single gear and all traffic is sent to that gear. If you add other cartridges like MongoDB or MySQL, those cartridges will share the same gear and resources as your web cartridge.

When you create a scalable application, the HAProxy cartridge is added as a load balancer to your first web cartridge gear. If you add other cartridges like MongoDB or MySQL to your application, they are installed on their own dedicated gears.

How Scaling Works

The HAProxy cartridge sits between your application and the public internet and routes web traffic to your web cartridges. When traffic increases, HAProxy notifies the OpenShift servers that it needs additional capacity. OpenShift checks that you have a free gear (out of your remaining account gears) and then creates another copy of your web cartridge on that new gear. The code in the git repository is copied to each new gear, but the data directory begins empty. When the new cartridge copy starts it will invoke your build hooks and then the HAProxy will begin routing web requests to it. If you push a code change to your web application all of the running gears will get that update.

The first web gear in a scaling application has HAProxy installed, but also your web application. Once you scale to 3 gears, the web gear that is collocated with HAProxy is turned off, to allow HAProxy more resources to route traffic. Here’s a diagram of your scalable app. If you scale down back to 2 gears or less, the web cartridge on your first gear is started again.

The algorithm for scaling up and scaling down is based on the number of concurrent requests to your application. OpenShift allocates 16 connections per gear - if HAProxy sees that you’re sustaining 90% of your total connections, it adds another gear. If your demand falls to 50% of your total connections for several minutes, HAProxy removes that gear.

Because each cartridge is 'shared-nothing', if you want to share data between cartridges you can use a database cartridge. Each of the gears created during scaling has access to the database and can read and write consistent data.

The OpenShift web console shows you how many gears are currently being consumed by your application.

Supported Scaling Web Cartridges

Most of the standard OpenShift web cartridges are scalable using HAProxy, with the exception of the Do-It-Yourself, Jenkins, and Zend cartridges.