Hi Michael,
If the rules for each thread are different, then the most reasonable
thing to do is to create one Rete object per thread. I'm not sure why
you say this wouldn't make sense; if each thread is doing an
independent computation, why introduce contention between them?
If the rules for each thread are the same, then you have a couple of
alternatives.
The first approach would be to use one engine from all threads, and
keep the engine running *always* with run-until-halt. You make this
work by (1) adding a "thread tag" to all the working memory elements
that are going to be specific to a single thread -- just a slot
dedicated to holding a slot-specific identifier -- and having the
rules use this so that facts from different threads aren't mixed; and
(2) writing the rules so that it's not necessary to call "run" at
specific points. For example, if you don't want the rules for a
thread to fire until a certain point, then make them depend on a
"trigger fact" -- i.e., include a pattern like (run-thread-now ?tag)
which includes the thread tag for a specific thread. The engine will
run always (sleeping when there is no work to do) but rules won't
fire until you assert the trigger.
A newer approach involves "peering" of Rete objects, which is new in
Jess 7.1. Peered engines share a single copy of the compiled rules,
but otherwise operate independently. This is a just like your
proposal of having a separate Rete for each thread, but because the
compiled rules are shared, it has vastly lower memory overhead.
On Jan 10, 2008, at 8:03 AM, Michael Frey wrote:
Hi,
I have a few questions concerning a Jess working within a multiple
threaded environment. What we want to achieve is to have a series
of rules which are applicable to the facts which a specific thread
has inserted in working memory. From reading the documentation we
can group a set of rules into the Module framework, and this suits
fine. The issue we have is that Working Memory is related to
whatever Rules Module the 'focus' is assigned to. Keeping this in
mind, in our scenario we could have many threads asserting facts
into Working Memory.
So lets say that Thread_1 assigns facts and then wants the engine
to run. It sets the focus to Module_1 and executes the run method
on the engine! The first issue is that the engine will analyse all
facts in the Working memory, even facts which Thread_1 has not
inserted. The next potential issue is that setting the focus for a
specific Module and the running of the engine are different tasks,
i.e. they have different locks, a thread could be setting the focus
while at the same time another thread could be ordering the engine
to 'run'! If these assumptions are correct, then with our scenario
the changing of the focus module could have unexpected effects! Is
there a way to split the working memory and just associate it
with with a specific module. I would imagine not?
We have thought about this problem and starting a Rete engine per
thread, which would solve our problem, but with potentially 100
threads, this would not make sense, performance wise!!
Is there other ways around this with Jess? Any info appreciated!
Best regards,
Michael
--
Michael Frey
Telecommunications Software & Systems Group
ArcLabs Research & Innovation Centre
West Campus
Waterford Institute of Technology
Carriagnore, Co.Waterford, Ireland
mail: [EMAIL PROTECTED]
web: http://www.tssg.org
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users
[EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify owner-jess-
[EMAIL PROTECTED]
--------------------------------------------------------------------
---------------------------------------------------------
Ernest Friedman-Hill
Informatics & Decision Sciences Phone: (925) 294-2154
Sandia National Labs FAX: (925) 294-2234
PO Box 969, MS 9012 [EMAIL PROTECTED]
Livermore, CA 94550 http://www.jessrules.com
--------------------------------------------------------------------
To unsubscribe, send the words 'unsubscribe jess-users [EMAIL PROTECTED]'
in the BODY of a message to [EMAIL PROTECTED], NOT to the list
(use your own address!) List problems? Notify [EMAIL PROTECTED]
--------------------------------------------------------------------