I want to run all rules asyncronously to make it thread safe
When i m performing load test then why RuleEngine taking so much time to execute all rules.
NRuleRepository repository = null;
foreach (var rule in rules)
{
repository = new NRuleRepository();
repository.LoadRules(rule.Rule);
var factory = repository.Compile();
var session = factory.CreateSession();
NRuleBody data = null;
foreach (var fact in rule.RuleDataList)
{
data = new NRuleBody();
data.Rule = rule.Rule;
data.RuleData = fact;
session.Insert(data);
}
result += session.Fire();
}
Can i make call as below:
session.FireAsync();
or there is any other option to fire Multiple rules but in async ? and NRuleRepository class should be reinitialize on every request ?
At the very least, you could probably utilise
Task.Run()
in order to create a thread for each instance of the repository, but what you're doing seems very inefficient.Why are you inserting the rule with the data in the session? You've already added the rule to the repository.
If you are only ever having a singular rule in the repository, NRules is almost certainly overkill, and you would be better placed doing almost anything else.