Problem : Run Drool Application From Command Prompt
by Pankaj.Jain@lntinfotech.com
Hi
I am trying to integrate Drool with ofbiz and run application from command
prompt. In one way I have integrated it properly and I am able to run it
successfully.
Code : Which I was using initially
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
or
PackageBuilderConfiguration cfg = new PackageBuilderConfiguration();
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
Exception I got :
org.drools.RuntimeDroolsException: Unable to load dialect
'org.drools.rule.builder.dialect.java.JavaDialectConfiguration:java
:org.drools.rule.builder.dialect.java.JavaDialectConfiguration'
at
org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:274)
at
org.drools.compiler.PackageBuilderConfiguration.buildDialectConfigurationMap(PackageBuilderConfiguration.java:259)
at
org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:176)
at
org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:153)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:242)
.
.
.
Caused by: java.lang.NullPointerException
at
org.drools.rule.builder.dialect.java.JavaDialectConfiguration.setCompiler(JavaDialectConfiguration.java:92)
at
org.drools.rule.builder.dialect.java.JavaDialectConfiguration.init(JavaDialectConfiguration.java:55)
at
org.drools.compiler.PackageBuilderConfiguration.addDialect(PackageBuilderConfiguration.java:270
Problem I found :
In the class JavaDialectConfiguration in jar file drools-compiler.jar
there is a method named "setCompliler", in this method Null Pointer
Exception was coming.
Solution I provided :
In my application I created my custom class CustomJavaDialectConfiguration
by extending to class JavaDialectConfiguration, In this class I overrided
the method setCompiler. My method was exactly same as that of method
setCompiler in JavaDialectConfiguration . To call my dialect class I also
overrided the method "addDialect" of PackageBuilderConfiguration class .
For that I created class CustomPackageBuilderConfiguration by extending to
PackageBuilderConfiguration.
after that I wrote the code:
PackageBuilderConfiguration cfg = new CustomPackageBuilderConfiguration();
KnowledgeBuilder kbuilder =
KnowledgeBuilderFactory.newKnowledgeBuilder(cfg);
Now application is running perfectly fine from both eclipse and command
prompt without any exception.
I want to know as my overrided method "setCompiler" was exactly same then
why I had to override method, and In original code (ie in
drools-compiler.jar file) why it was giving exception ??? Was that due
to class lader or something else ?? Please do help in this regard ....
Thanks & Regards:
Pankaj Jain | L&T infotech |Navi Mumbai
Mobile: +91 9920218945
Email : pankaj.jain(a)lntinfotech.com
www.Lntinfotech.com
"Whatever the mind of man can conceive & believe, it can achieve."
Larsen & Toubro Infotech Ltd.
www.Lntinfotech.com
This Document is classified as:
L&T Infotech Proprietary L&T Infotech Confidential L&T Infotech
Internal Use Only L&T Infotech General Business
This Email may contain confidential or privileged information for the
intended recipient (s) If you are not the intended recipient, please do
not use or disseminate the information, notify the sender and delete it
from your system.
______________________________________________________________________
16 years, 5 months
custom serialization of session
by Tom Huybrechts
Hi,
I'm trying to provide some custom serialization for certain classes
when serializing a session.
I thought an ObjectMarshallingStrategy would do the trick. But
apparently that is only used for fact handles, and not for process
variables. Is there a way to do this for process variables too ?
Tom
16 years, 5 months
Problems with the declare @propertyChangeSupport Annotation
by Oliver Noack
Hi there,
first some details of my environment, i'm using Drools Guvnor to create
my rules and a MVC-Java application which accesses these rules. My facts
are based on the models of the Java application, and are imported in
Guvnor in a jar-file.
I'm trying to integrate PropertyChangeSupport properly in my current
project. In a previous version I used the RuleBase and inserted the
objects with the boolean flag "dynamic" = true:
boolean dynamic = true;
WorkingMemory workingMemory = ruleBase.newStatefulSession();
workingMemory.insert(someObject, dynamic);
This worked flawlessly. But since this is not possible in the Drools 5
Api I tried to use the @propertyChangeSupport annotation. My idea is to
declare the metadata for the Object in this way:
http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-expert/ht...
But the first problem is that I found no possibility in Guvnor to add
metadata to a Fact Declaration, so for the purpose to test I created a
temporary DRL File with all my rules and the declaration of the
@propertyChangeSupport. Somehow like this:
package somePackage
import com.someObject
declare someObject
@propertyChangeSupport
end
[bunch of rules]
...
But this isn't working, the object's property changes are ignored. Btw.
the PropertyChangeListener is implemented correctly in the considered
object. Do you have some hints to point me into the right direction?
Thanks for help,
Oliver Noack
16 years, 5 months
Returned mail: see transcript for details
by Returned mail
The original message was received at Tue, 21 Jul 2009 01:53:32 -0800
from [27.171.122.220]
----- The following addresses had permanent fatal errors -----
<rules-users(a)lists.jboss.org>
----- Transcript of the session follows -----
... while talking to lists.jboss.org.:
>>> RCPT To:<rules-users(a)lists.jboss.org>
<<< 550 MAILBOX NOT FOUND
16 years, 5 months
cannot access globals - multiple processes
by Thomas Zwifl
hi there!
i am using drools 5.1 snapshot release.
i have built up the following application:
* first the source files are parsed and a knowledgebase is created
* the application has multiple service-objects
* each service object gets a reference to the same knowledgebase
* each service creates a StatefulKnowledgeSession in its constructor,
and then adds its global variables to the session.
* after all services are created, the startService method of each service
is called.
* within this method there is the following code:
new Thread(
new Runnable()
{
public void run()
{
ksession.fireUntilHalt();
}
}
).start();
ksession.startProcess(servicename, params);
the problem is: if i run only 1 service everything works fine. when running more than 1 services i cannot access the global variables from my rules or processes anymore. anyone has an idea whats the reason for that behavior?
Thanks a lot in advance!
tom
--
Neu: GMX Doppel-FLAT mit Internet-Flatrate + Telefon-Flatrate
für nur 19,99 Euro/mtl.!* http://portal.gmx.net/de/go/dsl02
16 years, 5 months
Global variables and multiple processes
by Thomas Zwifl
hi!
i am using drools 5.1 snapshot release.
i built up following application:
* at the beginning the sourcefiles (*.rf, *.drl) are parsed
* the app has multiple service objects.
* each service object gets a reference to the same KnowledgeBase
(created prior)
* in the constructor of a service, a StatefulKnowledgeSession
is created, and the global variables are assigned to the session.
* after all services are created, they a started (methodcall startService())
* within this method, there is the following code:
--
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/chbrowser
16 years, 5 months
trying to load Rules as XML file in KnowledgeBuilder
by Abarna Ramachandran
*Hi
I am trying to learn drools. Please help me with this problem. I am using
the HelloWorldExample from drools5.0 examples.
I have converted the HelloWorld.drl to HelloWorld.xml using the XmlDumper
class as follows: *
final Reader source = new InputStreamReader(
HelloWorldExample.class.getResourceAsStream( "HelloWorld.drl" ) );
Reader source = new InputStreamReader(fis );
final DrlParser drlp= new DrlParser();
final PackageDescr astx = drlp.parse(source);
String hope = new String();
XmlDumper xmldumper = new XmlDumper();
hope = xmldumper.dump(astx);
System.out.print(hope);
try {
FileWriter fw = new FileWriter(new File("d://HelloWorld.xml"));
fw.write(hope);
fw.flush();
fw.close();
} catch (IOException e){
}
*Then i am trying to load it as follows: *
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
// this will parse and compile in one step
kbuilder.add(ResourceFactory.newClassPathResource("HelloWorld.xml",
HelloWorldExample.class), ResourceType.XDRL);
// Check the builder for errors
if (kbuilder.hasErrors()) {
System.out.println(kbuilder.getErrors().toString());
throw new RuntimeException("Unable to compile
\"HelloWorld.drl\".");
}
// get the compiled packages (which are serializable)
final Collection<KnowledgePackage> pkgs = kbuilder
.getKnowledgePackages();
// add the packages to a knowledgebase (deploy the knowledge
packages).
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(pkgs);
*When i try to run this example, i am getting the error*
null: 5, 77): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 5, 77): cvc-elt.1: Cannot find the declaration of element 'package'.
(null: 6, 64): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 8, 51): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 12, 26): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 13, 47): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 15, 6): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 15, 53): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 16, 39): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 17, 50): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 20, 60): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 27, 12): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 31, 30): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 32, 47): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 34, 6): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 34, 38): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 35, 39): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 36, 50): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 39, 60): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
(null: 46, 12): schema_reference.4: Failed to read schema document '
drools.org/drools-5.0.xsd', because 1) could not find the document; 2) the
document could not be read; 3) the root element of the document is not
<xsd:schema>.
Unable to create a Field value of type 'ValueType = 'int'' and value
'Message.HELLO ' : [Rule name='Hello World']
java.lang.NoSuchFieldException: HELLO Unable to create restriction
'[QualifiedIndentifierRestr: == Message.HELLO ]' for field 'status' in the
rule 'Hello World' : [Rule name='Hello World']
Unable to create a Field value of type 'ValueType = 'int'' and value
'Message.GOODBYE ' : [Rule name='Good Bye']
java.lang.NoSuchFieldException: GOODBYE Unable to create restriction
'[QualifiedIndentifierRestr: == Message.GOODBYE ]' for field 'status' in
the rule 'Good Bye' : [Rule name='Good Bye']
Exception in thread "main" java.lang.RuntimeException: Unable to compile
"HelloWorld.drl".
at org.drools.examples.HelloWorldExample.main(HelloWorldExample.java:36)
*I have included the drools5.0 runtime in the classpath of the project and
workspace. Am i missing something?
Is it the right way to load the rules in xml format to KnowledgeBuilder? Is
there an alternate way? Please HELP!
thanks
Abarna*
16 years, 5 months
Re: [rules-users] optimization on a lot of simple rules
by Greg Barton
Well, if your rules are going to be that simple, have you tried sequential mode? If there's never any reaction to working memory changes you don't need the rete network. You should get much better performance out of that ruleset, and others like it, in sequential mode.
See http://downloads.jboss.com/drools/docs/5.0.1.26597.FINAL/drools-expert/ht..., section "3.3.7.1. Sequential Mode"
In a nutshell, the rete network is used for tracking and reacting to changes in the objects inserted into working memory. (i.e. a rule fires, changes a WM object, then other rules may be eligible to fire based on that change.) If you're not going to be using that functionality you'd be constructing and maintaining the rete for no reason.
--- On Mon, 7/20/09, nesta <nesta.fdb(a)163.com> wrote:
> From: nesta <nesta.fdb(a)163.com>
> Subject: Re: [rules-users] optimization on a lot of simple rules
> To: rules-users(a)lists.jboss.org
> Date: Monday, July 20, 2009, 10:13 PM
>
> I execute above test codes, with 100 rules running 1000
> times. In the same
> time, I profile the test codes.
> http://www.nabble.com/file/p24581025/profile.jpg
> The profile result shows that some methods execute 100,000
> times.
> In test codes,
> Service has two states, 0 or 1.
> Subscriber has two states, 0 or 1.
>
> inserted facts:
> Product product = new Product(1, 1);
> Service service = new Service(1);
> Subscriber subscriber = new Subscriber(1);
>
> Service matches a half of total rules, namely 50. So is
> Subscriber.
> (50 + 50 ) * 1000 (running times) = 100,000
>
> I am confused what drools does. Is there a way to optimize
> it?
>
>
> Greg Barton wrote:
> >
> >
> > 1) Yes, if you eliminate joins in rules, you will have
> no joins in the
> > rete. This is self evident.
> >
> > 2) The way you have the rules structured, there is no
> relationship between
> > the joined objects. This will cause what's
> called a "cartesian join"
> > where all combinations of all instances of each object
> type are
> > instantiated. This can be very expensive, memory
> and CPU wise. You've
> > stated that there are only one instance of each object
> type in working
> > memory, but are you absolutely sure of that?
> Cartesian joins can easily
> > cause performance problems quite quickly.
> >
> > For instance, say you've got these objects in working
> memory:
> >
> > Subscriber(gender="male")
> > Subscriber(gender="female")
> > Service(name="ftp")
> > Service(name="http")
> > Product(id=1)
> > Product(id=2)
> > Product(id=3)
> >
> > After inserting a Decision into working memory, the
> rule will fire 2*2*3
> > times. (#Subscribers * #Services * #Products)
> This is by design. Is this
> > what you want?
> >
> > 3) Do you really need the 'Subscriber(gender == "male"
> or "female")' term?
> > Why not just 'Subscriber()'? Are you classifying
> transgendered or
> > nonhuman subscribers in your system?
> >
> > --- On Mon, 7/20/09, nesta <nesta.fdb(a)163.com>
> wrote:
> >
> >> From: nesta <nesta.fdb(a)163.com>
> >> Subject: Re: [rules-users] optimization on a lot
> of simple rules
> >> To: rules-users(a)lists.jboss.org
> >> Date: Monday, July 20, 2009, 10:22 AM
> >>
> >> I want to test the matching performance of drools.
> As I
> >> mentioned that there
> >> are a lot of rules and the rule is like:
> >> rule 1
> >> when
> >> Decision()
> >> Subscriber(gender ==
> >> "male" or "female")
> >> Service(name ==
> >> "ftp" or "http")
> >> Product(id == 1)
> >> ......
> >> then
> >> end
> >>
> >> After test, more condition elements under when,
> more time
> >> needs to execute
> >> the test.
> >> for example
> >> Location ( location == "home" or "office")
> >> and so on.
> >> So I worry about the matching performance with
> drools.
> >>
> >> I found that a lot of JoinNodes would be executed
> in
> >> runtime. I mean if
> >> there is 1000 rules, there will be a lot of
> JoinNodes
> >> (There are at least
> >> 1000 JoinNodes between Decision and Product ). And
> it
> >> exactly affects the
> >> execution performance.
> >>
> >> As you know, Decision, Product, Servcie and so on
> are plan
> >> Java classes. If
> >> I define all of attributes of above classes in one
> class
> >> named WholeFact,
> >> only one Java Type, there is no mentioned issue.
> >>
> >> With WholeFact class, the rule will be changed as
> follows:
> >> rule 1
> >> when
> >> WholeFact(
> >> subscriberGender == "male" or "female",
> >>
> >> serviceName
> >> == "ftp" or "http",
> >>
> >>
> >> productId == 1 or 2 or 3 ...
> >> )
> >> then
> >> end
> >>
> >>
> >> Greg Barton wrote:
> >> >
> >> >
> >> > Now this finally rises to something that
> needs rules.
> >> :) In all of the
> >> > previous examples you've given you could just
> have a
> >> > Map<ProductKey,Handler> where the
> Handler looks
> >> like this:
> >> >
> >> > interface Handler {
> >> > void handle(Product product, Decision
> >> decision);
> >> > }
> >> >
> >> > ...and the ProductKey consists of properties
> that
> >> uniquely identify how
> >> > the Product is handled. So, on it's own,
> that
> >> functionality did not
> >> > require rules.
> >> >
> >> > However, now that you've introduced more
> complex
> >> decisions, with varying
> >> > data, to affect the Decision for each
> Property type,
> >> rules are more
> >> > appropriate.
> >> >
> >> > Is there any reason why you only have one of
> each
> >> object type in memory at
> >> > one time? Maybe if you state more of the
> problem
> >> requirements we can help
> >> > you better.
> >> >
> >> > --- On Mon, 7/20/09, nesta <nesta.fdb(a)163.com>
> >> wrote:
> >> >
> >> >> From: nesta <nesta.fdb(a)163.com>
> >> >> Subject: Re: [rules-users] optimization
> on a lot
> >> of simple rules
> >> >> To: rules-users(a)lists.jboss.org
> >> >> Date: Monday, July 20, 2009, 4:14 AM
> >> >>
> >> >> Thanks very much.
> >> >> But if for every rule, there is one
> algorithm or
> >> discount
> >> >> which means that
> >> >> result has nothing related with Product's
> id and
> >> usage. I
> >> >> can't merge all
> >> >> rules in one rule. At the same time,
> besides
> >> Product and
> >> >> Decision fact type,
> >> >> there are more fact types.
> >> >> For example:
> >> >> rule 1
> >> >> when
> >> >> Decision()
> >> >> Subscriber(gender ==
> >> >> "male" or "female")
> >> >> Service(name ==
> >> >> "ftp" or "http")
> >> >> Product(id == 1)
> >> >> ......
> >> >> then
> >> >> ......
> >> >> end
> >> >> rule 2
> >> >> when
> >> >> Decision()
> >> >> Subscriber(gender ==
> >> >> "male" or "female")
> >> >> Service(name ==
> >> >> "ftp" or "http")
> >> >> Product(id == 2)
> >> >> ......
> >> >> then
> >> >> ......
> >> >> end
> >> >>
> >> >> .....
> >> >> .....
> >> >>
> >> >> In this scenario, if there are 1000
> rules, there
> >> will
> >> >> be a lot of JoinNode.
> >> >> But in runtime, there is only one
> Decision
> >> instance, one
> >> >> Subscriber instance
> >> >> and Service instance.
> >> >>
> >> >> If I define all data in one fact type, I
> think
> >> that there
> >> >> are not a lot of
> >> >> JoinNodes.
> >> >>
> >> >> Is there any other method?
> >> >>
> >> >>
> >> >>
> >> >> Wolfgang Laun-2 wrote:
> >> >> >
> >> >> > Well, what is the realtion between
> id, usage
> >> and the
> >> >> result that's to be
> >> >> > stored in a Decision or a global?
> >> >> >
> >> >> > Typically, such rules could be
> written as
> >> >> >
> >> >> > rule x
> >> >> > no-loop true
> >> >> > when
> >> >> > $d : Decision()
> >> >> > $p :Product( id == 1, $usage
> :
> >> >> usage )
> >> >> > then
> >> >> > compute/store value,
> depending
> >> >> on the formula for id == 1 (using
> >> >> > usage)
> >> >> > end
> >> >> > // similar rule for id == 2,3,...
> >> >> >
> >> >> > If value is a straightforward
> function of id
> >> (and
> >> >> usage), then implement a
> >> >> > function compValue and use a single
> rule,
> >> e.g.:
> >> >> >
> >> >> > rule x
> >> >> > no-loop true
> >> >> > when
> >> >> > $d : Decision()
> >> >> > Product( $id : id, $usage :
> >> >> usage)
> >> >> > then
> >> >> > modify $d value to compValue(
> $id,
> >> $usage
> >> >> )
> >> >> >
> >> >> > Distinguishing all individual
> combinations of
> >> id and
> >> >> usage on the LHS
> >> >> > seems
> >> >> > excessive.
> >> >> >
> >> >> > The ordering of CEs also affects
> execution
> >> times.
> >> >> >
> >> >> > -W
> >> >> >
> >> >> > On 7/20/09, nesta <nesta.fdb(a)163.com>
> >> >> wrote:
> >> >> >>
> >> >> >>
> >> >> >> In this scenario, there are
> 1000
> >> products,
> >> >> different product has
> >> >> >> different
> >> >> >> price, besides this, the price
> is
> >> affected by
> >> >> usage. I want to use
> >> >> >> Product.id to match the rules.
> >> >> >>
> >> >> >> As you mentioned "The crude
> duplication
> >> of rules
> >> >> where only the constant
> >> >> >> to
> >> >> >> be matched with
> >> >> >> Product.id varies can, most
> likely, be
> >> avoided."
> >> >> >>
> >> >> >> How to avoid it in this
> scenario?
> >> >> >>
> >> >> >>
> >> >> >> Wolfgang Laun-2 wrote:
> >> >> >> >
> >> >> >> > It's difficult to suggest
> an
> >> optimized form
> >> >> for your rules 1-infinity,
> >> >> >> > since
> >> >> >> > we do not know what you
> want to
> >> achieve.
> >> >> >> >
> >> >> >> > The crude duplication of
> rules where
> >> only the
> >> >> constant to be matched
> >> >> >> with
> >> >> >> > Product.id varies can, most
> likely,
> >> be
> >> >> avoided.
> >> >> >> >
> >> >> >> > -W
> >> >> >> >
> >> >> >> >
> >> >> >> >
> >> >> >> > On Sun, Jul 19, 2009 at
> 3:15 PM,
> >> nesta <nesta.fdb(a)163.com>
> >> >> wrote:
> >> >> >> >
> >> >> >> >>
> >> >> >> >> Hi,
> >> >> >> >>
> >> >> >> >> I am a newbie in
> drools. There
> >> are a lot
> >> >> of simple rules in a
> >> >> >> scenario.
> >> >> >> >> For example
> >> >> >> >> rule 1
> >> >> >> >> when
> >> >> >> >> Product( id
> >> >> ==1, usage == 1)
> >> >> >> >> $decision :
> >> >> Decision()
> >> >> >> >> then
> >> >> >> >>
> >> >> $decision.setValue(1);
> >> >> >> >> end
> >> >> >> >>
> >> >> >> >> rule 2
> >> >> >> >> when Product( id ==2,
> usage ==
> >> 1)
> >> >> >> >> $decision :
> Decision()
> >> >> >> >> rule 3
> >> >> >> >> when Product( id ==3,
> usage ==
> >> 1)
> >> >> >> >> $decision :
> Decision()
> >> >> >> >> rule 4
> >> >> >> >> when Product( id ==4,
> usage ==
> >> 1)
> >> >> >> >> $decision :
> Decision()
> >> >> >> >> rule 5
> >> >> >> >> when Product( id ==5,
> usage ==
> >> 1)
> >> >> >> >> $decision :
> Decision()
> >> >> >> >> ......
> >> >> >> >>
> >> >> >> >> I have a Product fact
> whose id =
> >> 5 and
> >> >> usage = 1, in my first
> >> >> >> thinking,
> >> >> >> >> only
> >> >> >> >> rule 5 is matched,
> there should
> >> be not
> >> >> much more different between 1
> >> >> >> rule
> >> >> >> >> and a lot of rules in
> runtime.
> >> >> >> >>
> >> >> >> >> But the result shows
> that they
> >> are
> >> >> different. More rules will cost
> >> >> >> more
> >> >> >> >> time. If there are 1
> thousand
> >> rules, some
> >> >> Node and Sink will execute 1
> >> >> >> >> thousand times.
> >> >> >> >>
> >> >> >> >> My question is how to
> optimize
> >> this
> >> >> scenario?
> >> >> >> >> --
> >> >> >> >> View this message in
> context:
> >> >> >> >>
> >> >> >>
> >> >>
> >> http://www.nabble.com/optimization-on-a-lot-of-simple-rules-tp24556724p24...
> >> >> >> >> Sent from the drools -
> user
> >> mailing list
> >> >> archive at Nabble.com.
> >> >> >> >>
> >> >> >> >>
> >> >>
> _______________________________________________
> >> >> >> >> rules-users mailing
> list
> >> >> >> >> rules-users(a)lists.jboss.org
> >> >> >> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >> >> >> >>
> >> >> >> >
> >> >> >> >
> >> >>
> _______________________________________________
> >> >> >> > rules-users mailing list
> >> >> >> > rules-users(a)lists.jboss.org
> >> >> >> > https://lists.jboss.org/mailman/listinfo/rules-users
> >> >> >> >
> >> >> >> >
> >> >> >>
> >> >> >> --
> >> >> >> View this message in context:
> >> >> >>
> >> >>
> >> http://www.nabble.com/optimization-on-a-lot-of-simple-rules-tp24556724p24...
> >> >> >> Sent from the drools - user
> mailing list
> >> archive
> >> >> at Nabble.com.
> >> >> >>
> >> >> >>
> >> _______________________________________________
> >> >> >> rules-users mailing list
> >> >> >> rules-users(a)lists.jboss.org
> >> >> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >> >> >>
> >> >> >
> >> >> >
> >> _______________________________________________
> >> >> > rules-users mailing list
> >> >> > rules-users(a)lists.jboss.org
> >> >> > https://lists.jboss.org/mailman/listinfo/rules-users
> >> >> >
> >> >> >
> >> >>
> >> >> --
> >> >> View this message in context:
> >> >>
> >> http://www.nabble.com/optimization-on-a-lot-of-simple-rules-tp24556724p24...
> >> >> Sent from the drools - user mailing list
> archive
> >> at
> >> >> Nabble.com.
> >> >>
> >> >>
> _______________________________________________
> >> >> rules-users mailing list
> >> >> rules-users(a)lists.jboss.org
> >> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >> >>
> >> >
> >> >
> >> >
> >> >
> >> >
> _______________________________________________
> >> > rules-users mailing list
> >> > rules-users(a)lists.jboss.org
> >> > https://lists.jboss.org/mailman/listinfo/rules-users
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/optimization-on-a-lot-of-simple-rules-tp24556724p24...
> >> Sent from the drools - user mailing list archive
> at
> >> Nabble.com.
> >>
> >>
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users(a)lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >>
> >
> >
> >
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
> --
> View this message in context: http://www.nabble.com/optimization-on-a-lot-of-simple-rules-tp24556724p24...
> Sent from the drools - user mailing list archive at
> Nabble.com.
>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 6 months
Upgrading to Drools 5, but continuing with old API
by Sobhana
hi,
We are using Drools 4.0.7 at present and looking to move to Drools 5.0. How
long is the old API expected to be supported? This will help us plan by when
we'll need to refactor our code to use the new APIs.
What about the rules in existing DRL files? I read in another post that they
are backward compatible. Will there be a huge learning curve in
understanding the new DRL syntax so that it can be used for upcoming rules?
Is there a problem in using the new DRL syntax with old Drools APIs?
Thanks,
Sobhana
--
View this message in context: http://www.nabble.com/Upgrading-to-Drools-5%2C-but-continuing-with-old-AP...
Sent from the drools - user mailing list archive at Nabble.com.
16 years, 6 months
Re: [rules-users] optimization on a lot of simple rules
by Greg Barton
1) Yes, if you eliminate joins in rules, you will have no joins in the rete. This is self evident.
2) The way you have the rules structured, there is no relationship between the joined objects. This will cause what's called a "cartesian join" where all combinations of all instances of each object type are instantiated. This can be very expensive, memory and CPU wise. You've stated that there are only one instance of each object type in working memory, but are you absolutely sure of that? Cartesian joins can easily cause performance problems quite quickly.
For instance, say you've got these objects in working memory:
Subscriber(gender="male")
Subscriber(gender="female")
Service(name="ftp")
Service(name="http")
Product(id=1)
Product(id=2)
Product(id=3)
After inserting a Decision into working memory, the rule will fire 2*2*3 times. (#Subscribers * #Services * #Products) This is by design. Is this what you want?
3) Do you really need the 'Subscriber(gender == "male" or "female")' term? Why not just 'Subscriber()'? Are you classifying transgendered or nonhuman subscribers in your system?
--- On Mon, 7/20/09, nesta <nesta.fdb(a)163.com> wrote:
> From: nesta <nesta.fdb(a)163.com>
> Subject: Re: [rules-users] optimization on a lot of simple rules
> To: rules-users(a)lists.jboss.org
> Date: Monday, July 20, 2009, 10:22 AM
>
> I want to test the matching performance of drools. As I
> mentioned that there
> are a lot of rules and the rule is like:
> rule 1
> when
> Decision()
> Subscriber(gender ==
> "male" or "female")
> Service(name ==
> "ftp" or "http")
> Product(id == 1)
> ......
> then
> end
>
> After test, more condition elements under when, more time
> needs to execute
> the test.
> for example
> Location ( location == "home" or "office")
> and so on.
> So I worry about the matching performance with drools.
>
> I found that a lot of JoinNodes would be executed in
> runtime. I mean if
> there is 1000 rules, there will be a lot of JoinNodes
> (There are at least
> 1000 JoinNodes between Decision and Product ). And it
> exactly affects the
> execution performance.
>
> As you know, Decision, Product, Servcie and so on are plan
> Java classes. If
> I define all of attributes of above classes in one class
> named WholeFact,
> only one Java Type, there is no mentioned issue.
>
> With WholeFact class, the rule will be changed as follows:
> rule 1
> when
> WholeFact(
> subscriberGender == "male" or "female",
>
> serviceName
> == "ftp" or "http",
>
>
> productId == 1 or 2 or 3 ...
> )
> then
> end
>
>
> Greg Barton wrote:
> >
> >
> > Now this finally rises to something that needs rules.
> :) In all of the
> > previous examples you've given you could just have a
> > Map<ProductKey,Handler> where the Handler looks
> like this:
> >
> > interface Handler {
> > void handle(Product product, Decision
> decision);
> > }
> >
> > ...and the ProductKey consists of properties that
> uniquely identify how
> > the Product is handled. So, on it's own, that
> functionality did not
> > require rules.
> >
> > However, now that you've introduced more complex
> decisions, with varying
> > data, to affect the Decision for each Property type,
> rules are more
> > appropriate.
> >
> > Is there any reason why you only have one of each
> object type in memory at
> > one time? Maybe if you state more of the problem
> requirements we can help
> > you better.
> >
> > --- On Mon, 7/20/09, nesta <nesta.fdb(a)163.com>
> wrote:
> >
> >> From: nesta <nesta.fdb(a)163.com>
> >> Subject: Re: [rules-users] optimization on a lot
> of simple rules
> >> To: rules-users(a)lists.jboss.org
> >> Date: Monday, July 20, 2009, 4:14 AM
> >>
> >> Thanks very much.
> >> But if for every rule, there is one algorithm or
> discount
> >> which means that
> >> result has nothing related with Product's id and
> usage. I
> >> can't merge all
> >> rules in one rule. At the same time, besides
> Product and
> >> Decision fact type,
> >> there are more fact types.
> >> For example:
> >> rule 1
> >> when
> >> Decision()
> >> Subscriber(gender ==
> >> "male" or "female")
> >> Service(name ==
> >> "ftp" or "http")
> >> Product(id == 1)
> >> ......
> >> then
> >> ......
> >> end
> >> rule 2
> >> when
> >> Decision()
> >> Subscriber(gender ==
> >> "male" or "female")
> >> Service(name ==
> >> "ftp" or "http")
> >> Product(id == 2)
> >> ......
> >> then
> >> ......
> >> end
> >>
> >> .....
> >> .....
> >>
> >> In this scenario, if there are 1000 rules, there
> will
> >> be a lot of JoinNode.
> >> But in runtime, there is only one Decision
> instance, one
> >> Subscriber instance
> >> and Service instance.
> >>
> >> If I define all data in one fact type, I think
> that there
> >> are not a lot of
> >> JoinNodes.
> >>
> >> Is there any other method?
> >>
> >>
> >>
> >> Wolfgang Laun-2 wrote:
> >> >
> >> > Well, what is the realtion between id, usage
> and the
> >> result that's to be
> >> > stored in a Decision or a global?
> >> >
> >> > Typically, such rules could be written as
> >> >
> >> > rule x
> >> > no-loop true
> >> > when
> >> > $d : Decision()
> >> > $p :Product( id == 1, $usage :
> >> usage )
> >> > then
> >> > compute/store value, depending
> >> on the formula for id == 1 (using
> >> > usage)
> >> > end
> >> > // similar rule for id == 2,3,...
> >> >
> >> > If value is a straightforward function of id
> (and
> >> usage), then implement a
> >> > function compValue and use a single rule,
> e.g.:
> >> >
> >> > rule x
> >> > no-loop true
> >> > when
> >> > $d : Decision()
> >> > Product( $id : id, $usage :
> >> usage)
> >> > then
> >> > modify $d value to compValue( $id,
> $usage
> >> )
> >> >
> >> > Distinguishing all individual combinations of
> id and
> >> usage on the LHS
> >> > seems
> >> > excessive.
> >> >
> >> > The ordering of CEs also affects execution
> times.
> >> >
> >> > -W
> >> >
> >> > On 7/20/09, nesta <nesta.fdb(a)163.com>
> >> wrote:
> >> >>
> >> >>
> >> >> In this scenario, there are 1000
> products,
> >> different product has
> >> >> different
> >> >> price, besides this, the price is
> affected by
> >> usage. I want to use
> >> >> Product.id to match the rules.
> >> >>
> >> >> As you mentioned "The crude duplication
> of rules
> >> where only the constant
> >> >> to
> >> >> be matched with
> >> >> Product.id varies can, most likely, be
> avoided."
> >> >>
> >> >> How to avoid it in this scenario?
> >> >>
> >> >>
> >> >> Wolfgang Laun-2 wrote:
> >> >> >
> >> >> > It's difficult to suggest an
> optimized form
> >> for your rules 1-infinity,
> >> >> > since
> >> >> > we do not know what you want to
> achieve.
> >> >> >
> >> >> > The crude duplication of rules where
> only the
> >> constant to be matched
> >> >> with
> >> >> > Product.id varies can, most likely,
> be
> >> avoided.
> >> >> >
> >> >> > -W
> >> >> >
> >> >> >
> >> >> >
> >> >> > On Sun, Jul 19, 2009 at 3:15 PM,
> nesta <nesta.fdb(a)163.com>
> >> wrote:
> >> >> >
> >> >> >>
> >> >> >> Hi,
> >> >> >>
> >> >> >> I am a newbie in drools. There
> are a lot
> >> of simple rules in a
> >> >> scenario.
> >> >> >> For example
> >> >> >> rule 1
> >> >> >> when
> >> >> >> Product( id
> >> ==1, usage == 1)
> >> >> >> $decision :
> >> Decision()
> >> >> >> then
> >> >> >>
> >> $decision.setValue(1);
> >> >> >> end
> >> >> >>
> >> >> >> rule 2
> >> >> >> when Product( id ==2, usage ==
> 1)
> >> >> >> $decision : Decision()
> >> >> >> rule 3
> >> >> >> when Product( id ==3, usage ==
> 1)
> >> >> >> $decision : Decision()
> >> >> >> rule 4
> >> >> >> when Product( id ==4, usage ==
> 1)
> >> >> >> $decision : Decision()
> >> >> >> rule 5
> >> >> >> when Product( id ==5, usage ==
> 1)
> >> >> >> $decision : Decision()
> >> >> >> ......
> >> >> >>
> >> >> >> I have a Product fact whose id =
> 5 and
> >> usage = 1, in my first
> >> >> thinking,
> >> >> >> only
> >> >> >> rule 5 is matched, there should
> be not
> >> much more different between 1
> >> >> rule
> >> >> >> and a lot of rules in runtime.
> >> >> >>
> >> >> >> But the result shows that they
> are
> >> different. More rules will cost
> >> >> more
> >> >> >> time. If there are 1 thousand
> rules, some
> >> Node and Sink will execute 1
> >> >> >> thousand times.
> >> >> >>
> >> >> >> My question is how to optimize
> this
> >> scenario?
> >> >> >> --
> >> >> >> View this message in context:
> >> >> >>
> >> >>
> >> http://www.nabble.com/optimization-on-a-lot-of-simple-rules-tp24556724p24...
> >> >> >> Sent from the drools - user
> mailing list
> >> archive at Nabble.com.
> >> >> >>
> >> >> >>
> >> _______________________________________________
> >> >> >> rules-users mailing list
> >> >> >> rules-users(a)lists.jboss.org
> >> >> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >> >> >>
> >> >> >
> >> >> >
> >> _______________________________________________
> >> >> > rules-users mailing list
> >> >> > rules-users(a)lists.jboss.org
> >> >> > https://lists.jboss.org/mailman/listinfo/rules-users
> >> >> >
> >> >> >
> >> >>
> >> >> --
> >> >> View this message in context:
> >> >>
> >> http://www.nabble.com/optimization-on-a-lot-of-simple-rules-tp24556724p24...
> >> >> Sent from the drools - user mailing list
> archive
> >> at Nabble.com.
> >> >>
> >> >>
> _______________________________________________
> >> >> rules-users mailing list
> >> >> rules-users(a)lists.jboss.org
> >> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >> >>
> >> >
> >> >
> _______________________________________________
> >> > rules-users mailing list
> >> > rules-users(a)lists.jboss.org
> >> > https://lists.jboss.org/mailman/listinfo/rules-users
> >> >
> >> >
> >>
> >> --
> >> View this message in context:
> >> http://www.nabble.com/optimization-on-a-lot-of-simple-rules-tp24556724p24...
> >> Sent from the drools - user mailing list archive
> at
> >> Nabble.com.
> >>
> >> _______________________________________________
> >> rules-users mailing list
> >> rules-users(a)lists.jboss.org
> >> https://lists.jboss.org/mailman/listinfo/rules-users
> >>
> >
> >
> >
> >
> > _______________________________________________
> > rules-users mailing list
> > rules-users(a)lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
> --
> View this message in context: http://www.nabble.com/optimization-on-a-lot-of-simple-rules-tp24556724p24...
> Sent from the drools - user mailing list archive at
> Nabble.com.
>
>
> _______________________________________________
> rules-users mailing list
> rules-users(a)lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
16 years, 6 months