drools performance with <
by Tom Carchrae
Hello,
I'm new to Drools and am trying it out. I've found it easy enough so
far, but quickly ran into a performance bottleneck. (perhaps an all
too familiar story! :) ). So, I made a simple example to try and
track down the behavior. Here it is.
I wanted to create a rule that uses an < comparison between pairs of
objects. The following are the performance results:
10 objects. Java comparison took 0 ms
10 objects. Rule firing took 2516 ms
100 objects. Java comparison took 0 ms
100 objects. Rule firing took 1984 ms
1000 objects. Java comparison took 47 ms
1000 objects. Rule firing took 132500 ms
10000 objects. Java comparison took 4641 ms
10000 objects. Rule firing took .... (please wait...)
Here is the rule
rule "A < B"
when
a : TestObject( )
b : TestObject( valueDouble < a.valueDouble )
then
b.setValueint(b.getValueint()+1);
end
Now, I do understand that this (worst-case) is a comparison of N x N
objects... so, 1000 = 1000000 comparisons. However, ~100ms per
comparison seems relatively expensive for such a simple check. I am
using StatefulKnowledgeSession (I tried Stateless but this gave only a
mild performance improvement - and I would also like to use insert in
some of my rules).
How would one speed up such a query? I know part of the problem is
the < comparison. The results with == are much better (presumably, it
can do lots of pruning of the space)
Model creation 0
10 objects. Rule firing took 2829 ms
100 objects. Rule firing took 93 ms
1000 objects. Rule firing took 657 ms
10000 objects. Rule firing took 3375 ms
100000 objects. Rule firing took 33266 ms
I have thought about clever tricks that I could do to try and speed
things up, like sorting into groups, etc. But it all seems relatively
convoluted. Am I correct in coming to the conclusion that a <
comparison is not the kind of thing that you should do in Drools?
How would you go about this? I would prefer to keep all the logic in
the DRL files. I'm guessing you do a Java based comparison and use a
fire-once rule to invoke this code.
Thanks in advance for any insight,
Tom
15 years, 11 months
error on retracting fact on drools 5.0.1
by Garner, Shawn
I have a rule and it is supposed to retract two objects
when
$objectOne : ObjectOne(...)
$objectTwo : ObjectTwo(...)
then
retract($objectOne);
#retract($objectTwo);
end
No matter what I do I can't ever retract objectTwo.
I put a print statement and it is there.
If I comment out the retraction of objectTwo it works fine.
I tried just retraction of objectTwo and that fails too.
I tried prefixing with drools.retract.
I get this:
com.principal.health.rules.RulesException: Root exception: [Error: drools.retract($objectTwo): null]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0] - [Error: drools.retract($objectTwo): null]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at com.principal.health.rules.impl.DroolsRuleSetImpl.fireRuleflow(DroolsRuleSetImpl.java:100)
at com.principal.health.rules.RulesTestCase.executeRules(RulesTestCase.java:247)
at com.principal.health.rules.RulesTestCase.executeAvailableRules(RulesTestCase.java:129)
at com.principal.health.rules.impl.available.MemberNetworkXFormRulesRuleId6Test.retractMemberNetworkContractWithNullTeminationDates(MemberNetworkXFormRulesRuleId6Test.java:235)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at org.junit.internal.runners.TestMethodRunner.executeMethodBody(TestMethodRunner.java:99)
at org.junit.internal.runners.TestMethodRunner.runUnprotected(TestMethodRunner.java:81)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestMethodRunner.runMethod(TestMethodRunner.java:75)
at org.junit.internal.runners.TestMethodRunner.run(TestMethodRunner.java:45)
at org.junit.internal.runners.TestClassMethodsRunner.invokeTestMethod(TestClassMethodsRunner.java:71)
at org.junit.internal.runners.TestClassMethodsRunner.run(TestClassMethodsRunner.java:35)
at org.junit.internal.runners.TestClassRunner$1.runUnprotected(TestClassRunner.java:42)
at org.junit.internal.runners.BeforeAndAfterRunner.runProtected(BeforeAndAfterRunner.java:34)
at org.junit.internal.runners.TestClassRunner.run(TestClassRunner.java:52)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:38)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:460)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:673)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:386)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)
Caused by: org.drools.runtime.rule.ConsequenceException: [Error: drools.retract($wrappedNetwork): null]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:943)
at org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:885)
at org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1086)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:660)
at org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:627)
at org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:183)
at com.principal.health.rules.impl.DroolsRuleSetImpl.fireRuleflow(DroolsRuleSetImpl.java:91)
... 23 more
Caused by: [Error: drools.retract($wrappedNetwork): null]
[Near : {... Unknown ....}]
^
[Line: 1, Column: 0]
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:374)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.optimizeAccessor(ReflectiveAccessorOptimizer.java:138)
at org.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:133)
at org.mvel2.MVELRuntime.execute(MVELRuntime.java:85)
at org.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:104)
at org.mvel2.MVEL.executeExpression(MVEL.java:978)
at org.drools.base.mvel.MVELConsequence.evaluate(MVELConsequence.java:87)
at org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:934)
... 29 more
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:618)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.getMethod(ReflectiveAccessorOptimizer.java:931)
at org.mvel2.optimizers.impl.refl.ReflectiveAccessorOptimizer.compileGetChain(ReflectiveAccessorOptimizer.java:316)
... 36 more
Caused by: java.lang.AssertionError: null
at org.junit.Assert.fail(Assert.java:69)
at org.junit.Assert.assertTrue(Assert.java:32)
at org.junit.Assert.assertTrue(Assert.java:41)
at com.principal.health.rules.impl.available.MemberNetworkXFormRulesRuleId6Test$2.objectRetracted(MemberNetworkXFormRulesRuleId6Test.java:221)
at org.drools.impl.StatefulKnowledgeSessionImpl$WorkingMemoryEventListenerWrapper.objectRetracted(StatefulKnowledgeSessionImpl.java:501)
at org.drools.event.WorkingMemoryEventSupport.fireObjectRetracted(WorkingMemoryEventSupport.java:89)
at org.drools.common.AbstractWorkingMemory.retract(AbstractWorkingMemory.java:1186)
at org.drools.base.DefaultKnowledgeHelper.retract(DefaultKnowledgeHelper.java:158)
at org.drools.base.DefaultKnowledgeHelper.retract(DefaultKnowledgeHelper.java:172)
... 42 more
SDG
-----Message Disclaimer-----
This e-mail message is intended only for the use of the individual or
entity to which it is addressed, and may contain information that is
privileged, confidential and exempt from disclosure under applicable law.
If you are not the intended recipient, any dissemination, distribution or
copying of this communication is strictly prohibited. If you have
received this communication in error, please notify us immediately by
reply email to Connect(a)principal.com and delete or destroy all copies of
the original message and attachments thereto. Email sent to or from the
Principal Financial Group or any of its member companies may be retained
as required by law or regulation.
Nothing in this message is intended to constitute an Electronic signature
for purposes of the Uniform Electronic Transactions Act (UETA) or the
Electronic Signatures in Global and National Commerce Act ("E-Sign")
unless a specific statement to the contrary is included in this message.
While this communication may be used to promote or market a transaction
or an idea that is discussed in the publication, it is intended to provide
general information about the subject matter covered and is provided with
the understanding that The Principal is not rendering legal, accounting,
or tax advice. It is not a marketed opinion and may not be used to avoid
penalties under the Internal Revenue Code. You should consult with
appropriate counsel or other advisors on all matters pertaining to legal,
tax, or accounting obligations and requirements.
15 years, 11 months
Advice needed on a Design problem - Orderly execution of rules based on a ruleflow-group and a ruleflow "template" where rule-flow-group is only known at runtime
by Pritam
We have an interesting problem for our site design where we're using drools
as a filtering mechanism to "include" a specific content on the site
(content being a snippet of html).
I need to compile a knowledge base from a root folder, recursively.
- \site.drl
- \some-section\some-section.drl
- \some-section\some-page1.drl
- \some-section\some-page1-default.drl
- \some-section\some-page2.drl
- \some-section\some-page2-default.drl
- \some-section\.....
- \another-section\another-section.drl
- \another-section\blah-page1.drl
- \another-section\blah-page1-default.drl
- \another-section\blah-page2.drl
- \another-section\blah-page2-default.drl
- ....
Assume, a few hundred rule files from the above folder structure, each rule
file having rules with a ruleflow-group corresponding to it's folder
structure.
At any point, if I fire the rules (using StatelessKnowledgeSession), I
expect a rule flow something this:
<START>
|
site
|
section*
|
<XOR>
/ \
page* page-default*
\ /
\ /
<JOIN>
|
<END>
* this ruleflow-group name is dynamic (corresponding to its folder
structure)
As you see, I have a "template" for a rule-flow execution, but my
ruleflow-group name is only known at runtime since it's dependent on the
underling folder structure and not known at ruleflow-definition. I do
however know the folder structure before execution (since you can always
build this via file io using a bootstrap into memory) and the name of the
rule file since I follow a strict naming convention matching the URI of the
http request (which in turn matches the file structure).
How do I build this kind of rule flow execution using rule-flows? Can I
programmatically construct the rule flow and store it in memory?
Also, assume a knowledge base of hundreds of rules, how do I execute a
specific rulegroup using the StatelessKnowledgeSession api (I can't see any)
from that KnowledgeBase?
Thanks
--
View this message in context: http://n3.nabble.com/Advice-needed-on-a-Design-problem-Orderly-execution-...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 11 months
Problems with GWT WebProject and Drools5.0!
by vamshidhar reddy chitti
Hi All,
I have integrated drools rule engine 5.0 with GWT WebProject. When I try to call the rule engine from GWT Applicaiton Engine, I get following exception
java.security.AccessControlException: access denied (java.io.FilePermission C:\Documents and Settings\vamshidharc\drools.packagebuilder.conf read)
at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)
at java.security.AccessController.checkPermission(AccessController.java:546)
at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)
at com.google.appengine.tools.development.DevAppServerFactory$CustomSecurityManager.checkPermission(DevAppServerFactory.java:139)
at java.lang.SecurityManager.checkRead(SecurityManager.java:871)
at java.io.File.exists(File.java:731)
at org.drools.util.ChainedProperties.loadProperties(ChainedProperties.java:243)
at org.drools.util.ChainedProperties.<init>(ChainedProperties.java:69)
at org.drools.util.ChainedProperties.<init>(ChainedProperties.java:41)
at org.drools.compiler.PackageBuilderConfiguration.init(PackageBuilderConfiguration.java:167)
at org.drools.compiler.PackageBuilderConfiguration.<init>(PackageBuilderConfiguration.java:153)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:242)
at org.drools.compiler.PackageBuilder.<init>(PackageBuilder.java:142)
at org.drools.builder.impl.KnowledgeBuilderProviderImpl.newKnowledgeBuilder(KnowledgeBuilderProviderImpl.java:29)
at org.drools.builder.KnowledgeBuilderFactory.newKnowledgeBuilder(KnowledgeBuilderFactory.java:29)
at com.cura.test.server.RuleEngineInvoker.readKnowledgeBase(RuleEngineInvoker.java:72)
at com.cura.test.server.RuleEngineInvoker.invokeRuleEngine(RuleEngineInvoker.java:51)
at com.cura.test.server.GreetingServiceImpl.getDept(GreetingServiceImpl.java:25)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at com.google.gwt.user.server.rpc.RPC.invokeAndEncodeResponse(RPC.java:527)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.processCall(RemoteServiceServlet.java:166)
at com.google.gwt.user.server.rpc.RemoteServiceServlet.doPost(RemoteServiceServlet.java:86)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:487)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1093)
at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:121)
at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1084)
at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:360)
at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:181)
at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:712)
at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:405)
at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:54)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:313)
at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:139)
at org.mortbay.jetty.Server.handle(Server.java:313)
at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:506)
at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:844)
at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:644)
at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:205)
at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:381)
at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:396)
at org.mortbay.thread.BoundedThreadPool$PoolThread.run(BoundedThreadPool.java:442)
does anyone hav idea?
tnx in advance
bye
vamshi
15 years, 11 months
Integrating rules with your applications +Changeset.xml
by Nilima R
Can anyone explain/example how to use changeset.xls to integrate with the
rules I have written in Guvnor.Need to use Drools API for Integrating
rules with java application
At present am using the below code
Properties properties = new Properties();
InputStream stream = rulesServlet.class
.getResourceAsStream ("/com/opensource/rules.properties");
properties.load(stream);
RuleAgent agent = RuleAgent.newRuleAgent
(properties);
RuleBase base = agent.getRuleBase();
FactType customer = base.getFactType(
"myPackage.Customer");
Object cust1 = customer.newInstance();
customer.set(cust1, "totalIntemsPrice", price);
base.newStatelessSession().execute(cust1);
System.out.println("Discount is a "+
customer.get(cust1, "discount"));
The documentation is not pretty clear.
Nilima
____________________________________________
Experience certainty. IT Services
Business Solutions
Outsourcing
____________________________________________
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
15 years, 11 months
JIRA case for parser errors with nested boolean prefixAnd/Or expressions
by Axelrod, Nelson
Hi Edson,
I added the JIRA ticket below regarding the bug with the nested
prefixAnd/Or expressions
https://jira.jboss.org/jira/browse/JBRULES-2414
as a subticket to a similar issue described here
https://jira.jboss.org/jira/browse/JBRULES-2383
Thank you!
Nelson
------------------------------
Message: 4
Date: Tue, 19 Jan 2010 17:01:41 -0500
From: Edson Tirelli <ed.tirelli(a)gmail.com>
Subject: Re: [rules-users] rules-users Digest, Vol 38, Issue 58
To: Rules Users List <rules-users(a)lists.jboss.org>
Message-ID:
<e6dd5ba31001191401r67ddf877o7e9619ba0d23b281(a)mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"
Yes, the good news is that it is clearly a parsing error, what makes
it
easy to fix. Do you mind opening a JIRA and attaching a test case or the
info from your e-mails?
Thanks,
Edson
15 years, 11 months
Accumulate + Temporal Operators
by Paul R.
Hi,
I'm using accumulate with sliding windows to verify that certain event
conditions are present for a specified period of time, which works fine,
however
I need to verify that both conditions are present at the same time, i.e
Foo.value > 1 for 10 seconds and Bar.value < 1 for 10 seconds. There doesn't
appear to be an obvious way to use the temporal operators in this situation.
Can anybody offer any suggestions?
rule test no-loop true
when
$f : Double(doubleValue > 1.0) from accumulate( Foo($v : value) over
window:time ( 10s )
from entry-point EntryPoint, min($v))
$b : Double(doubleValue < 1.0) from accumulate( Bar($v : value) over
window:time ( 10s )
from entry-point EntryPoint, max($v))
then
// ...
end
Any help greatly appreciated.
Thanks,
Paul
15 years, 11 months