Bug 502052 - Query observables leak RuleEngine instances
Summary: Query observables leak RuleEngine instances
Status: RESOLVED FIXED
Alias: None
Product: Viatra
Classification: Modeling
Component: Query (show other bugs)
Version: 1.4.0   Edit
Hardware: PC Windows NT
: P3 normal
Target Milestone: 1.5.0M1   Edit
Assignee: Abel Hegedus CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2016-09-23 05:56 EDT by Balazs Grill CLA
Modified: 2016-10-04 06:57 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Balazs Grill CLA 2016-09-23 05:56:26 EDT
When an observable list to a matcher result is created through org.eclipse.viatra.addon.databinding.runtime.api.ViatraObservables.observeMatchesAsList(Matcher), a RuleEngine is created which is never disposed.

It should be disposed on the observable's disposal event if it was created solely for this observable instance.
Comment 1 Eclipse Genie CLA 2016-09-23 12:01:12 EDT
New Gerrit change created: https://git.eclipse.org/r/81809
Comment 2 Abel Hegedus CLA 2016-09-23 12:41:11 EDT
The proposed patch provides a fix for this issue.

I think we should consider deprecating the methods which accept a query engine and enforce the usage of a rule engine. Together with an easy way to create it (RuleEngines.createViatraQueryRuleEngine at the moment), this would make the user aware that this object should be managed by his code.

At the very least, we should educate users better (wiki and JavaDoc) about the life cycle of such observables.

However, you could also convince me that users who would like to use VIATRA Observables should not have to worry about such issues and having too many rule engines is not a serious problem, as they are not too heavyweight.
Comment 3 Gabor Bergmann CLA 2016-09-24 11:48:28 EDT
Would sharing rule engines across Observable* provide any significant performance benefits?
Comment 4 Abel Hegedus CLA 2016-09-26 08:13:25 EDT
It would decrease the number of listeners in several places. My guess is that once there are observables in the thousands, the overhead becomes measurable (each model update listener is invoked, then executes SchedulerFactory -> Scheduler -> ScheduedExecution -> IExecutor -> iterate on conflict set). Sharing the rule engine would result in a single iteration on one conflict set.
Comment 5 Gabor Bergmann CLA 2016-09-26 09:01:16 EDT
In that case, can we perhaps use a default "managed" rule engine for each event source (VQ engine), similarly to the managed VQ engine for each model scope?
Comment 6 Abel Hegedus CLA 2016-09-26 09:34:52 EDT
Yes, managed EVMs might make sense and have come up at least for me several times. However, due to the high degree of configurability, it seemed better to avoid choosing a default configuration.

Still, we could have a manager for execution schemas like this:
- initialised on a given Query Engine
- uses model update listener of engine for scheduling

Even in this case you would need to either restrict access to modifying the conflict resolver or risk different applications disrupting each other.

A middle ground would be to implement such a manager without making it singleton and the VIATRA Data binding could use an internal instance for observables of the same query engine (since it knows that it is safe to do that). Even simpler, such an implementation could be directly added to VIATRA Data binding and if it seems reusable, moved to EVM core later.

I think this last point should be doable in 1.5 timeframe.
Comment 8 Abel Hegedus CLA 2016-10-04 06:57:59 EDT
Observables created using query engine should no longer leak rule engines.