6 Policy-Based Scaling

Oracle WebLogic Server supports policy-based scaling, which is the ability to automatically execute a scaling operation on a dynamic cluster in response to a change in demand, or any other condition, that is monitored by a policy that has been configured in a domain-scope diagnostic system module.The following sections describe policy-based scaling in WebLogic Server and include an example of policy-based scaling using smart rules to track the average throughput in a cluster:

What is Policy-Based Scaling?

Policy-based scaling is based on policies and associated actions, leveraging the Policies and Actions component of the WebLogic Diagnostics Framework (WLDF). A policy sets the conditions under which a scaling operation on a dynamic cluster must occur, and when these conditions are met, the scaling action performs the scaling operation. For more information on the Policies and Actions component of WLDF, see Configuring Policies and Actions in Configuring and Using the Diagnostics Framework for Oracle WebLogic Server.

WLDF provides two elastic actions, scale up and scale down, that you can assign to a policy to perform a scaling operation. For more information on the scale up and scale down actions, see Elastic Actions. Only one scaling action can be assigned to a given policy.

For example, Example 6-1 shows the WLST commands to create and configure a policy that, when triggered, executes a scale up action. Note the following:

  • The scale up action, scaleUp, is created. This action is configured to scale up the dynamic cluster, DynamicCluster, by one server instance.

  • The policy, named highMark, is configured to be evaluated every 10 seconds.

  • When the policy is triggered — that is, it is evaluated to true — the corresponding scale up action is executed.

Similarly, Example 6-2 shows the configuration of a policy that, when triggered, executes a scale down action. Note the following:

  • The scale down action, scaleDown, is created. This action is configured to scale down the dynamic cluster, DynamicCluster, by one server instance.

  • The policy, named LowMark, is configured to be evaluated every 10 seconds.

  • When the policy is triggered — that is, it is evaluated to true — the corresponding scale down action is executed.

Example 6-1 Creating a Policy to Scale Up a Dynamic Cluster

scaleUp=wn.lookupScaleUpAction('scaleUp')
if scaleUp == None:
  print "Creating scale up action"
  scaleUp=wn.createScaleUpAction('scaleUp')
scaleUp.setScalingSize(1)
scaleUp.setClusterName(DynamicCluster)
high=wn.createWatch('highMark')
high.setExpressionLanguage('EL')
high.getSchedule().setMinute('*')
high.getSchedule().setSecond('*/10')
high.getRuleType()
high.setAlarmType('AutomaticReset')
high.setAlarmResetPeriod(150000)
high.setRuleExpression("wls:ClusterHighThroughput('"+DynamicCluster+"', '10s', '30s', 250, 60)")
high.addNotification(scaleUp)
high.setEnabled(true)

Example 6-2 Creating a Policy to Scale Down a Dynamic Cluster

scaleDown=wn.lookupScaleDownAction('scaleDown')
if scaleDown == None:
  print "Creating scale down action"
  scaleDown=wn.createScaleDownAction('scaleDown')
scaleDown.setScalingSize(1)
scaleDown.setClusterName(DynamicCluster)
low=wn.createWatch('lowMark')
low.setExpressionLanguage('EL')
low.getSchedule().setMinute('*')
low.getSchedule().setSecond('*/10')
low.getRuleType()
low.setAlarmType('AutomaticReset')
low.setAlarmResetPeriod(60000)
low.setRuleExpression("wls:ClusterLowThroughput('"+DynamicCluster+"', '10s', '60s', 50, 75)")
low.addNotification(scaleDown)
low.setEnabled(true)

Note:

To configure automated elasticity for a dynamic cluster, you must create a domain-scope diagnostic system module in which you define the scaling policy, along with its corresponding elastic action, and then target that diagnostic module to the Administration Server.

Introducing Smart Rules

Smart rules are prepackaged functions with a set of configurable parameters that allow you to create complex policy expressions just by specifying the values for these configurable parameters.

A smart rule can be used as a predicate within a policy expression, either alone or with other predicates to create a more complex policy expression. Smart rules policy expressions are specified using the Java Expression Language (EL). See Configuring Smart Rule Based Policies in Configuring and Using the Diagnostics Framework for Oracle WebLogic Server.

