Oracle by Example brandingSelect a Load Balancing Policy

section 0Before You Begin

This 15-minute tutorial shows you how to select a load balancer policy to use in your application deployed in Oracle Application Container Cloud Service.

Background

This tutorial, shows you the difference between using the Round Robin and Hash IP load balancing policy using a sample application in Node.js. The application is a REST application developed with Express and it implements the GET method that increment a global variable and return the timestamp and the value of the counter. The purpose of the application is show how the counter is incremented with every request using the different load balancing policies supported by Oracle Application Container Cloud Service.

Load Balancing provides automated traffic distribution from one entry point to multiple servers, improves resource utilization, facilitates scaling, and helps ensure high availability. Oracle Application Container Cloud Service supports two primary policy types:

  • Round Robin. Distributes incoming traffic sequentially to each server in a backend set list. After each server has received a connection, the load balancer repeats the list in the same order. Round Robin is the default load balancer policy.
  • IP Hash. Uses an incoming request's source IP address as a hashing key to route non-sticky traffic to the same backend server. The load balancer routes requests from the same client to the same backend server as long as that server is available. IP Hash ensures that requests from a particular client are always directed to the same backend server, as long as it is available.

What Do You Need?

  • An Oracle Cloud account with access to an instance of Oracle Application Container Cloud Service
  • The sample-node-app.zip project file

Deploy an Application with the Round Robin Load Balancing PolicyDeploy an Application with the Round Robin Load Balancing Policy

  1. Open the Oracle Application Container Cloud Service console.
  2. In the Applications list view, click Create Application.
  3. In the Create Application dialog box, click Node.
  4. In the Application section, enter TestRoundRobin for the name of your application. Click Browse.
  5. In the File Upload dialog box, select sample-node-app.zip and click Open.
  6. Keep the default values in the Instances and Memory fields and click Create.

section 2Test the TestRoundRobin Application

  1. Click the URL of the application. Pay attention to the timestamp and the counter value.
    Deployments page
    Description of the illustration round-robin-instance-1.png
  2. In the browser, click Refresh .
    Deployments page
    Description of the illustration round-robin-instance-2.png

You created the TestRoundRobin application using the instances by default (2) that means there is a copy of your application running in each instance, so each instance has its own counter, that's the reason you saw counter=1 the two times you did a request.

The round robin load balancing policy lists all the instances and every time you execute a request, the next instance in the list process the request. We can assume that the first request was processed by the instance 1 and the second by the instance 2.


section 3Deploy an Application with the Hash IP Load Balancing Policy

  1. Extract the content of the sample-node-app.zip file.
  2. Open the manifest.json file and add the loadBalancingPolicy parameter with the IP_HASH value:
    {
      "runtime":{
        "majorVersion":"8"
      },
      "command": "node myapp.js",
      "release": {},
      "notes": "Testing the load balancing policies",
      "home":"/test",
      "loadBalancingPolicy":"IP_HASH"
    } 
  3. Save the file and compress again all the files in the sample-node-app.zip file.
  4. Open the Oracle Application Container Cloud Service console.
  5. In the Applications list view, click Create Application.
  6. In the Create Application dialog box, click Node.
  7. In the Application section, enter TestHashIP for the name of your application. Click Browse.
  8. In the File Upload dialog box, select sample-node-app.zip and click Open.
  9. Keep the default values in the Instances and Memory fields and click Create.

section 4Test the TestHashIP Application

  1. Click the URL of the application. Pay attention to the timestamp and the counter value.
    Deployments page
    Description of the illustration hash-ip-instance-1.png
  2. In the browser, click Refresh .
    Deployments page
    Description of the illustration hash-ip-instance-2.png

You can notice that the counter is incremented every time you execute a request to your application, this is because every request associated to the same IP is proceed by the same instance.



more informationWant to Learn More?

Selecting a Load Balancer Policy