7 August 2013

Prevent Looping and Inefficient Rule Executions

This recipe, taken from the recently published Oracle SOA Suite 11g Performance Cookbook gives guidance on how to avoid rule executions that will loop, potentially indefinitely! We’ll use an inbound XML fact and a local RL fact as an example.

Getting ready

You’ll need access to a SOA composite containing an Oracle Business Rules component in JDeveloper to apply this recipe. We’ll assume you have an XSD schema with an input type RequestInput containing input and bonus String types, and output String value called output in a type ResponseOutput. These aren’t efficient but serve as an example. We’ll step through adding a rule to a composite and creating an RL fact.

How to do it...

1.      Open a SOA composite. Right click on the Project and select Business Rules (Service Components), use the search box if it is not immediately available.

2.      Give the rule a name and click the green plus icon to add the RequestInput to the input and ResponseOutput to the output types.

3.      In the rules designer, click on the Facts icon and select the RL Facts tab. Click the green plus icon, then right click and select edit.

4.      Name the RL Fact Customer Role and click the green plus icon to add a property. Name the property Role and set its type to String. Add another property called Reward of type int.

5.      Select Ruleset1 and click the green icon to Create a Rule

6.      In the IF test set the condition to select RequestInput.input>=”200”.

7.      Set the THEN action to assert new CustomerAccount( Role:”GOLD”)

8.  Click the green plus icon in the ruleset to add a rule 2. In the IF condition set CustomerAccount.Role==”GOLD”
9. In the THEN action set modify CustomerAccount.Reward=150
10. In the THEN action set modify CustomerAccount.Role=”SILVER”
11.  To complete the ruleset so it will compile, add a third rule to assign the output of the Customer.Account if it is “GOLD” as “high value” and a fourth rule to set it to “low value” otherwise.

How it works...

In this example we created a ruleset with rules that checked input XML facts and modified RL facts appropriately before assigning a response to an output XML fact.
Whilst the assignment in step 11 may seem odd, it illustrates an important facet of rule execution. When actions alter a value that is checked in another condition, in this case CustomerAccount.Role, then a rule loop occurs. These loops can occur across a single rule, decision table or multiple rules and decision tables in the same ruleset. It would be easy for a business user to inadvertently create a logic pattern that caused this looping by applying an inefficient pattern such as a reward scheme in our example. The loops created by these patterns have the potential to continue indefinitely, ultimately preventing further composites from being able to execute in the rule context.
To avoid this scenario we should construct our rule logic to try and prevent these scenarios from occurring. Runtime monitoring is helpful in identifying these items when testing.

Oracle SOA Suite-Upcoming Events

Oracle SOA Suite 11g Performance - Interactive Surgery Session
Monday, 9th of September 2013, 4pm - 5pm
Submit your performance problems for our experts to analyse during the webinar and you can win a copy of ‘Oracle SOA Suite 11g Performance Tuning Cookbook'!

If you enjoyed this post, why not subscribe to our feed?

Enter your email address:

No comments :

Post a Comment