Performance issues with a rule that includes LHS functions
by Mike Goldner
I have a rule that is suffering severe performance degradation as I insert
facts into the (stateful) session. In my simplified example, the first
100 fact insertions take less than 10ms per fact. By the 1000th fact,
insertions are taking about 850ms per fact. In production, the impact is
much more severe, reaching 5000ms or more by the 1000th insertion. The
number of facts per execution can vary from a few hundred to a few
thousand.
I've created a simplified example that demonstrates the problem: Imagine
that there is a line plotted through a 3-dimensional plane and it is
necessary to ensure that each plotted coordinate is an equal distance from
the adjacent coordinates. I realize that the math isn't correct, but it
is sufficient for the example.
The constraint (and source of performance degradation) imposed by my data
source is that the plane (X, Y, or Z) is variable and it is defined by an
separate index that serves as a pointer into the coordinate list. If I
remove the function calls, the problem disappears.
Any suggestions on how I could rewrite the rule?
Here is my rule:
package test;
declare Data
plane : int
coordinates : java.util.List
end
rule "Performance degradation with functions."
dialect "mvel"
when
$current : Data( $currentPosition : getPosByAxis(plane, coordinates) )
$before : Data( $beforePosition : getPosByAxis(plane, coordinates) <
$currentPosition)
not Data( getPosByAxis(plane, coordinates) > $beforePosition && <
$currentPosition)
$after : Data($afterPosition : getPosByAxis(plane, coordinates) >
$currentPosition)
not Data(getPosByAxis(plane, coordinates) < $afterPosition && >
$currentPosition)
eval ( ($currentPosition - $beforePosition) == ($afterPosition -
$currentPosition) )
then
System.out.println("Rule RHS fired.");
end
function Double getPosByAxis(int plane, java.util.List coordinates) {
return (Double) coordinates.get(plane);
}
Thanks,
Mike Goldner
13 years, 10 months
Accessing properties of an object within a Nested Collection of a Nested Collection
by aa034373
I am having a hard time trying to figure this out, maybe it is obvious and I
have overlooked it.... I am trying to evaluate properties of a object
contained within a nested collection of a nested collection on the LHS.
Here is an example of the object model I am working with.
*AutoManufacturer* is the parent class, with *Brand* residing in a
collection on the object, with *Model* residing in a collection on *Brand*,
and finally, *Part* residing in a collection of *Model*. These classes were
created for illustration purposes for this question.....
My question more specifically would be, on the LHS, how would I write a rule
for instance that would find all *Part* objects with a Vendor of "PV999999".
Secondly, on the RHS, how could I iterate the resulting collection of Part
objects to print something like the partname for each of them.
Here are the class objects:
AutoManufacturer class
-----------------------------------------------------
package com.nabble.demo.model;
import java.util.ArrayList;
import java.util.List;
/**
* Class that represents an automobile manufacturer
*/
public class AutoManufacturer
{
private String manufacturerName;
private String manufacturerId;
private List<Brand> brandsCollection;
/**
* Default constructor
*/
public AutoManufacturer()
{
this.brandsCollection = new ArrayList<Brand>();
}
/**
* @return the manufacturerName
*/
public String getManufacturerName()
{
return this.manufacturerName;
}
/**
* @param manufacturerName the manufacturerName to set
*/
public void setManufacturerName( String manufacturerName )
{
this.manufacturerName = manufacturerName;
}
/**
* @return the manufacturerId
*/
public String getManufacturerId()
{
return this.manufacturerId;
}
/**
* @param manufacturerId the manufacturerId to set
*/
public void setManufacturerId( String manufacturerId )
{
this.manufacturerId = manufacturerId;
}
/**
* @return the brandsCollection
*/
public List<Brand> getBrandsCollection()
{
return this.brandsCollection;
}
/**
* @param brand the Brand to add to the collection
*/
public void addBrand( Brand brand )
{
this.brandsCollection.add(brand);
}
}
Brand class
------------------------------------------------------
package com.nabble.demo.model;
import java.util.ArrayList;
import java.util.List;
public class Brand
{
private String brandName;
private String brandId;
private List<Model> brandModels;
public Brand()
{
this.brandModels = new ArrayList<Model>();
}
/**
* @return the brandName
*/
public String getBrandName()
{
return brandName;
}
/**
* @param brandName the brandName to set
*/
public void setBrandName( String brandName )
{
this.brandName = brandName;
}
/**
* @return the brandId
*/
public String getBrandId()
{
return brandId;
}
/**
* @param brandId the brandId to set
*/
public void setBrandId( String brandId )
{
this.brandId = brandId;
}
/**
* @return the brandModels
*/
public List<Model> getBrandModels()
{
return brandModels;
}
/**
* @param model the Model to add
*/
public void addModel( Model model )
{
this.brandModels.add(model);
}
}
Model class
--------------------------------------------------------
package com.nabble.demo.model;
import java.util.ArrayList;
import java.util.List;
/**
* Class that represents a particular model of an automaker's brand of car
*/
public class Model
{
private String modelName;
private String modelId;
private List<Part> partsList;
public Model()
{
this.partsList = new ArrayList<Part>();
}
/**
* @return the modelName
*/
public String getModelName()
{
return this.modelName;
}
/**
* @param modelName the modelName to set
*/
public void setModelName( String modelName )
{
this.modelName = modelName;
}
/**
* @return the modelId
*/
public String getModelId()
{
return this.modelId;
}
/**
* @param modelId the modelId to set
*/
public void setModelId( String modelId )
{
this.modelId = modelId;
}
/**
* @return the partsList
*/
public List<Part> getPartsList()
{
return this.partsList;
}
/**
* Method to add new part to collection
*
* @param part
*/
public void addPart( Part part )
{
this.partsList.add(part);
}
}
Part Class
----------------------------------------------------------------
package com.nabble.demo.model;
/**
* Class that represents a part used on a Model of car
*/
public class Part
{
private String partsId;
private String partsName;
private String partVendor;
/**
* Default constructor
*/
public Part()
{
}
/**
* @return the partsId
*/
public String getPartsId()
{
return this.partsId;
}
/**
* @param partsId the partsId to set
*/
public void setPartsId( String partsId )
{
this.partsId = partsId;
}
/**
* @return the partsName
*/
public String getPartsName()
{
return this.partsName;
}
/**
* @param partsName the partsName to set
*/
public void setPartsName( String partsName )
{
this.partsName = partsName;
}
/**
* @return the partVendor
*/
public String getPartVendor()
{
return partVendor;
}
/**
* @param partVendor the partVendor to set
*/
public void setPartVendor( String partVendor )
{
this.partVendor = partVendor;
}
}
Finally...... here is my class to create an instance of the AutoManufacturer
object that would become the FACT for the rule to fire upon.
package com.nabble.demo;
import com.nabble.demo.model.AutoManufacturer;
import com.nabble.demo.model.Brand;
import com.nabble.demo.model.Model;
import com.nabble.demo.model.Part;
/**
* Class to demonstrate using Autommaker model objects
*/
public class ProcessAutomaker
{
/**
* @param args
*/
public static void main( String[] args )
{
//Create instance of AutoManufacturer
AutoManufacturer automanf = new AutoManufacturer();
automanf.setManufacturerId("123456");
automanf.setManufacturerName("Large Auto Maker");
//Create instance of Model
Model model = new Model();
model.setModelName("LargeSUV");
model.setModelName("MN444555");
//Create instances of Part, add to current Model instance
Part part = new Part();
part.setPartsId("PP123456");
part.setPartsName("Steering Wheel");
part.setPartVendor("PV999999");
model.addPart(part);
part = new Part();
part.setPartsId("PP123499");
part.setPartsName("Brake Pedal");
part.setPartVendor("PV999999");
model.addPart(part);
part = new Part();
part.setPartsId("PP123499");
part.setPartsName("Floor Mat");
part.setPartVendor("PV111111");
model.addPart(part);
//Create instance of Brand
Brand brand = new Brand();
brand.setBrandName("Brand1");
brand.setBrandId("BB123456");
brand.addModel(model);
automanf.addBrand(brand);
}
}
--
View this message in context: http://drools.46999.n3.nabble.com/Accessing-properties-of-an-object-withi...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
working memory error
by Zhao Yi
I have two knowledge bases,one is drl file the other is pkg file. My
application creates knowledge base from drl files first then create
knowledge base from pkg file. There is nothing wrong when I create drl file
knowledge base and fire rules, but I got below error when I create pkg file
knowledge and fire the rules. Does anyone know what this issue mean?
Caused by: java.lang.LinkageError: loader constraint violation: loader
(instance of org/drools/rule/JavaDialectRuntimeData$PackageClassLoader)
previously initiated loading for a different type with name
"org/drools/WorkingMemory"
--
View this message in context: http://drools.46999.n3.nabble.com/working-memory-error-tp3961517.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
drools5.3.0 rule time error with osgi environment
by Zhao Yi
I am using drools 5.3.0 and work in osgi environment. i have installed
drools-core, drools-api, drools-compiler and drools-tempalte in osgi
context. I have no problem to load knowledgebase but get error when fire
rules, please see below error message. Does anyone know how to fix it?
java.lang.LinkageError: loader constraint violation: when resolving
interface method
"org.drools.spi.KnowledgeHelper.update(Lorg/drools/FactHandle;)V" the class
loader (instance of
org/drools/rule/JavaDialectRuntimeData$PackageClassLoader) of the current
class, defaultpkg/Rule_ScanRange__startLocationCheck, and the class loader
(instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) for
resolved class, org/drools/spi/KnowledgeHelper, have different Class objects
for the type org/drools/FactHandle used in the signature
java.lang.LinkageError: loader constraint violation: when resolving
interface method
"org.drools.spi.KnowledgeHelper.update(Lorg/drools/FactHandle;)V" the class
loader (instance of
org/drools/rule/JavaDialectRuntimeData$PackageClassLoader) of the current
class, defaultpkg/Rule_ScanRange__startLocationCheck, and the class loader
(instance of org/eclipse/osgi/internal/baseadaptor/DefaultClassLoader) for
resolved class, org/drools/spi/KnowledgeHelper, have different Class objects
for the type org/drools/FactHandle used in the signature
--
View this message in context: http://drools.46999.n3.nabble.com/drools5-3-0-rule-time-error-with-osgi-e...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
Getting Error while using Drools 5.3.0
by mkhan_rt54fde
Hi,
My application works fine with Drools v 4.0.7. However, when I run my
application using Drools 5.3.0, I am getting the following error:
org.drools.rule.InvalidRulePackage: Evaluator '>' does not support type
'ValueType = 'String' : [Rule name='VIN required for newer vehicles']
at org.drools.rule.Package.checkValidity(Package.java:478)
at
org.drools.common.AbstractRuleBase.addPackages(AbstractRuleBase.java:481)
at org.drools.reteoo.ReteooRuleBase.addPackages(ReteooRuleBase.java:458)
at org.drools.reteoo.ReteooRuleBase.addPackage(ReteooRuleBase.java:465)
Here is the condition I am using in my .dsl file:
[condition][]request contains no VIN and the car was built after year
{value}=info: CarRulesInfo(quoteRequest.VIN == null, quoteRequest.modelyear
> 1982 )
Any suggestions on how to fix this problem.
Thanks in advance.
--
View this message in context: http://drools.46999.n3.nabble.com/Getting-Error-while-using-Drools-5-3-0-...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
Even to check if all the rules have been fired
by sumatheja
Hi All,
I'm using a stateful knowledge session in my project, where *
ksession.fireUntilHalt()* will trigger the rules as and when the facts are
inserted. I,m developing a functionaly where I need to insert some new
facts and and retract them once the valid rules have been fired. I'm unable
to find the exact event listener to check if all the valid rules have been
fired. Do I need to handle this case(is it implicitly handled)?
*AfterActivationFiredEvent
*seems to be activated after successfully firing each rule, so I feel this
wont serve the purpose. Thanks in advance.
--
cheers
Sumatheja Dasararaju
13 years, 10 months
Advanced Enum options not working in Guvnor 5.4 Decision table
by worldofprasanna
Hi,
Am trying to use the Enums which are dependent on other enums (similar to
that of engineType and petrolType example given in the doc). But this
feature works well for Business rule not in case of Decision table. In
decision table, I got the engineType updated with the enum values while
petrolType is still displaying Textbox to enter the values.
code :
'Item.category':['Consumer','Electronics']
'Item.subcategory[category=Consumer]':['Television','Radio']
'Item.subcategory[category=Electronics]':['Apple','Sony']
Kindly let me know how can I use Advanced Enum option in Decision table.
Thanks,
Prasanna.
--
View this message in context: http://drools.46999.n3.nabble.com/Advanced-Enum-options-not-working-in-Gu...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
Drools 5.3 Salience
by gboro54
I know using salience is not the best way to order rules but some of our
rules do have a higher priority then others. Since we are writing the rules
using a DSL I have created set set of Priority levels which set the
salience. One of these levels set salience to 0(default value). Is there any
harm in putting this on every rule with no priority for consistence when
reading the rules.
TIA
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-5-3-Salience-tp3955545.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months
Re: [rules-users] Does Drools have a Rules Authoring engine?
by gboro54
Rule authoring in Drools can be done in 2 ways: with the Eclipse or Guvnor. I
am not sure what you mean by a Rules Authoring Engine though. What
requirements to you have for rule authoring? Are business users or developer
authoring rules?
vsm wrote
>
> Drools is a Business Rules Management Engine. I wanted to know if Drools
> has any front-end application that does Rules Authoring?
>
> If yes, then let me know some additional details about it.
> If not, then any suggestions on which Rules Authoring engine would be a
> good alternative with Drools?
>
> Thanks in advance!
>
--
View this message in context: http://drools.46999.n3.nabble.com/Does-Drools-have-a-Rules-Authoring-engi...
Sent from the Drools: User forum mailing list archive at Nabble.com.
13 years, 10 months