Re: [rules-users] Using Drools as a glorified Hashmap
by John Peterson
How many match rules do you have? You could always set a single
"invalid" rule with a low salience (at least lower than your match
rules) that is always true and sets the flag that it is invalid. Then
put all the rules into the same activation-group so that only one can
fire. If the invalid flag is set, that means that the 'no match' rule
was the only one that could have fired. If it matches, the
activation-group will prevent the 'no match' rule from firing....
------------------------------
Message: 3
Date: Tue, 18 May 2010 02:56:21 -0700 (PDT)
From: djb <dbrownell83(a)hotmail.com>
Subject: [rules-users] Using Drools as a glorified Hashmap
To: rules-users(a)lists.jboss.org
Message-ID: <1274176581461-825851.post(a)n3.nabble.com>
Content-Type: text/plain; charset=us-ascii
Hi Drools users,
I've got a situation where I've got a list of Drug codes which can only
be
used for certain prescription codes.
The traditional method for implementing this is to simply pre-load the
values in a static Hashmap. Then if get() returns null, it is not a
valid
combination. O(1), blazingly fast.
The issue with using Drools for this, is that Drools can match a code to
a
code, and mark it as valid, but cannot call it invalid, as another rule
may
still be relevant. Therefore, using Drools for this would require
marking
combinations as valid, and afterwards, doing a linear traversal of the
prescriptions to see if there are any combinations that are not valid.
Is this the case? I would like to try implement it in Drools just for
the
sake of consistency, but it seems a bit of a hack.
Thanks,
Daniel
--
View this message in context:
http://drools-java-rules-engine.46999.n3.nabble.com/Using-Drools-as-a-gl
orified-Hashmap-tp825851p825851.html
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 9 months
Event expiration doubt
by Makewise - Vitor Rui Mendonça
Hi!
I've detected some problems in my rules regarding event expiration but I can't understand why. Maybe someone with more experience could help me out.
I think the example is quite simple: the application receives transactions. The lack of transactions for an hour should raise an alarm. If there's a transaction when the alarm is on, then the application should rearm, clear the alarm state and check for lack of transactions.
The rules:
package com.company.application;
import com.company.application.Notifier;
import com.company.application.Notification;
import com.company.application.Transaction;
dialect "java"
# event which represents an alarm state
declare NoTransactions
@role( event )
dummy1: long
end
# event which represents the start of drools engine
declare EngineStarted
@role( event )
dummy2 : long
end
# event which represents the need to check for absence of transactions for the first hour
declare CheckFirstTransaction
@role( event )
@expire( 1h )
dummy3: long
end
# event which represents a Transaction
declare Transaction
@role( event )
@expires( 1h )
end
# Notification System
global Notifier notifier;
rule "***start***"
when
not( EngineStarted() )
then
insert( new EngineStarted() );
insert( new CheckFirstTransaction() );
end
rule "***notrx_after_start***"
when
$engineStarted : EngineStarted()
$checkFirstTransaction : CheckFirstTransaction()
not( NoTransactions() )
not( Transaction( this after[0s,1h] $engineStarted ) from entry-point "incoming" )
then
insert ( new NoTransactions() );
retract( $checkFirstTransaction );
notifier.send( new Notification( "ALARM" ) );
end
rule "***notrx_after_trx***"
when
EngineStarted()
not( NoTransactions() )
$transaction: Transaction() from entry-point "incoming"
not( Transaction( this != $transaction, this after [0s,1h] $transaction ) from entry-point "incoming" )
then
insert( new NoTransactions());
notifier.send( new Notification( "ALARM" ) );
end
rule "***rearm***"
when
EngineStarted()
$noTransactions : NoTransactions()
$transaction: Transaction( this after $noTransactions ) from entry-point "incoming"
then
retract( $noTransactions );
notifier.send( new Notification( "REARM" ) );
end
The unit test:
kSession.fireAllRules(); // needed to detect lack of transactions in the first hour
/* here, "***start***" rule fires => "EngineStarted" and "CheckFirstTransaction" inserted */
clock.advanceTime( 1, TimeUnit.HOURS );
/* here, "***notrx_after_start***" rule fires => "NoTransactions" inserted, "CheckFirstTransaction" retracted */
clock.advanceTime(10, TimeUnit.MINUTES );
entryPoint.insert( new Transaction() );
/* before inserting "Transaction" into EntryPoint, "NoTransactions" is retracted */
kSession.fireAllRules();
The problem:
After inserting the last transaction, automatically the NoTransactions event is retracted. Debugging inside drools-core project, I've discovered that the event was retracted because expiration (WorkingMemoryReteExpireAction on actionQueue).
I've also found some more explain how expiration events works, by Edison (http://drools-java-rules-engine.46999.n3.nabble.com/Events-are-not-automa...). That shed some light on *when* the event is retracted but I don't understand *why* it's retracted.
Thanks In Advance!
Vítor Mendonça Moreira
Analista / Programador
Direcção de Investigação e Desenvolvimento
Rua Dr. Francisco Sá Carneiro, nº. 4 r/c esq.
2500 - 206 - Caldas da Rainha
Tel: (+351) 262 832 196
Fax: (+351) 262 186 455
Web: www.makewise.pt <http://www.makewise.pt>
Uma empresa: Grupo Sousa Pedro <http://www.sousapedro.com>
15 years, 9 months
Optimizing the size of a StatefulKnowledgeSession object.
by Johannes Meier
Dear Drools' developers and users,
I have a problem regarding the size of my Drools' StatefulKnowledgeSession.
As I'm working with a 'stateful' session that lives on a web server I have
bound this session onto my web session. That means the Drools' session is
able to access some facts from preceding calls. The Drools' session lives as
long as the web session lives.
So far so good. Now I've started to mesure the size of the
StatefulKnowledgeSession by usage of heap dumps and some profiling tools.
This yielded a size of approximately 5 MB.
Is there any approach to optimize the size of a StatefulKnowledgeSession?
Apparently this object has a lot of overhead (from my point of view)
regarding the Drools Flow and Gouvenor frameworks because I'm not utilizing
this frameworks at all (just Drools Expert). Maybe this is an approach to
optimize the session's size?
If I accept this size, is there a convenient way to serialize the
StatefulKnowledgeSession between calls? I'm thinking about storing the whole
StatefulKnowledgeSession inside the database or maybe some datastructure
apart from the websession. Every call inside one web session would have to
lead to a deserialization, application and serialization of Drools' session.
Thank you in advance for any reply.
Kind regards!
Johannes
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Optimizing-the-size-o...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 9 months
Re: [rules-users] Jbilling Drools performance
by Greg Barton
See attached project, DroolsBilling.
You can build it with Maven from the project directory: mvn clean package
To run it after building: java -jar target/DroolsBilling-1.0.jar <numRules> <numPhoneNumbersPerThread>
$ java -server -jar target/DroolsBilling-1.0.jar 100 100000Rules load time: 3482msRules execution time: 732ms, per number: 0.00732msRules execution time: 731ms, per number: 0.00731msRules execution time: 746ms, per number: 0.00746msRules execution time: 760ms, per number: 0.0076msRules execution time: 832ms, per number: 0.00832msRules execution time: 623ms, per number: 0.00623msRules execution time: 600ms, per number: 0.0060msRules execution time: 632ms, per number: 0.00632msRules execution time: 630ms, per number: 0.0063msRules execution time: 607ms, per number: 0.00607msDONE!
At higher numbers of rules you have to increase the perm gen and heap memory:
$ java -server -Xmx1024M -XX:MaxPermSize=128M -jar target/DroolsBilling-1.0.jar 10000 100000Rules load time: 58317msRules execution time: 1580ms, per number: 0.0158msRules execution time: 1580ms, per number: 0.0158msRules execution time: 1586ms, per number: 0.01586msRules execution time: 2493ms, per number: 0.02493msRules execution time: 2502ms, per number: 0.02502msRules execution time: 1360ms, per number: 0.0136msRules execution time: 1358ms, per number: 0.01358msRules execution time: 1376ms, per number: 0.01376msRules execution time: 473ms, per number: 0.00473msRules execution time: 489ms, per number: 0.00489msDONE!
As you can see the time to process one phone number is lower than 1 minute. :) The example uses 5 concurrent threads and was executed on a 4 core machine.
A Sample.drl is included that shows the format of the rules generated, basically this:
rule "PhoneNumber000000000" when p : PhoneNumber( digit0 == '0', digit1 == '0', digit2 == '0', digit3 == '0', digit4 == '0', digit5 == '0', digit6 == '0', digit7 == '0', digit8 == '0', digit9 == '0') then p.setPrice(0.0);end
They should be substantially similar to the rules generated behind the decision table you've given, so the performance should be similar. As you can see from the times above, rule creation is expensive but execution is cheap. As Mark said, reuse the KnowledgeBase.
--- On Tue, 5/18/10, Antonio Anderson Souza <antonio(a)voicetechnology.com.br> wrote:
From: Antonio Anderson Souza <antonio(a)voicetechnology.com.br>
Subject: Re: [rules-users] Jbilling Drools performance
To: "Rules Users List" <rules-users(a)lists.jboss.org>
Date: Tuesday, May 18, 2010, 4:11 PM
Greg,
CDR is a Call Detail Record, sorry I forgot to explain it, the object is
a POJO with the following attributes:
field: name: datereference type: DATE value: 2010-04-28 00:00:00.0
field: name: billingid type: STRING value: 20100428.15544.42adf
field: name: accountid type: INTEGER value: 15544
field: name: billingperiod type: STRING value: 20100401
field: name: billingclassification type: STRING value: DUR
field: name: ipxcallguid type: STRING value:
5k692927-guwtka-g8kj8d0u-1-g8krry54-o4n
field: name: transactiondatetime type: DATE value: 2010-04-28
20:21:01.337
field: name: billingitemid type: INTEGER value: 0
field: name: ratesystem type: STRING value: IPXNET
field: name: originnumber type: STRING value:
551135880520(a)bitcompany.braste
field: name: destinationnumber type: STRING value: 551139012650
field: name: destinationareaid type: STRING value: 100000551
field: name: chargedduration type: DATE value: 1980-01-01 00:02:06.0
field: name: chargedamount type: FLOAT value: 0.0816
field: name: userid type: INTEGER value: 3372
field: name: username type: STRING value: bitcom51
field: name: unitamount type: FLOAT value: 0.00389
field: name: amountcurrency type: STRING value: USD
field: name: timezone type: INTEGER value: -3
field: name: registertype type: STRING value: MV
field: name: datelastupdated type: DATE value: 2010-04-29 02:57:18.54
field: name: lastupdatedby type: STRING value: IPXRateCalls rev032
field: name: lastupdateremarks type: STRING value: null
field: name: dateinserted type: DATE value: 2010-04-29 02:57:18.54
field: name: destinationdetail type: STRING value: SAO PAULO
field: name: type type: STRING value: Fixo
field: name: collectedcallflag type: INTEGER value: 0
field: name: jb_timestamp type: DATE value: null
field: name: digit0 type: INTEGER value: 5
field: name: digit1 type: INTEGER value: 5
field: name: digit2 type: INTEGER value: 1
field: name: digit3 type: INTEGER value: 1
field: name: digit4 type: INTEGER value: 3
field: name: digit5 type: INTEGER value: 9
field: name: digit6 type: INTEGER value: 0
field: name: digit7 type: INTEGER value: 1
field: name: digit8 type: INTEGER value: 2
field: name: digit9 type: INTEGER value: 6
field: name: digit10 type: INTEGER value: 5
field: name: digit11 type: INTEGER value: 0
This spreadsheet is only a sample because the whole one has 40000 rules, I'm checking the Jbilling code, but it seams to be loading the rules each time.
Best regards,
Antonio Anderson Souza
Voice Technology
http://www.antonioams.com
2010/5/18 Greg Barton <greg_barton(a)yahoo.com>
OK, so a few questions:
What is a CDR? How much data does it contain? Do you load the rules fresh each time you process one? Are there other rules besides the ones listed in the decision table?
15 years, 9 months
removeKnowledgePackage Call Hangs!!
by malkhafaji
I am trying to unload a KnowledgePackage that is already loaded in my
KnowledgeBase. The call:
this.knowledgeBase.removeKnowledgePackage(knowledgePackage.getName());
hangs (never returns). I had a similar problem with adding a
KnowledgePackage to a KnowledgeBase and someone on here suggested that there
was a synchronization problem in the internal implementation of the add
method in the KnowledgeBase class, and that problem went away when I
downloaded M1 files (from Feburary 10th of this year). However, I just got
to test the removing of the KnowledgePackage and I seem to have a similar
problem (?).
Here is my unload rule:
rule "MyRule 1.0"
when
mpr : MyObject()
eval(mpr.isKnowledgeBaseLoaded("ACTIVE_KP"))
then
mpr.print("Rule MyRule 1.0 Executed");
mpr.removeKnowledgeBase("ACTIVE_KP");
end
The statement "Rule MyRule 1.0 Executed" is printed, and I am able to debug
the code all the way to the line outlined above, and that is when it goes in
a black hole. Any ideas why this is happening? Is this something fixed in
M2? Here is the log:
INFO|11904/0|10-05-13 13:19:54|Exception in thread "Thread-5"
org.drools.runtime.rule.ConsequenceException: rule: MyRule 1.0
INFO|11904/0|10-05-13 13:19:54|
INFO|11904/0|10-05-13 13:19:54| at
org.drools.runtime.rule.impl.DefaultConsequenceExceptionHandler.handleException(DefaultConsequenceExceptionHandler.java:23)
INFO|11904/0|10-05-13 13:19:54| at
org.drools.common.DefaultAgenda.fireActivation(DefaultAgenda.java:981)
INFO|11904/0|10-05-13 13:19:54| at
org.drools.common.DefaultAgenda.fireNextItem(DefaultAgenda.java:918)
INFO|11904/0|10-05-13 13:19:54| at
org.drools.common.DefaultAgenda.fireAllRules(DefaultAgenda.java:1130)
INFO|11904/0|10-05-13 13:19:54| at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:739)
INFO|11904/0|10-05-13 13:19:54| at
org.drools.common.AbstractWorkingMemory.fireAllRules(AbstractWorkingMemory.java:705)
INFO|11904/0|10-05-13 13:19:54| at
org.drools.impl.StatefulKnowledgeSessionImpl.fireAllRules(StatefulKnowledgeSessionImpl.java:200)
INFO|11904/0|10-05-13 13:19:54| at
com.medcpu.mpu.pp.engine.Drools.fireRules(Drools.java:459)
INFO|11904/0|10-05-13 13:19:54| at
com.medcpu.mpu.MpuExecutor.executeRules(MpuExecutor.java:191)
INFO|11904/0|10-05-13 13:19:54| at
com.medcpu.mpu.MpuExecutor.initiateRuleExecution(MpuExecutor.java:431)
INFO|11904/0|10-05-13 13:19:54| at
com.medcpu.mpu.MpuExecutor.propertyChanged(MpuExecutor.java:147)
INFO|11904/0|10-05-13 13:19:54| at
com.medcpu.mpu.MpuExecutor.run(MpuExecutor.java:498)
INFO|11904/0|10-05-13 13:19:54| at
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
INFO|11904/0|10-05-13 13:19:54| at
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
INFO|11904/0|10-05-13 13:19:54| at java.lang.Thread.run(Unknown Source)
INFO|11904/0|10-05-13 13:19:54|Caused by: java.lang.NullPointerException
INFO|11904/0|10-05-13 13:19:54| at
org.drools.reteoo.RuleTerminalNode.doRemove(RuleTerminalNode.java:369)
INFO|11904/0|10-05-13 13:19:54| at
org.drools.common.BaseNode.remove(BaseNode.java:95)
INFO|11904/0|10-05-13 13:19:54| at
org.drools.reteoo.ReteooBuilder.removeRule(ReteooBuilder.java:237)
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/removeKnowledgePackag...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 9 months
Error when Loading New KnowledgeBuilder
by Ken Archer
I just built installed the Drools Eclipse plug-in on a new development machine, and now whenever I load a new KnowledgeBuilder (KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();), the source of PackageBuilderConfiguration.class loads in a new tab with the following lines before the code:
Class File Editor
Source not found
The JAR of this class file belongs to container 'Drools Library' which does not allow modifications to source attachments on its entries.
The default 5.0.1 Drools Runtime jars are in the Drools Library path, just like on my previous development machine. Any thoughts?
Ken Archer
15 years, 9 months
Jbilling Drools performance
by Antonio Anderson Souza
Dear All,
I'm deploying a JBilling using Drools in a Telecom Carrier in Brazil, and
I'm using Decision tables in xls files to execute the pricing, my pricing
table has about 40.000 rules, and I'm getting a terrible performance about
1.5 minute to execute the price of each CDR (Call Detail Record) mediated.
Follow bellow a small piece of my decision table:
*RuleTable Padrao* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
* *
*
*CONDITION* *CONDITION* *ACTION* *PRIORITY * *PricingField* *
PricingManager* *manager* *salience* name eval (strValue.charAt(0) ==
'$param') eval (strValue.charAt(1) == '$param') eval (strValue.charAt(2) ==
'$param') eval (strValue.charAt(3) == '$param') eval (strValue.charAt(4) ==
'$param') eval (strValue.charAt(5) == '$param') eval (strValue.charAt(6) ==
'$param') eval (strValue.charAt(7) == '$param') eval (strValue.charAt(8) ==
'$param') eval (strValue.charAt(9) == '$param') eval (strValue.charAt(10) ==
'$param') eval (strValue.charAt(11) == '$param') itemId setPrice($param)
Campo Digito1 Digito2 Digito3 Digito4 Digito5 Digito6 Digito7 Digito8
Digito9 Digito10 Digito11 Digito12 ID do Item Preço Ordem destinationnumber
5 5 1 1 3 5 8 8 0 1 8 8 300 0.00000 1 destinationnumber 5 5 1 1 3 5 8 8 0 1
8 7 300 0.00000 2 destinationnumber 5 5 1 1 3 5 8 8 0 1 8 6 300 0.00000 3
destinationnumber 5 5 1 1 3 5 8 8 0 1 8 5 300 0.00000 4 destinationnumber 5
5 1 1 3 5 8 8 0 1 8 4 300 0.00000 5 destinationnumber 5 5 1 1 3 5 8 8 0 1 8
3 300 0.00000 6 destinationnumber 5 5 1 1 3 5 8 8 0 1 8 2 300 0.00000 7
destinationnumber 5 5 1 1
300 0.40000 8
Is it normal? Are there somebody using Jbilling in a similar way? Does
anybody can help me?
Best regards,
Antonio Anderson Souza
Voice Technology
http://www.antonioams.com
15 years, 9 months
Potential Deadlock using fireUntilHalt and signalEvent
by mardo
Hi there,
I am facing the following situation: In a few words, I have the following
separate Threads running:
- a fireUntilHalt() on the StatefulKnowledgeSession --> Thread-1 in the
picture
- a recurrent insertion of events into the knowledge base --> Thread-main in
the picture
- a custom asynchroneous WorkItemHandler, which does some fake work and then
signalizes completion to the flow engine (Threads 3&4 in the picture).
It is often the case that my program runs into a deadlock.
My impression is, that fireUntilHalt() (Thread1) gets the synchronized
monitor on AbstractWorkingMemory.actionQueue in line 1411 , while the
WorkItemManager (Thread3) gets the monitor on NamedEntryPoint in line 120.
When fireUntilHalt() then tries to get the monitor on NamedEntryPoint in
line 260, while the WorkItemManager tries to get the monitor on
AbstractWorkingMemory.actionQueue in line 1411, we have a deadlock.
Please correct me if there is any misunderstanding from my side regarding
the synchronization concepts.
Thanks and best
Markus
15 years, 9 months
How to find ALL active sub/processes for a root process instance?
by tolitius
Having several active processes ( parent + its subprocesses + subprocesses of
the parent subproccesses ):
mysql> select InstanceId, processId, state from processinstanceinfo;
+------------+--------------------------------+-------+
| InstanceId | processId | state |
+------------+--------------------------------+-------+
| 1 | main-flow | 1 |
| 2 | first-level-subprocess-flow | 1 |
| 3 | second-level-subprocess-flow | 1 |
+------------+--------------------------------+-------+
Having a parent process instance ID, how to programmatically (using the out
of the box framework capabilities) find all _active_ subprocesses? [ of all
levels, e.g. including subprocesses of the parent subprocesses ]?
I would think that the answer is:
StatefulKnowledgeSession session =
knowledgeProvider.loadStatefulKnowledgeSession( sessionId );
WorkflowProcessInstance parentProcess = ( WorkflowProcessInstance )
session.getProcessInstance( processInstanceId );
for ( NodeInstance node : parentProcess.getNodeInstances() ) {
.... ... ...
}
But no, it only returns a one level of subprocesses.
So two(2) questions here:
1. How to programmatically, using OTB framework features get them?
2. Why does not processInstance"Info" have "Info" about a sub process,
like a PARENT_ID?
Thank you,
/Anatoly
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/How-to-find-ALL-activ...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 9 months
Using Drools as a glorified Hashmap
by djb
Hi Drools users,
I've got a situation where I've got a list of Drug codes which can only be
used for certain prescription codes.
The traditional method for implementing this is to simply pre-load the
values in a static Hashmap. Then if get() returns null, it is not a valid
combination. O(1), blazingly fast.
The issue with using Drools for this, is that Drools can match a code to a
code, and mark it as valid, but cannot call it invalid, as another rule may
still be relevant. Therefore, using Drools for this would require marking
combinations as valid, and afterwards, doing a linear traversal of the
prescriptions to see if there are any combinations that are not valid.
Is this the case? I would like to try implement it in Drools just for the
sake of consistency, but it seems a bit of a hack.
Thanks,
Daniel
--
View this message in context: http://drools-java-rules-engine.46999.n3.nabble.com/Using-Drools-as-a-glo...
Sent from the Drools - User mailing list archive at Nabble.com.
15 years, 9 months