6 Policy-Based Scaling
- 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. - 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. - Policy-Based Scaling Example
You can create policies that use thewls:HighThroughput()
andwls:LowThroughput()
smart rules to scale a dynamic cluster up under high load, and then scale the dynamic cluster back down when the demand decreases.
What is Policy-Based Scaling?
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.
Parent topic: Policy-Based Scaling
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 theThreadPoolRuntimeMBean.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 averageThroughput
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 theThreadPoolRuntimeMBean.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 averageThroughput
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:
-
See Create and configure policies and actions in Administering Oracle WebLogic Server with Fusion Middleware Control using the Fusion Middleware Control console.
-
See Smart Rule Reference in Configuring and Using the Diagnostics Framework for Oracle WebLogic Server.
Parent topic: Policy-Based Scaling
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.
The following topics describe the tasks for running a demonstration that shows policy-based scaling of a dynamic cluster:
- Prerequisites
- Setting the Environment
- Creating the Domain and its Resources
- Configuring and Starting the Apache Web Server
- Viewing Dynamic Server Configuration and Activity
- Using JMeter to Drive the Demo
- Re-running and Stopping the Elasticity Demo
Parent topic: Policy-Based Scaling
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:
Parent topic: Policy-Based Scaling Example
Installing Required Software
To run this example, download and install the following software:
-
Oracle WebLogic Server—for instructions and more information, see Installing the Oracle WebLogic Server and Coherence Software in Installing and Configuring Oracle WebLogic Server and Coherence.
Note:
You must have a valid JDK 8 to install and use WebLogic Server for this example. See JDK 8 Certification in What's New in Oracle WebLogic Server.
-
Apache HTTP Server - Ensure that you have a supported Apache HTTP Server installation. See https://www.oracle.com/technetwork/middleware/ias/downloads/fusion-certification-100350.html.
-
Apache HTTP Server 2.2.x plug-ins for WebLogic Server are available for download on the My Oracle Support (http://support.oracle.com) and Software Delivery Cloud (http://edelivery.oracle.com) web sites as zip files containing the necessary binary and helper files. See Configure the Apache HTTP Server Plug-In for more information about configuring the plug-in for Apache HTTP Server.
-
Apache JMeter—you can view instructions and download and install Apache JMeter from
http://jmeter.apache.org/download_jmeter.cgi
.
Parent topic: Prerequisites
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.
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.
Parent topic: Prerequisites
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.
-
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:
-
Click Start.
-
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. -
Enter the administrator credentials, if requested.
-
-
In the command window, change to the
ORACLE_HOME
/wlserver/server/bin
directory. -
Run the
setWLSEnv
script. For example:Windows:
ORACLE_HOME\wlserver\server\bin> setWLSEnv.cmd
Unix:
prompt> sh setWLSEnv.sh
Parent topic: Policy-Based Scaling Example
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
, andDynamicCluster-4
. -
Create and configures the smart rule-based policies,
highMark
andlowMark
, and the elastic actions,scaleDown
andscaleUp
.
To create the domain:
Parent topic: Policy-Based Scaling Example
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:
httpd.exe
sudo systemctl start httpd
Parent topic: Policy-Based Scaling Example
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 Remote 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 Remote Console:
See Starting and Stopping Servers in Administering Server Startup and Shutdown for Oracle WebLogic Server.
Parent topic: Policy-Based Scaling Example
Using JMeter to Drive the Demo
To execute the test plan from JMeter:
Parent topic: Policy-Based Scaling Example
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
Parent topic: Policy-Based Scaling Example