Drools spawning a lot of JIT threads
by Frank Pavageau
Hi.
I'm using Drools 5.5 in a web application, upgraded a few months ago from
5.1. When starting multiple instances of the application on a server *at
the same time*, I recently noticed some problems with the JVMs complaining
of not being able to create native threads.
The stack trace led to Drools, and more specifically MvelConstraint
submitting JIT tasks to an Executor through its jitEvaluator() method. The
Executor is created by ExecutorProviderImpl and is a basic
CachedThreadPool, which means it can create an unbounded number of threads
(which then die after idling for a minute). In my case, it apparently meant
around 900 threads per JVM, which multiplied by the number of running JVMs
saturated the OS for a short while.
Has anyone else been bitten by this? Should there be a more reasonable
default implementation and should I create an issue for this?
I then have a question related to how I fixed this: I created my own
implementation of ExecutorProvider by extending ExecutorProviderImpl and
creating a ThreadPoolExecutor with an upper bound on the number of threads
and a LinkedBlockingQueue to queue the tasks when all the threads are
already busy. That works fine, the only problem is telling Drools to use my
implementation: the only way I've found is by
calling ServiceRegistryImpl.getInstance().registerLocator().
ServiceRegistryImpl implements ServiceRegistry, but the interface doesn't
seem to be exposed through Drools' more public API; it seems a bit wrong to
call the implementing class directly to get its instance, especially given
the Javadoc which states "This is an internal class, not for public
consumption". Am I missing something?
Regards,
Frank
10 years, 7 months
Re: [rules-users] java.lang.NoSuchMethodError thrown in drools api
by DE_Azrael
Good morning !
@snak: That was the first hint I found during my investigation but it could
not be the failure.
It could not be a problem of version incompatibility. As I wrote the
transaction was working 4 times and failed at the 5th transaction
(reproducable).
If it would be a problem of incompatibility no transaction could be
successful.
>From the error stack I was wondering why it was saying
ConditionEvaluatorf4a3f354729241ac8370890200fdf2d8.evaluate(Unknown Source)
Guess this class is generated automaticly and the source that is missing at
this point is the kbase.
I checked again the initialisation of kbase and I found a failure.
The kbase is defined as static and is beeing initialised with the first
transaction. Additionaly it's beeing updated every few minutes.
After I corrected this the failure disappear.
I did the following changes:
*old code:*
if ((knowledgeSetupTimestamp + timeInMillis) < System.currentTimeMillis())
ageReload = true;
if ((kbase == null) || ageReload) {
synchronized (DroolsHelper.class) {
if ((kbase == null) || ageReload) {
.........
}
}
}
*new corrected code:*
if ((kbase == null) || (knowledgeSetupTimestamp + timeInMillis <
System.currentTimeMillis())) {
synchronized (DroolsHelper.class) {
if ((kbase == null) || (knowledgeSetupTimestamp + timeInMillis <
System.currentTimeMillis())) {
.........
}
}
}
I'm still a bit puzzled about the reported failure and it would be great if
someone could explain me this behaviour.
Thanks a lot !
Cheers Johannes
--
View this message in context: http://drools.46999.n3.nabble.com/java-lang-NoSuchMethodError-thrown-in-d...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 7 months
KieScanner with Maven 3
by Maxime Falaize
Hello,
Does the KieScanner support Maven 3? I noted that LATEST, RELEASE and
SNAPSHOT metaversions for Maven are no longer supported by Maven 3 so do I
have to understand that we cannot use the KieScanner with Maven 3?
By the way I noted that if I set my KieContainer with a LATEST version, the
KieScanner systematically redeploy my JAR as the KieScanner compare the
real version with "LATEST". I've seen that there were some changes in the
KieScanner in the 6.1.0, did you fix it? I can't test right now because I
face a rule compilation problem with the new 6.1.0 version and I still have
to figure this out.
Regards
--
Maxime FALAIZE
10 years, 7 months
java.lang.NullPointerException in simple example
by ahgiovanini
Hi guys!
I'm new in the world of jboss and drools and I'm making some simple examples
that existing on
https://github.com/droolsjbpm/drools/tree/master/drools-examples-api
Now, I'm studing the CashFlow example and in my project when I run it, I
receive a error message saying:
Exception in thread "main" java.lang.NullPointerException
at com.sample.CashFlowMain.main(CashFlowMain.java:30)"
I don't know the why this message, because I set the acp at lines 20 and 21.
Someone would help me please?
Thanks
package com.sample;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.FactHandle;
import java.text.SimpleDateFormat;
import java.util.Date;
public class CashFlowMain {
public static void main(String[] args) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
KieContainer kc =
KieServices.Factory.get().getKieClasspathContainer();
KieSession ksession = kc.newKieSession("CashFlowKS");
AccountPeriod acp = new AccountPeriod();
acp.setStart(date("2013-01-01")); // set acp - line 20
acp.setEnd(date("2013-03-31")); // set acp - line 21
Account ac = new Account(1, 0);
CashFlow cf1 = new CashFlow(date( "2013-01-12"), 100,
CashFlowType.CREDIT, 1 );
CashFlow cf2 = new CashFlow(date( "2013-02-2"), 200,
CashFlowType.DEBIT, 1 );
CashFlow cf3 = new CashFlow(date( "2013-05-18"), 50,
CashFlowType.CREDIT, 1 );
CashFlow cf4 = new CashFlow(date( "2013-03-07"), 75,
CashFlowType.CREDIT, 1 );
FactHandle fh = ksession.insert(acp);
ksession.insert( ac );
ksession.insert( cf1 );
ksession.insert( cf2 );
ksession.insert( cf3 );
ksession.insert( cf4 );
ksession.fireAllRules();
acp.setStart(date( "2013-04-01"));
acp.setEnd(date( "2013-06-31"));
ksession.update(fh, acp);
ksession.fireAllRules();
}
public static Date date(String str) throws Exception {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
return sdf.parse( str );
}
}
--
View this message in context: http://drools.46999.n3.nabble.com/java-lang-NullPointerException-in-simpl...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 7 months
Re: [rules-users] A employee roster like case - OptaPlanner
by ge0ffrey
Sounds like a typical OptaPlanner problem.
Domain model:
- CareTaker
- OldPerson
- Day
- Visit(OldPerson, Day)
- @PlanningEntity VisitAssignment (Visit, @PlanningVariable CareTaker)
Using the OptaPlanner employee rostering example:
- CareTaker == Employee
- OldPerson == ShiftType
- Day == ShiftDate
- Visit(OldPerson, Day) == Shift (ShiftType, ShiftDate)
- @PlanningEntity VisitAssignment (Visit, @PlanningVariable CareTaker) ==
ShiftAssignment (Shift, @PlanningVariable Employee)
--
View this message in context: http://drools.46999.n3.nabble.com/A-employee-roster-like-case-tp4029352p4...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 7 months
Re: [rules-users] (Hot?) rules production deployment
by Pykhtin, Alex
Thank you again, Steve.
We need to make all kind of changes to the rules, however, small changes are more frequent than significant ones. So, every time we are deploying a new rule, there is a risk of it either not compiling or failing properly follow business logic.
We can trust users with any changes, however, moving the code to production is a big deal. This should be vetted by an authority figure, and there must be a simple and transparent rollback plan.
Yes, we want to be very risk-averse.
Ideally, we would like to have:
1. A staging environment where automation tests are run;
2. A change can be deployed to production only if all automation tests have passed;
3. Some kind of administration console from which a change can be manually deployed to production (via uploading to production Maven repository or in some other way);
4. Production Drools system picking up new changes without interruption of service;
5. Production console function allowing a one-click rollback of a recent change;
Alex
P.S. Sorry, it looks like I have not mastered proper replying to a forum thread.
> Pretty much correct.
>
> re. 5 - It depends on what you mean by it becoming clear that a release is a bad one.
>
> I have tended to code up my own knowledge base reloads and check for errors, but I'm pretty sure that if your rules don't compile, then neither the KnowledgeAgent nor the KieScanner will deploy them. If you use Guvnor, then your project will not be built and packaged if the rules don't compile.
>
> However, if the problem is that the new rules are just 'wrong' within your domain, then it's hard to think of any way in which that could be detected > automatically, other than by you yourself writing the validation.
>
> To help with this, I have previously set up a FitNesse server which would load in the latest rules and evaluate them, ensuring that output expectations are met. However, no such test suite is perfect. It may be that a change is made which needs a new test to evaluate it. If that test is not written, then the suite of tests still passes.
>
> Similarly, you can write unit tests for the build. You can deploy to a staging server, where the rules can be evaluated with as-live data, so that you can regression test the rules service in isolation from the rest of your application.
>
> Looking at rollback, in one Guvnor-based system, I have the users take a snapshot for each rules deployment. They then copy that snapshot to an "approved" snapshot. This way, rollback is just a case of copying the previous version to "approved" and deploying that. The users are legal and back office operations teams, and they are pretty efficient at following this process these days.
>
> However, in the end it comes down to things like:
> What kind of rule changes do users typically make? i.e. Are they just changing some numbers in existing decision tables?
> Can you trust the users to only make non-risky changes? Guvnor won't stop them from altering the structure of decision tables, or adding new non-decision-table rules.
> How risk-averse are you?
>
> Steve
10 years, 7 months
Drools Fusion Dropping Actions to Events?
by chandu_divi
I am using Drools Fusion 6.0.1.Final version, it looks like some (rather
several) actions to the events are dropped. I am sending about 100K events
and expecting an action to all the events, but only 5000 actions are
performed, which means about 95K actopms are dropped.
The same issue was posted in the thread
http://drools.46999.n3.nabble.com/rules-users-Drools-Fusion-Dropping-Even...,
but it is marked as resolved.
The defect https://issues.jboss.org/browse/DROOLS-131 is also marked as
fixed.
But this issue seems to be appearing again.
Here is my code.
kmodule.xml
<?xml version="1.0" encoding="UTF-8"?>
<kmodule xmlns="http://jboss.org/kie/6.0.0/kmodule">
<kbase name="eventDrop" packages="ed" eventProcessingMode="stream">
<ksession name="edSession"/>
</kbase>
</kmodule>
ed.drl
package drools
import foo.TemperatureEvent
declare TemperatureEvent
@role(event)
end
rule "RULE S1"
when
$te:TemperatureEvent(measure <= 50) from entry-point entryone
then
System.err.println("The temperature at location - "+$te.getLocation() +
" is " + $te.getMeasure());
end
rule "RULE S2"
when
$te:TemperatureEvent(measure > 50) from entry-point entryone
then
System.err.println("The temperature at location - "+$te.getLocation() +
" is " + $te.getMeasure());
end
TemperatureEvent.java
package foo;
public class TemperatureEvent {
int measure;
String location;
long timeStamp;
public TemperatureEvent(int measure, String location, long timeStamp) {
this.measure = measure;
this.location = location;
this.timeStamp = timeStamp;
}
public int getMeasure() {
return measure;
}
public void setMeasure(int measure) {
this.measure = measure;
}
public String getLocation() {
return location;
}
public void setLocation(String location) {
this.location = location;
}
public long getTimeStamp() {
return timeStamp;
}
public void setTimeStamp(long timeStamp) {
this.timeStamp = timeStamp;
}
}
App.java
package foo;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.Random;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.api.runtime.rule.EntryPoint;
public class App {
public static void main(String[] args) throws Exception {
System.setErr(new PrintStream(new FileOutputStream("report.txt")));
// Start Drools.
KieServices ks = KieServices.Factory.get();
KieContainer kContainer = ks.getKieClasspathContainer();
final KieSession kSession = kContainer.newKieSession("edSession");
EntryPoint entryPoint1 = kSession.getEntryPoint("entryone");
new Thread() {
@Override
public void run() {
kSession.fireUntilHalt();
}
}.start();
Random measure = new Random(System.currentTimeMillis());
Random location = new Random(System.currentTimeMillis() - 1000000L);
String locations[] = { "Bangalore", "Chennai", "Delhi", "Mumbai",
"Kolkata" };
for (int i = 0; i < 10; ++i) {
for (int j = 0; j < 1000; ++j) {
TemperatureEvent te = new TemperatureEvent(
measure.nextInt(100),
locations[location.nextInt(5)],
System.currentTimeMillis());
entryPoint1.insert(te);
// Thread.sleep(1);
}
}
Thread.sleep(100);
kSession.halt();
kSession.dispose();
}
}
--
View this message in context: http://drools.46999.n3.nabble.com/Drools-Fusion-Dropping-Actions-to-Event...
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 7 months
Distributed Drools
by Daniel Souza
Hi all, I'm looking for some distributed solution available with drools. I
want to create a distributed Multi-agent architecture for my project using a
shared working memory.
Searching for solutions, I found the DJess and Octopus solution that use the
Jess inference engine.
For Drools, I found this one:
http://www.plugtree.com/making-a-non-persistent-ha-knowledge-session/
It seems that Kie is flexible enough to distribute the knowledge session in
local ksessions, but I think that the ha-ksession doesn't provide a shared
working memory to different kbases. Seeing the sample project, there's just
one rule set (drl) with only one rule. I can use as a sample model to do
what I want to do. This project showed me how I can extend the Kie and
implement my own.
I'm not familiar with Drools 6 yet, but I'm reading papers about distributed
Rule-Based Systems concerning Multi-Agent Systems solutions and I didn't
find any solution using Drools. The majority solutions were provided using a
shared working memory with local copies.
*Than, it gives me a question: is it possible to create a shared working
memory with Drools?*
To refresh What I mean, there's an old paper showing differences between
Blackboard Systems and Rule-Based Systems (see Figure 1).
<http://drools.46999.n3.nabble.com/file/n4029338/production_systems_vs_bla...>
In Figure 1, the Blackboard is a shared working memory to insert facts,
where each knowledge source (KS) is activated according with the facts
inserted. Each KS is a specific expert with your own rules set that look for
the blackboard to produce partial solutions that can be seen as new facts to
be inserted in the blackboard. These partial solutions can activate more KS
to produce new partial solutions until the final solution be reached. In
contrast, in production systems, we build a knowledge base with a set o
rules that can be activated according with facts inserted in a local working
memory (there's no shared working memory between others kbases with their
own rules set).
In DJess, the authors introduce a model for distributing rule-based
inference systems called Web of Inference Systems (WoIS). Each member of
WoIS is composed of an inference system (IS) and a rule base, while all ISs
operate on a single Shared Working Memory (SWM). WoIS is controlled by a
dedicated
component called manager (M). Each IS holds a copy of a part of the SWM in
its local working memory, while all ISs run independently in parallel. This
model was utilized to implement a distributed version of Jess called DJess.
Synchronization between interfering rules is achieved by means of shadow
facts and ghost facts. A shadow fact is a Jess fact linked to a Java bean
object. Each shared fact is implemented as a shadow fact, and thus an
associated Java bean object is created. All the proxies corresponding to the
same shared fact are linked together by means of a Java remote object called
ghost fact. Access of the ISs to the ghost facts are synchronized by
acquiring locks during the transition from the conflict resolution stage to
the act stage of an inference cycle.
If not were done yet, I want to implement my own approach using Drools. I
don't know if I can reach the final solution using Drools, but it seems the
the Kie is flexible enough to be extend and I implement something. I'm
planning to use the FIPA Subscribe protocol to synchronize the Shared
Working Memory with a local working memory for each agent.
"The FIPA Subscribe Interaction Protocol (IP) allows an agent to request a
receiving agent to perform an action on subscription and subsequently when
the referenced object changes"
<http://fipa.org/specs/fipa00035/SC00035H.html>
Regards,
Daniel Souza
--
View this message in context: http://drools.46999.n3.nabble.com/Distributed-Drools-tp4029338.html
Sent from the Drools: User forum mailing list archive at Nabble.com.
10 years, 7 months