Execution time for drools5.0 against large data size
by ABRA2
Hi
I would like to test the time taken to run a single rule (eg.
HelloWorldExample from Drools5.0 documentation) against large data size (i.e
the object inserted in ksession is 10,000). The .drl file is loaded only
once and i am looping the part where message object is created and set with
values and inserted into ksession for 10,000 times. The time taken was 10.7
secs on an average. Am i doing something wrong? Can i improve it in anyway?
Your help is appreciated.
thanks
ABRA
HelloWorld.drl :
package org.drools.examples
import org.drools.examples.HelloWorldExample.Message;
global java.util.List list
rule "Hello World"
dialect "mvel"
when
m : Message( status == Message.HELLO, message : message)
then
System.out.println( message );
modify ( m ) { message = "Goodbye cruel world",
status = Message.GOODBYE };
end
rule "Good Bye"
dialect "java"
when
Message( status == Message.GOODBYE, message : message )
then
System.out.println( message );
end
HelloWorldExample.java
/**
* This is a sample file to launch a rule package from a rule source file.
*/
public class HelloWorldExample {
public static final void main(final String[] args) throws Exception {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory
.newKnowledgeBuilder();
// this will parse and compile in one step
kbuilder.add(ResourceFactory.newClassPathResource("HelloWorld.drl",
HelloWorldExample.class), ResourceType.DRL);
// 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);
final StatefulKnowledgeSession ksession = kbase
.newStatefulKnowledgeSession();
ksession.setGlobal("list", new ArrayList());
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugWorkingMemoryEventListener());
// setup the audit logging
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
.newFileLogger(ksession, "log/helloworld");
long starttime = System.currentTimeMillis();
for(int u=0;u<10000;u++)
{
final Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
ksession.insert(message);
ksession.fireAllRules();
}
long endtime = System.currentTimeMillis();
System.out.println("execution time is "+(endtime-starttime));
logger.close();
ksession.dispose();
}
public static class Message {
public static final int HELLO = 0;
public static final int GOODBYE = 1;
private String message;
private int status;
public Message() {
}
public String getMessage() {
return this.message;
}
public void setMessage(final String message) {
this.message = message;
}
public int getStatus() {
return this.status;
}
public void setStatus(final int status) {
this.status = status;
}
public static Message doSomething(Message message) {
return message;
}
public boolean isSomething(String msg, List list) {
list.add(this);
return this.message.equals(msg);
}
}
}
--
View this message in context: http://old.nabble.com/Execution-time-for-drools5.0-against-large-data-siz...
Sent from the drools - user mailing list archive at Nabble.com.
15 years
Performance hit in version 5.0?
by Duane Rosengartner
Group,
The following HelloWorld example is taken from the example code coming with the latest Drools downloads. One modification is the addition of the loop(10K times). Please note that the loading of the drl file is outside of this loop. Our developer tells us that this same example runs in 300milliseconds in Drools 2.0. Version 5.0 runs for 10 seconds. We have a large batch process that will suffer greatly if this is something we can't work around. Any ideas for performance gains in 5.0 will be greatly appreciated.
Duane
duane(a)proqualitysoft.com
public static final void main(final String[] args) throws Exception {
final KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
// this will parse and compile in one step
kbuilder.add(ResourceFactory.newClassPathResource("HelloWorld.drl",
HelloWorldExample.class), ResourceType.DRL);
// 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);
final StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
ksession.setGlobal("list", new ArrayList<Object>());
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugWorkingMemoryEventListener());
// setup the audit logging
KnowledgeRuntimeLogger logger = KnowledgeRuntimeLoggerFactory
.newFileLogger(ksession, "log/helloworld");
long starttime = System.currentTimeMillis();
for(int u=0;u<10000;u++)
{
final Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
ksession.insert(message);
ksession.fireAllRules();
}
long endtime = System.currentTimeMillis();
System.out.println("execution time is "+(endtime-starttime));
logger.close();
ksession.dispose();
}
15 years
DRLParser not parsing collections
by Ken Archer
I have successfully used DRLParser with several DRL files, except when they include the 'contains' syntax. My code for parsing DRL and then dumping into XML, is below:
public class DroolsDumper {
public static final void main(String[] args) throws DroolsParserException {
DrlParser parser = new DrlParser();
PackageDescr descr = parser.parse(new InputStreamReader(DroolsDumper.class.getResourceAsStream("/source.drl" )));
// Dump to xml rule.
XmlDumper dumper = new XmlDumper();
String result = dumper.dump(descr);
System.out.println(result);
}}
This code returns the following error when the DRL includes 'contains' syntax:
Exception in thread "main" java.lang.NullPointerException
at org.drools.xml.XmlDumper.visitPackageDescr(XmlDumper.java:224)
at org.drools.xml.XmlDumper.dump(XmlDumper.java:71)
at com.sample.DroolsDumper.main(DroolsDumper.java:19)
This code works fine with the following DRL (whether I dump the parsed DRL into XML or back into DRL):
rule 'cart rule'
dialect "mvel"
when
Cart ()
then
System.out.println("Hello World");
end
But it returns the above error when the same DRL includes 'contains':
rule 'cart rule'
dialect "mvel"
when
Cart (skus contains (123))
then
System.out.println("Hello World");
end
The DRL works fine in test scenarios and my cart class's array is declared simply as follows:
package shopping;
import java.util.ArrayList;
public class Cart {
public ArrayList<Integer> skus = new ArrayList<Integer>();
public ArrayList<Integer> getSkus() {
return skus;
}
public void setSkus(ArrayList<Integer> skus) {
this.skus = skus;
}
}
15 years
Ant build script and XLS Decision Tables failing
by Adam Rinehart
Has anyone been able to compile an XLS decision table into a package via an
Ant build script?
I've scouring the documentation on the Drools Ant Compiler Task (what little
I could find) and I can't find any documentation on hw to pass configuration
into the ant task for things such as compiling XLS decision tables.
Without a configuration entry, when I try and run the build script
referencing an excel file, it fails with the following error:
Buildfile: C:\Documents and
Settings\Adam\workspace\RivaDroolsExperiment\build-5.1.xml
compileArtifacts:
BUILD FAILED
C:\Documents and
Settings\Adam\workspace\RivaDroolsExperiment\build-5.1.xml:21: RuleBaseTask
failed: null
---------------
I suspect this message is because the compiler task is failing with a null
pointer exception, which it throws when you don't provide it with a
configuration file. I am running
the build3423-rev29890-20091102-1042 Drools 5.1 Snapshot.
The relevant snippet from the build script:
<target name="compileArtifacts">
<compiler srcdir="${projectPath}src/main/rules"
tofile="${projectPath}target/experiment.pkg" binformat="package"
bintype="knowledge" classpathref="model.classpath">
<include name="Sample.xls" />
</compiler>
</target>
------------------
Thanks,
Adam
15 years, 1 month
Strange MVEL error
by Shah, Malay
Hi All,
I am trying to compile a drool rule using MVEL dialect and getting the
following weird error.
Unable to determine the used declarations.
unbalanced braces (near code: << ... core1_entityOID); ...>>) (position:
33) : [Rule name=Legacy ETSDB Rule, agendaGroup=MAIN, salience=0,
no-loop=false]
org.mvel.ParseException: unbalanced braces (near code: << ...
core1_entityOID); ...>>) (position: 33)Unable to build expression for
'consequence'
The code I am trying to compile is:
package S_124
import com.ms.ieddata.dataQuality.violation.Violation;
import com.ms.ieddata.etsdb.model.EtsExecution_core;
import com.ms.ieddata.etsdb.model.EtsExecutionOrder_core;
global java.util.HashSet violations;
global java.util.HashSet violationKeys;
dialect "mvel"
rule "Legacy ETSDB Rule"
when
EtsExecution_core1:EtsExecution_core(crossInd == "1" , lastCapacity !=
"3" , lastDestinationID not in ("EUREX","IDEM","MEFF","LIFFE"))
EtsExecutionOrder_core1:EtsExecutionOrder_core(entityOID ==
EtsExecution_core1.parentOID , exDestination in ("I","L") ,
swapComponentType != "swaps" , orderCapacity not in
("D","R","X","L","E","T","C","O","P","S"),EtsExecutionOrder_core1_entity
OID:entityOID,EtsExecutionOrder_core1_application:application,EtsExecuti
onOrder_core1_entityVID:entityVID)
then
String key="S-124_EtsExecution_core" + "_entityVID_" +
"EtsExecutionOrder_core1_entityVID" + "_application_" +
"EtsExecutionOrder_core1_application" + "_entityOID_" +
"EtsExecutionOrder_core1_entityOID";
vPresent = violationKeys.contains(key);
if (!vPresent)
{
violation = new Violation();
violation.putRuleActionAttribute("ruleId","S-124");
violation.putRuleActionAttribute("ruleName","Legacy ETSDB Rule");
violation.putRuleActionAttribute("legacyRuleType","1");
violation.putRuleActionAttribute("entityName","EtsExecution_core");
violation.putRuleActionAttribute("fieldName","Field");
violation.putRuleActionAttribute("entityVID",EtsExecutionOrder_core1_ent
ityVID);
violation.putRuleActionAttribute("application",EtsExecutionOrder_core1_a
pplication);
violation.putRuleActionAttribute("entityOID",EtsExecutionOrder_core1_ent
ityOID);
}
end
The code works fine when I use java dialect. Also, if I remove the if
statement from consequence, the code get compiled in mvel and java
dialects. Am I missing something obvious here? I am using drools 4.0.1.
Thanks
Malay Shah
Morgan Stanley | IDEAS Practice Areas
750 Seventh Avenue, 6th Floor | New York, NY 10019
Phone: +1 212 762-4495
Malay.Shah(a)morganstanley.com
--------------------------------------------------------------------------
NOTICE: If received in error, please destroy, and notify sender. Sender does not intend to waive confidentiality or privilege. Use of this email is prohibited when received in error. We may monitor and store emails to the extent permitted by applicable law.
15 years, 1 month
generate jar with type declarations?
by strug
hi there!
i am asking myself if there is a way to get the compiled type declaration? i
found one thread that says that guvnor can do it.
what i want to do is s.th. like that:
- writing rules using dynamic facts (type declarations)
- generating a jar with the compiled type declarations
- using this jar inside a unit-test only
- having full code completion and strong typing
- avoid using "string-based" factType API
Regards, Leif
--
View this message in context: http://old.nabble.com/generate-jar-with-type-declarations--tp26163931p261...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 1 month
Synchronization requirements on newStatelessKnowledgeSession()?
by Laird Nelson
Are there any synchronization requirements on calling
knowledgeBase.newStatelessKnowledgeSession()? Must I synchronize on
anything to make this call in a multithreaded environment?
Once I have a StatelessKnowledgeSession, must I synchronize on anything to
work with it, or is it truly stateless in all regards?
I'm not sure my previous message on this topic was received properly.
Thanks,
Laird
15 years, 1 month
ProcessInstanceInfo.processInstanceId null with MySQL / Tomcat
by Barry K
Hello,
I am having an issue with persisting the Stateful Session in MySQL and
hopefully someone can help. I'll try and return the favor in the future.
:-)
I am running the following environment
Drools 5.1M1 (Stateful Rule Session with Persistence)
Tomcat 6
MySQL 5
When I run with a unit test the statefulsession is persisted correctly to
the MySQL database, but when I run in Tomcat I get a NullPointer because the
ProcessInstanceInfo.processInstanceId is null.
It appears that the tag @GeneratedValue(strategy = GenerationType.AUTO) is
not working for me when connecting to MySQL through a Tomcat pooled
connection.
The unit test is using a PoolingDataSource while Tomcat is using a resource
in Context.xml.
Has anyone seen a similar issue or can provide a direction for me to look?
Thanks for any help,
Barry
--
View this message in context: http://old.nabble.com/ProcessInstanceInfo.processInstanceId-null-with-MyS...
Sent from the drools - user mailing list archive at Nabble.com.
15 years, 1 month
ILog JRules to Drools Migration
by Simon
Has anybody ported a large number of rules from ILog JRules to Drools?
If yes, I'm very much interested in the following information:
- how did you do the migration (automatic vs. manual)?
- if automatic, how exactly (AST to AST transform, custom JRules
parser, ...)
- which features of JRules did you use (decision tables, rule
tasks, ...)?
- which migration issues did you encounter? how did you solve them?
- ...
Thanks
Simon
15 years, 1 month
Once the engine gets the package from guvnor, how to cache it and make it independent of guvnor.
by Wesley Akio Imamura
Hi,
I'm using this drools 5.0 scenario: agent using changeset file pointing to a
LATEST package guvnor URL.
The guvnor docs says how to start the agent resource scanning to make the
engine change aware:
- ResourceFactory.getResourceChangeNotifierService().start();
- ResourceFactory.getResourceChangeScannerService().start();
I suppose once the agent gets the packages from guvnor and caches it, it
should not need guvnor anymore unless there are changes. The agent could use
the cache and guvnor could be offline for a long time. This worked on
version 5 M1. You could even restart the engine and it started using the
cached version.
The problem I have with the latest 5.0 with new Knowledge classes ang
changeset.xml: when guvnor is offline, the resource scanning detects this
and unsubscribes the package, leaving the engine without any knowledge. When
guvnor is up again, the resource scanning cannot detect it, and the engine
remains without any knowledge.
How do I tell the agent to not unsubscribe url's that are offline, not to
remove their knowledge and just use the cache ?
Can I still configure the cache directory ?
Maybe the problem I have is that I'm using the LATEST packages and not
snapshots ?
The point here is to make the engine totally independent of Guvnor when it
got a package once.
Hope anyone can help me. Maybe I'll try version 5.1 to see what happens then
guvnor is down.
Thanks,
Wesley.
[2009:10:292 12:10:296:debug] ResourceChangeScanner attempt to scan 0
resources
--
Wesley Akio Imamura
São Paulo - SP - Brazil
15 years, 1 month