meta data for this page
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
sap_hybris_commerce:promotions_rules_engine:start:how_to_improve_the_performance_of_the_rule_engine [2022/09/19 10:07] – [Find slow performing rules using drools metrics] Antonio Robirosa | sap_hybris_commerce:promotions_rules_engine:start:how_to_improve_the_performance_of_the_rule_engine [2022/10/14 15:10] (current) – aspect to log events Antonio Robirosa | ||
---|---|---|---|
Line 3: | Line 3: | ||
Unpublish all promotion rules which are triggered by old coupons which are inactive. A cronjob can be created to regularly remove these unused rules | Unpublish all promotion rules which are triggered by old coupons which are inactive. A cronjob can be created to regularly remove these unused rules | ||
+ | ===== Log the calls to the hybris code ===== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | ===== Log all events generated by the rule engine ===== | ||
+ | |||
+ | <WRAP center round important 100%> | ||
+ | The details of the logged events are not very useful. | ||
+ | </ | ||
+ | |||
+ | Create the following class: | ||
+ | |||
+ | < | ||
+ | package org.areko.core.ruleengineservices; | ||
+ | |||
+ | import de.hybris.platform.ruleengine.RuleEvaluationContext; | ||
+ | import de.hybris.platform.ruleengine.impl.DefaultPlatformRuleEngineService; | ||
+ | |||
+ | import java.io.IOException; | ||
+ | import java.nio.file.Files; | ||
+ | import java.util.Collection; | ||
+ | import java.util.function.Supplier; | ||
+ | |||
+ | import javax.annotation.PostConstruct; | ||
+ | |||
+ | import org.apache.commons.collections.CollectionUtils; | ||
+ | import org.kie.api.KieServices; | ||
+ | import org.kie.api.command.BatchExecutionCommand; | ||
+ | import org.kie.api.logger.KieRuntimeLogger; | ||
+ | import org.kie.api.runtime.ExecutionResults; | ||
+ | import org.kie.api.runtime.KieContainer; | ||
+ | import org.kie.api.runtime.KieSession; | ||
+ | import org.kie.api.runtime.rule.FactHandle; | ||
+ | import org.slf4j.Logger; | ||
+ | import org.slf4j.LoggerFactory; | ||
+ | |||
+ | /** | ||
+ | * This implementation logs the events generated by the rule engine | ||
+ | */ | ||
+ | public class ArLoggingPlatformRuleEngineService extends DefaultPlatformRuleEngineService | ||
+ | { | ||
+ | private static final Logger LOGGER = LoggerFactory.getLogger(ArLoggingPlatformRuleEngineService.class); | ||
+ | |||
+ | private KieServices kieServices; | ||
+ | |||
+ | // OOTB Code adding the logger | ||
+ | protected Supplier< | ||
+ | return () -> { | ||
+ | KieSession kieSession = (KieSession)this.getKieSessionHelper().initializeSession(KieSession.class, | ||
+ | LOGGER.debug(" | ||
+ | final KieRuntimeLogger kieRuntimeLogger = addAuditLogger(kieSession); | ||
+ | |||
+ | ExecutionResults executionResults; | ||
+ | try { | ||
+ | executionResults = (ExecutionResults)kieSession.execute(command); | ||
+ | } finally { | ||
+ | Collection factHandles = kieSession.getFactHandles(); | ||
+ | if (CollectionUtils.isNotEmpty(factHandles)) { | ||
+ | factHandles.stream().filter(FactHandle.class:: | ||
+ | .map(FactHandle.class:: | ||
+ | .forEach(h -> kieSession.delete((FactHandle) h)); | ||
+ | } | ||
+ | |||
+ | LOGGER.debug(" | ||
+ | kieSession.dispose(); | ||
+ | kieRuntimeLogger.close(); | ||
+ | } | ||
+ | |||
+ | return executionResults; | ||
+ | }; | ||
+ | } | ||
+ | |||
+ | private KieRuntimeLogger addAuditLogger(final KieSession kieSession) | ||
+ | { | ||
+ | try | ||
+ | { | ||
+ | return this.kieServices.getLoggers().newFileLogger(kieSession, | ||
+ | } catch (IOException e) | ||
+ | { | ||
+ | throw new RuntimeException(e); | ||
+ | } | ||
+ | } | ||
+ | |||
+ | @PostConstruct | ||
+ | protected void setUp() { | ||
+ | this.kieServices = this.getRuleEngineBootstrap().getEngineServices(); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Secondly add this bean definition to one of the spring application context of your hybris workspace: | ||
+ | |||
+ | < | ||
+ | <alias name=" | ||
+ | <bean id=" | ||
+ | class=" | ||
+ | </ | ||
+ | </ | ||
+ | |||
+ | After you start the server, create a cart, add products and a voucher, you will get the file / | ||
+ | |||
+ | < | ||
+ | sed -i ' | ||
+ | </ | ||
===== Find slow performing rules using drools metrics ===== | ===== Find slow performing rules using drools metrics ===== | ||
- | Drools comes with a logging module [[hhttps:// | + | FIXME Drools comes with a logging module [[hhttps:// |
+ | |||
+ | ===== Useful links ===== | ||
+ | |||
+ | [[https:// | ||
+ | |||
+ | [[https:// | ||
+ | |||
-- Based on SAP commerce 2105 | -- Based on SAP commerce 2105 |