[automation] Enable asynchronous execution of rules and lock engine lock when loading scripts#5635
[automation] Enable asynchronous execution of rules and lock engine lock when loading scripts#5635Nadahar wants to merge 3 commits into
Conversation
|
I think this additional capability, as well as executing start level triggers asynchronously, is a good thing 👍 |
|
If there is a desire to for this solution, I want to ask if anybody sees something obvious that I've missed. It is used by |
|
I've pushed another commit here that isn't really related. I can make a separate PR for it if desired, however, having everything spread across many PRs/branches makes it very hard to test how things work together. What this commit does is make sure that the lock for script engines that implement @florian-h05 I'm hoping that the lock I lock is the correct one. I'm not quite sure exactly how the script engine instances (that are really just script contexts for Graal) are managed, but since the rules will later have access to the "shared context" created by the script, I have some hope that this lock is the correct one. |
|
As an option, I've pushed a commit that implements the asynchronous methods in |
|
Regarding I find it "impossible" to figure out exactly what that PR changed and why, but this is where the |
|
I'm good with this approach 👍 |
|
I am also good with this approach 👍 I think we should get this finished before doing another milestone build on Friday, this is required to fix some multithreading issues people have been experiencing. @Nadahar You know what I refer to. |
|
Probably the PR title and description should be adjusted as this also ensures that script loading is synchronized if needed. |
|
@florian-h05 I absolutely agree that this should be in before the next milestone. But, we must figure out how to handle the lock acquisition timeouts. Currently, they are hardcoded inconsistently. Having a long timeout will make things go very slow before finally failing, if things happen rapidly, the "lock acquisition queue" could grow infinitely long because new entries are added faster than they time out. That would effectively grind the system to a halt, at least everything related to these rules. So, while technically not "hanging" or "deadlocked", the effect would be indistinguishable. At the same time, a too short timeout might cause problems for some users that keep triggering/running rules faster than they can finish. One can discuss whether that's a problem or not, because the "design" of the rules are hardly ideal if this is the case. Yet, if people have been used to this "working somehow", but now it results in an error, they might find that "unacceptable" and trying to explain that they must rearrange their logic might not be an easy task. So, what is the right value? Should it be configurable? |
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
…uire it when loading scripts Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
5a06cb6 to
63ae078
Compare
This has been in the back of my mind for a little while. The situation is that when
runNow()is called, the calling thread is forced to wait for the rule execution to finish before returning, even if it doesn't need the execution result. This causes unnecessary waiting and potential deadlocks.This PR offers
runAsync()in addition torunNow(), where the caller can choose which behavior is desirable.runAsync()returns aFuture, so that it's still possible to wait for and retrieve the result, but it's entirely optional. It's also possible to cancel the rule execution if it hasn't yet started.I did this somewhat in a rush now, because I saw that this would also solve what #5634 does without the need to schedule yet another set of "tasks" that will just have to wait while the rule thread executes the rule. I'm thus submitting it as a draft, it's not "polished" and there might be aspects I have overlooked.
I'd like the approach to be discussed before investing further work in the idea.