Improving the performance of the sequential execution mode
Sequential algorithm
-
The rules must be homogeneous. Homogeneous rules mean that the conditions of these rules must be set on the same kind and number of objects. If you try to apply the sequential algorithm to heterogeneous rules, it typically creates more tuple objects, which can result in more rules being run than in the RetePlus mode. The common tuple signature can also cause heterogeneous rules not to fire: When there are no corresponding instances in working memory, no tuples can be created.
-
The rules must not be chained, that is, the modification done in the action part of a rule must not lead to execution of another rule.
If you specify the sequential execution mode for rules that are not compliant with it, the engine raises an error.
Tuples
A tuple is a list of objects that complies with a particular structure. A tuple structure is simply a sequence of class descriptors. Each location in a tuple structure is called a slot. The same class descriptor can appear more than once at different slots.
Take a tuple structure:
(Customer,Product)
Here is a tuple that complies with this structure:
(new Customer("Henry"),new DVD("Mickey"))
Note that the subclassing is taken into account because
a DVD is a Product. However, some
tuples that do not comply with the structure:
For example, the following tuple is too large:
(new Customer("Henry"),new CD("Madona"),new DVD("Mickey"))
This tuple is not correctly ordered:
(new DVD("Lord of the rings"),new Customer("Henry"))
And this tuple is too small:
(new Customer("Henry"))
In Java™, a tuple is easily implemented as an array of objects:
Java Tuple = Object[]
The Java code to create a tuple and its objects is:
new Object[] {new Customer("Henry"),new DVD("Mickey")}
At run time, the tuples are built automatically from the content of the working memory and then passed to the rule engine. The tuples are passed one after the other to the tuple-matching method.
Control properties in sequential mode
Control properties affect the sequential mode execution and the tuple structure. See Control properties for rule tasks in execution modes for more general information.
The number of rules to be executed per tuple and the order in which they execute can be specified with control properties: ordering, firing, and firinglimit.
The ordering property
The ordering property
is mandatory for sequential processing. It describes the order by
which the rules of the rule task will be executed.
There are two values available:
-
literal: The rules are kept in the order in which they are set into the task body (using up/down arrows). -
sorted: The rules are sorted according to their static priorities.
Note that another value, dynamic, is available
only for rule tasks using the RetePlus execution mode.
The firing property
The firing property
specifies whether, for each tuple, all the rules or only the first
rule that applies should be executed. This property is optional.
It has two possible values:
-
allrulesThis value means that all the rules that apply should be executed before skipping to the next tuple. This is the default value.
-
ruleThis value means that only the first rule that applies should be executed on the first tuple.
The firinglimit property
The firinglimit property
gives another level of control when the firing property
is set to allrules. It is used to specify a number
that represents the maximum number of rules to be executed before
skipping to the next tuple. This number should be greater than zero.
Known limitations of the sequential algorithm
The following table outlines the limitations of sequential processing, in particular its use combined with certain ILOG® Rule Language (IRL) constructs.
| Limitation | Description |
|---|---|
| ILOG Rule Language (IRL) limitations | Not all the rule patterns that have been designed for the stateful Rete matching are available. Compile time errors occur when a rule is not compliant with the current tuple-matching implementation. Therefore, when sequential processing is used, the IRL does not support the following features:
|
| Condition constructs | The following condition constructs are available in sequential processing:
|
| Refraction | The data unit for an engine cycle is the tuple. The engine does not record the tuples as they are matched, it rather forgets them between cycles. Therefore, there is no built-in support for refraction. Using the sequential execution mode, the above rule task becomes: The execution trace shows that, by using the sequential execution mode, the same rule are run twice for the same parts of two different tuples. Although there is no built-in support for refraction, the sequential execution mode uses a particular rule application strategy when it generates the body of the tuple matching method. The strategy, however, tries to limit the use of refraction. |
| ILOG Rule Language (IRL) facilities | In contrast, practically all the script-level expressions and statements of the IRL are available in sequential processing. They serve principally to maintain the consistency of the other rule tasks that are not set to the sequential algorithm. Here is a list of these features:
|