6 Policy-Based Scaling
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.
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 smart rule based policies for a diagnostic system module in the Oracle WebLogic Server Administration Console Online Help using the WebLogic Server Administration Console
-
See Smart Rule Reference in Configuring and Using the Diagnostics Framework for Oracle WebLogic Server.
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:
-
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
.
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.
-
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
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:
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
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:
See Starting and Stopping Servers in Administering Server Startup and Shutdown for Oracle WebLogic Server.
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:
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
, andDynamicCluster-4
. -
The server instances
DynamicCluster-1
andDynamicCluster-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 instancesDynamicCluster-1
andDynamicCluster-2
. -
The bottom chart shows the number of active Managed Servers in the cluster, as indicated by the value of the
AliveServerCount
attribute of theClusterRuntimeMBean
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.