Smart rules can be used in policy-based scaling. Policy-Based Scaling Example shows the use of policies that use smart rules, wls:ClusterHighThroughput() and wls:ClusterLowThroughput(), in their rule expressions. These two smart rules are also shown in Example 6-1 and Example 6-2:

  • Example 6-1 shows the wls:ClusterHighThroughput() smart rule. This smart rule measures whether the average throughput in a cluster is increasing, as indicated by the average value of the ThreadPoolRuntimeMBean.Throughput attribute in each Managed Server.

    As specified in this example, this smart rule is triggered — that is, it is evaluated to true — if the average Throughput value, collected at 10-second intervals over the previous 30 seconds, is greater than or equal to 250 on at least 60 per cent of the servers in the dynamic cluster, DynamicCluster. When this smart rule is triggered, it executes the scale up action, scaleUp, which starts up a server instance in the cluster.

  • Example 6-2 shows the wls:ClusterLowThroughput() smart rule. This smart rule measures whether the average throughput in a cluster is decreasing, as indicated by the average value of the ThreadPoolRuntimeMBean.Throughput attribute in each Managed Server.

    As specified in this example, this smart rule is triggered — that is, it is evaluated to true — if the average Throughput value, collected at 10-second intervals over the previous 60 seconds, is less than 50 on at least 75 per cent of the servers in the dynamic cluster, DynamicCluster. When this smart rule is triggered, it executes the scale down action, scaleDown, which stops a server instance in the cluster.

For more information about creating and configuring smart rule-based policies:

Policy-Based Scaling Example

You can create policies that use the wls:HighThroughput() and wls:LowThroughput() smart rules to scale a dynamic cluster up under high load, and then scale the dynamic cluster back down when the demand decreases.

Prerequisites

To successfully run this example, first prepare your environment and download the required files used in this example.

This section includes the following tasks:

Installing Required Software

To run this example, download and install the following software:

Downloading and Unpacking Required Files

The elasticity demo JAR files are available for download from the article Elasticity for Dynamic Clusters in the WebLogic Server Blog at the following location:

https://cdn.app.compendium.com/uploads/user/e7c690e8-6ff9-102a-ac6d-e4aebca50425/92a4be11-24be-41af-a122-be88dcc2684d/File/bd70c19e88c1927f0919d42171cbfe2b/wls_elasticity_demo.zip

Unpack the following files from the elasticity JAR that are used in this example:

Note:

Save all of the following files in the same directory. This directory is referred to as DEMO_HOME in this example.

  • create-domain script - this script creates the domain in this example.

  • Elasticity5MinuteDemo.jmx—the JMeter test plan used in this example.

  • Elasticity1HourDemo.jmx—optional, longer JMeter test plan.

Setting the Environment

After installing WebLogic Server in the ORACLE_HOME directory, run the setWLSEnv script command to set your environment variables for this example.

  1. Open a command window.

    Note:

    If you are running this demo on a Windows system, you may need to have administrator privileges. If so, open the command window as follows:

    1. Click Start.

    2. Right-click Command Prompt, then select Run as administrator.

      If Command Prompt is not listed in the Start Menu, enter command in the Search field, then right-click Command Prompt.

    3. Enter the administrator credentials, if requested.

  2. In the command window, change to the ORACLE_HOME/wlserver/server/bin directory.

  3. Run the setWLSEnv script. For example:

    Windows:

    ORACLE_HOME\wlserver\server\bin> setWLSEnv.cmd
    

    Unix:

    prompt> sh setWLSEnv.sh

Creating the Domain and its Resources

Creating the domain using the create-domain script sets up your domain for this example, including the following:

  • Creates the elasticity_domain domain and directory.

  • Creates and configures the dynamic cluster, DynamicCluster, and four dynamic servers, DynamicCluster-1, DynamicCluster-2, DynamicCluster-3, and DynamicCluster-4.

  • Create and configures the smart rule-based policies, highMark and lowMark, and the elastic actions, scaleDown and scaleUp.

To create the domain:

  1. Change to the directory in which you unpacked the demo JAR file. For example, on Windows:

    ORACLE_HOME\wlserver\server\bin> cd DEMO_HOME

  2. Run the create-domain script. For example:

    Windows:

    DEMO_HOME> create-domain.cmd username password

    Unix:

    DEMO_HOME> sh create-domain.sh username password

    Use the WebLogic Administrator's username and password to run the script.

Configuring and Starting the Apache Web Server

After the installation of Apache HTTP Server and the plug-in for Apache HTTP Server, ensure that you configure the httpd.conf file with the following details:

LoadModule weblogic_module /home/myhome/weblogic-plugins/lib/mod_wl.so

Also, specify the WebLogic cluster and all the ports of the managed servers in the cluster. You can also provide the cluster DNS name instead. For example:


<IfModule mod_weblogic.c>
WebLogicCluster localhost:8001,localhost:8002
</IfModule>
<Location>
SetHandler weblogic-handler
</Location>

