Upgrade to Pro — share decks privately, control downloads, hide ads and more …

[KieLive#33] Drools troubleshooting

[KieLive#33] Drools troubleshooting

Learn troubleshooting tips and techniques for issues like unexpected rule firing, spreadsheet errors, performance problem.

Link to the live streaming: http://red.ht/KieLive33

About this Event

[KieLive#33] Drools Troubleshooting

In this session, Toshiya will guide us through how to identify issues in Drools solutions. Some examples are:

Unexpected loop firing
property reactivity
spreadsheet
control execution flow
initial performance issues
runtime performance issues​

About the invited speaker:
Toshiya Kobayashi is a Principal Software Engineer at Red Hat, working in Drools Core team. 10 years experience in Red Hat technical support team.

About the KIE Lives:
The KIE Live Series is composed of live streamings that bring technical information and updates about business automation delivered by the projects under the KIE umbrella: Drools, jBPM, OptaPlanner, and Kogito.

Problems like process automation, decision automation, resource planning solution are the main topics, and of course, we always have in mind recent technology concepts like cloud-native application target for any type of cloud (private/public/hybrid/edge). You can expect to hear from business automation experts who code or/and deliver business automation within big enterprises across the world.

Join us to share, learn, and grow together.

Knowledge is everything

KIE Community

April 27, 2021

Transcript

26 slides
  1. . Drools Trouble-Shooting • Agenda • Unexpected rule firing •

    Property Reactivity • Debugging Spreadsheet • Control the flow of rule execution • Performance issues Demo projects can be found in https://github.com/tkobayas/kie-live They run with Drools 7.52.0.Final : When you develop/maintain a project, please use the latest version as possible!
  2. . My rule is looping! (recap) • Use EventListener to

    understand what's going on • DebugRuleRuntimeEventListener • DebugAgendaEventListener • You can write your custom listeners This Rule is activated Firing this Rule This Object is updated This Rule is activated again!
  3. . My rule is looping! (recap) • no-loop • Only

    prevents a loop which is triggered by the rule itself • lock-on-active • Once the rule is fired, it's no longer fired regardless of the origin of re-evaluation
  4. . Property reactivity (recap) Why this doesn't loop? Because Drools

    Engine analyzes rules: 1) This rule only tests item 2) item is not changed
  5. . Property reactivity (previous example) This rule loops Because Drools

    Engine knows: 1) This rule tests discount 2) discount is changed
  6. . Property reactivity (recap) Don't loop! This @watch tells :

    Re-evaluate this Pattern only when item is changed
  7. . Property reactivity • Since Drools 7, property reactivity is

    enabled by default • Be careful when you migrate from Drools 6 • Property reactivity is good for performance and you can write rules more naturally. • If you hit a strange behavior and doubt property reactivity, temporarily disable it so you can confirm the difference. kmodule.xml
  8. . Debugging Spreadsheet (recap) [main] ERROR Unable to build KieBaseModel:defaultKieBase

    [10,15]: [ERR 101] Line 10:15 no viable alternative at input '' [10,35]: [ERR 101] Line 10:35 no viable alternative at input '' [0,0]: Parser returned a null Package This message means, "A wrong word/character here!" Line# and Column# in the generated DRL (Note: \t is 1 char)
  9. . How to control the flow of rules? First evaluation

    group Second evaluation group Second evaluation group Final evaluation group
  10. . How to control the flow of rules? • Split

    into multiple KieBases • Good for maintenance/debug if your kbase is large • Salience • Most convenient but too much use could be messy • Agenda Group • Standard approach • Ruleflow Group • Good combination with BPMN • Control Fact • Flexible <DEMO>
  11. . Performance issues: • Set up your benchmark for repeatable

    testing • JMH (https://github.com/openjdk/jmh) is recommended for fine tuning • Enable GC logging • Narrow down the bottle-neck • Rule execution itself? • kie-server payload marshalling? • Application logic? • External system access in RHS? (e.g. DB, Web Service)
  12. . The first response is slow • KieBase loading is

    slow • Try executable model • just add dependency "drools-model-compiler", Then build a kjar (mvn clean install) Kogito uses executable model!
  13. . The first response is slow • First "fireAllRules" invocation

    is slow -> it gradually gets faster • Various internal caching • MvelConstraint is slow at first. Then MvelConstraint turns into a Java class dynamically so it will gets faster • JVM Jitting • Try executable model • doesn't have Mvel related perf issues • Warm up KieBase • Create a dummy KieSession. Insert dummy facts into a ksession and fire • Improvement depends on your rules. If your application is sensitive about the first response, it's worth trying
  14. . Rule execution is slow (Best Practice) • Watch out

    for Cross Product If you insert 1000 Customer facts and 1000 Product facts, 1000*1000 combination will be evaluated!
  15. . Rule execution is slow (Best Practice) • List the

    most restrictive rule conditions first • Use simple field constraints as possible (No eval)
  16. . Rule execution is slow • But reviewing lots of

    rules is hard... drools-metric helps your analysis <DEMO> Note: drools-metric is not for production environment. Use it in your test environment to analyze a bottleneck
  17. . Rule execution is slow (recap) • Find bottle-neck Node

    from drools-metric logs Node name How many time the condition is evaluated elapsed time (micro second)
  18. . Rule execution is slow (recap) • ReteDumper.dumpAssociatedRulesRete() shows which

    rule is associated with the problematic Node Check this rule!
  19. . Rule execution is slow (recap) • Fix rules following

    the best practice • For detailed explanation, please read: • https://github.com/tkobayas/MetricLogUtils/wiki/How-to-use-Me tricLogUtils
  20. . Community • Zulip chat • https://kie.zulipchat.com/ • #drools •

    Google group • https://groups.google.com/g/drools-usage • https://groups.google.com/g/drools-setup

More Decks by KIE Community

Other Decks in Technology