CacheControl / json-rules-engine

A rules engine expressed in JSON
ISC License
2.59k stars 459 forks source link

Multiple Engines neither completing nor erroring (condition.js "// todo parallelize) #229

Closed flodaniel closed 3 years ago

flodaniel commented 3 years ago

Hello,

we have quite a complex use case for a gamification project. In the end we have multiple engines running at the same time (some with different, some with identical facts/rules). It is quite a complex setup.

As soon as we start 10 or more engines within milliseconds they all stop (without erroring or completing) at line 133 in condition.js. This is the code block that also includes the todo, which I expect would resolve the blocking of the engines:

      return this._getValue(almanac) // todo - parallelize
      .then(function (rightHandSideValue) {
        return almanac.factValue(_this.fact, _this.params, _this.path).then(function (leftHandSideValue) {
          var result = op.evaluate(leftHandSideValue, rightHandSideValue);
          (0, _debug2.default)('condition::evaluate <' + leftHandSideValue + ' ' + _this.operator + ' ' + rightHandSideValue + '?> (' + result + ')');
          return { result: result, leftHandSideValue: leftHandSideValue, rightHandSideValue: rightHandSideValue, operator: _this.operator };
        });
      });

I am unable to identify why this would not work in a parallelized setup, such as ours. What, excepts running a maximum of 9 engines in parallel, can we do to resolve this?

Would woul be the steps to implement that todo?

CacheControl commented 3 years ago

@Firetrip I believe that TODO is in reference to the fact that we could parallelize the retrieval of the right hand side of the equation (the fact value) with the retrieval of the left hand size (the "value" property of the condition) via a Promise.all. So it's referring to a potential performance optimization, not a known bug.

Were you able to learn anything else about the root cause? I can't think of any global state that would prevent multiple engine instances from executing independently from one another. Are you able to provide a snippet that reproduces the problem?