Starting the Apache Web Server

Start the Apache WebServer using the following command from the Apache bin directory:

Windows
httpd.exe
Unix
sudo systemctl start httpd

Viewing Dynamic Server Configuration and Activity

When you run the start-servers script, the following WebLogic Server instances are started:

  • The Administration Server

  • Two server instances in the dynamic cluster named DynamicCluster:

    • DynamicCluster-1

    • DynamicCluster-2

You can use either the WebLogic Server Administration Console or Fusion Middleware Control to view the configuration of DynamicCluster and also the number of currently running server instances in the cluster as the demo runs.

For example, to view DynamicCluster in the WebLogic Server Administration Console:

  1. Launch the WebLogic Server Administration Console by entering the following URL in your browser's address bar:
    localhost:20001/console
    
  2. Log in using the WebLogic administrator's credentials that was used to execute the create-domain script.
  3. In the console home page, click Servers.

    The Summary of Servers page is displayed, listing the servers that are currently running and shut down. You can refer to this page as the demo runs to see the state of server instances.

See Starting and Stopping Servers in Administering Server Startup and Shutdown for Oracle WebLogic Server.

Using JMeter to Drive the Demo

To execute the test plan from JMeter:

  1. Open a command prompt and change to the bin directory of the JMeter installation. For example, C:\JMeter\apache-jmeter-2.13\bin.
  2. Enter the following command to start JMeter in GUI mode:
    jmeter.bat
    
  3. In the JMeter console, select File > Open and select Elasticity5MinuteDemo.jmx.
  4. From the Options menu, make sure that Log Viewer is selected.
  5. In the navigation pane on the left, make sure Elasticity Ping Servlet Driver is selected, shown in Figure 6-1.

    Figure 6-1 JMeter Test Navigation Pane

    Description of Figure 6-1 follows
    Description of "Figure 6-1 JMeter Test Navigation Pane"
  6. Select Run > Start.

Using the Monitoring Dashboard to Monitor Scaling Operations

After you start the test plan in JMeter, you can use the WebLogic Server Administration Console Monitoring Dashboard to view the server activity generated by the JMeter test. You will see the number of running server instances ramp up to four in response to the load. When the scenario completes, the additional instances will be scaled down until the minimum number of two running server instances is reached. This entire scenario lasts for five minutes.

To access the Monitoring Dashboard:

  1. Launch the WebLogic Server Administration Console, as described in Viewing Dynamic Server Configuration and Activity, if it is not already running.
  2. Under Charts and Graphs, click Monitoring Dashboard.
  3. In the Monitoring Dashboard, click the start button, shown in Figure 6-2.

    Figure 6-2 Monitoring Dashboard Start Button

    Description of Figure 6-2 follows
    Description of "Figure 6-2 Monitoring Dashboard Start Button"
  4. As JMeter ramps up the volume of simulated client invocations on the dynamic cluster, scaling policies are triggered that execute scaling actions.

    Notice the throughput of the currently running server instances at the moment new server instances are started. Figure 6-3 shows example output. The graphs you obtain may vary depending on your machine's performance characteristics.

    Figure 6-3 Dynamic Server Scaling Activity

    Description of Figure 6-3 follows
    Description of "Figure 6-3 Dynamic Server Scaling Activity"

In Figure 6-3, notice the following:

  • The top four charts show the throughput on the Managed Server instances DynamicCluster-1, DynamicCluster-2, DynamicCluster-3, and DynamicCluster-4.

  • The server instances DynamicCluster-1 and DynamicCluster-2, shown in the top two charts, show throughput spikes that begin at approximately 2:42:00.

  • The chart for DynamicCluster-3 shows that this third server was started when the throughput spikes occurred on the server instances DynamicCluster-1 and DynamicCluster-2.

  • The bottom chart shows the number of active Managed Servers in the cluster, as indicated by the value of the AliveServerCount attribute of the ClusterRuntimeMBean instances. This chart shows approximately when a third and a fourth server instance are started.

  • The third server instance, DynamicCluster-3, is started in the interval between 2:42:00 and 2:43:30.

  • Notice that a fourth server instance, DynamicCluster-4, is started shortly after 2:46:00, to coincide with an increase in throughout on the first three server instances.

  • After a new server instance is started, notice the corresponding decrease in throughput on the other server instances.

Re-running and Stopping the Elasticity Demo

You can re-run the elasticity demo from the JMeter GUI, or you can stop the demo and all running server instances by running the stop-servers script as follows:

Windows:

DEMO_HOME> stop-servers.cmd

Unix:

DEMO_HOME> sh stop-servers.sh