SlideShare a Scribd company logo
Developing
    Configurable and
    High Performance
    Apps in Drools

    Ajay Mahajan
    Lead Architect




1
Agenda


      What, Where, Why, When

      Drools Eco-System & A Use Case

      Rule Definitions

      Usage - Deployment Modes


      Best Practices
                                       Value from Session

2
What, Where, Why, When




3
What is a Rule Engine




4
Where Does It Fit




                        Parameterization


                          Code

                          Config Files

                          Database


                           Rules Engine




5
Why Should I Bother




                                    • Many ways to define Rules
                   Flexibility &    • Group rules and define priorities
                  Configurability   • Plethora of functions that help in decisioning
    Rule Engine




                                    • User friendly and Business Like
                  Manageability     • Better Tooling Support
                                    • Easier Understanding & Visualization


                                    • Just define your rules not execution details
                  Declarative v/s   • Execution is handled by Rules Engine
                    Imperial          • Sequencing and Re-entry
6
FUDs – Fear, Uncertainty and Doubt
                  • True, as compared to if-else statements in code

       Slow       • However, Rules are precompiled
                  • In Some Cases, execution is faster if designed correctly




                  • Yes, they do have a learning curve

     Difficult    • Start small and Limit the features to those you really need
                  • You don’t have to learn each feature and function offered




      More        • Yes, rules engine do need more space than a java class file
                  • Precompiled Rules form a Rete graph


     Memory       • Use stateless models where use case allows
                  • Stateful models – Follow the optimizations and mind your memory



                  • Commercial Tools can get expensive, e.g. Blaze and Jrules

    Expensive     • Open Source Drools has evolved over time, in its version 5.5
                  • Drools used in high volume, mission critical systems

7
When Should I Use a Rule Engine
    IF (Requirements== expressed as rules)


    IF (Rules == many OR complex OR changing frequently)


    IF (Rules == managed separately from application code)


    IF (memory != very low)


    IF (Application == evolving)


    IF (Developers == have skills OR ok with learning curve)


    IF (Business Users == like to see / experiment with rules)


    IF ( Additional Complexity < Benefits in Flexibility + Configurability)


    THEN use Rules Engine
8
Drools Ecosystem




9
Jboss - Drools
            Expert
            • Main Rules Engine Component
            • Have Stabilized after going through product cycles
            • Highly Successful and widely used

            Rule Flow (replaced by jBPM)
            • Group into Rule sets and define flow chart to execute them
            • Graphical Environment to define work flows
            • jBPM using BPMN 2.0 is the way to go for any serious BPM

            Guvnor
            • Web Based GUI to manage the Rules
            • Split out as separate component in V5
            • Read Only in Production, but modify in test/UAT for business

            Planner
            • Resources– travelling salesman, scheduling, routing
            • Heuristic Rules
            • Relatively new

            Fusion
            • Event Processing- ESP / CEP use cases
            • Concept of Sliding Time window
            • Other products such as Esper and Twitter Storm

10
Drools Expert – Steps
              • DRL, Decision
     Define     Tables, DSL



              Compile    • To Knowledge base



                          Create      • Uses Knowledge base
                          Session

                                       Insert   • Causes Activations
                                       Facts

                                                   Fire       • RHS
                                                  Rules         Executes

11
Real Use Case



     Trades
                              Matching Engine               Match Statuses
     T1, T4, T3, T2
                                                            T1     C3
                                                            T2      C1 + C3
                                                            T3+T4       C4


                               Confirmation
                               C1, C2, C3, C4

      100’s of Trades and Confirmations inflowing per second at peak hr
      Flowing in any order, not necessarily one after the other
      One trade can exactly match to one confirmation
      A trade can match to more than one confirmation
      One or more trades can match to one Confirmation
12
DRL – Drools Rules Language
     rule "Perfect Match"
          salience 100

            when
                   t:Trade()
                   c:Confirm(qty == t.qty , confirmId == t.cusip , amt == t.amt , price == t.price )
            then
                   log("Perfect Match for " + t.toString() + c.toString());
                   Match perfectMatch = new Match(t,c, "Perfect");

                   // retract perfect matches
                   retract(t);
                   retract(c);
     end                                                               Trade to Confirm Matching

                                                                  Why is this
           The base language for Rules Definition                  blazing
               All other Forms compile to this language            fast ??

           Rich and Versatile
               Entire Syntax, features and Rules definition is available


           Least User Friendly
13
DSL - Domain Specific Language
     expander Match.dsl

     rule "Exact Match Trade to Confirm"
     when
          Match Trade and Confirm
               - on cusip with confirmId
               - on amt
               - on price
     then
          Log "Perfect Match“
          Create Match with Status “Perfect”
          Remove Matched Elements
     end


        This is real code not Pseudo code

        DSL combines with grammar definition and translates to DRL
        Very Easy to Understand for Users and Visualize
        Power of creating new business vocabulary
        Encourages reuse



14
Decision Table
                             RuleTable     TradeRequests
                             NAME          CONDITION
                                                   CONDITION        ACTION             ACTION              ACTION            ACTION              ACTION                ACTION
                                           event:Event
                                                   event:Event
                                           eventGroup
                                                   $param != null   TradeRequest tr = ne
                                                                                       tr.setStartCaptureDate(DateUtils.getBusinessDate(event.get$1(), $2+1));
                                                                                                           tr.setEndCaptureDate(DateUtils.getBusinessDate(event.get$1(), $2+1));
                                                                                                                             tr.setStartTradeDate(DateUtils.getBusinessDate(event.get$1(), $2));
                                                                                                                                                 tr.setEndTradeDate(Date
                                                                                                                                                                       tr.setSettlementF


Trade Condition                            Event                                       Start Capture       End Capture                                                 Settlement
(Comment Column)             Name          Group Date Present       Trade Type         Date                Date              Traded After        Traded Before         Flag
TD < ED ; F = F              IncOpenFail   I     effectiveDate      Open Fails                             FreezeDate, 0                         EffectiveDate, -1     "F"

TD < ED ; SD <= FD ; F = O   IncRegOpen    I       effectiveDate    Regular Open       EffectiveDate, -1   FreezeDate, 0                         EffectiveDate, -1     "O"
TD < ED ; FD < SD            IncExtSet     I       effectiveDate    Extended Settle    EffectiveDate, -1   FreezeDate, 0                         EffectiveDate, -1

ED<=TD ; SD <=FD ; CD <= FD IncShortSet    I       effectiveDate    Short Settle       EffectiveDate, 0    FreezeDate, 0     EffectiveDate, 0
TD < ED ; FD < PD           IncAsOf        I       effectiveDate    As of Trades       FreezeDate, 1                                             EffectiveDate, -1


                                                                                                                                            Corporate Actions

          Excel columns are designated as Conditions or Actions

          Top few control rows are hidden from users,
                     Control rows help translate the excel into DRL


          Easy to understand for Users, once basic Excel formats are given
          Fit for use cases where there is need for intense parameterization

15
Learning & Best Practices
       Experiences, Usage Models, Performance




16
Real Life Experiences

       Complex Matching Engines

       •   Multiple Engines used for various functional matching
       •   Performed at 600 transactions / sec on one instance of execution
       •   If the I/o (messaging / database) were commented, got 8k executions / sec
       •   Stateful models used, but memory was conversed through optimizations

       Corporate Actions – Event Validations, Trade Extraction

       • Stateless model that evaluates each event separately through set of rules
         • 100’s of rules based on event types defined in Decision Tables
       • Increase in number of rules barely dent the performance
         • For 10k executions, 2 rules take 320 ms, and 100 rules take 328 ms

       Risk Analysis & Calculations

       • Calculations have lot of parameters, such as credit rating, product type, etc.
       • Calculations segmented into small number of individual steps
       • The decision of which formulae to use, was done by a Rules Engine



17
Usage Models
     Synchronous Execution
          Request – Response Style                          Your            Rule
                                                          Application      Engine
          Can act on the decision immediately


     Asynchronous Pipeline
                                                                         Rule
          Messaging Style                               Events                      Actions
                                                                        Engine
          Very scalable and resilient


     In Process with the Application
          Jar file as part of the application
          Excellent for Stateless execution, as reduces I/o without increasing memory
          Stateful executions are challenge in clustered environment & need memory sizing


     Out of Process as a runtime component
          Central Deployment & Management
          Overheads in Communication, and hence affects performance
          Could become bottleneck / central point of failure
          Needs sophisticated scaling models (e.g. functional split based on Hash or some key)


18
Improving Performance ..1
     Keep Separate Deployable Units rather than a giant rule engine component
          Divide and Conquer


     Use Stateless Sessions where Business case allows
          You can cluster and load balance your services seamlessly
          You can use in-process deployments easily


     Limit the number of facts in Stateful Executions
          The degradation is exponential beyond 400k objects in memory
          If higher volumes anticipated, than plan for multi deployments using sharding concepts


     Limit the Size of the objects checked in memory
          Use DTO (Data Transfer Object) pattern


     Use Batched Mode of Execution
          Check in more objects if you can in one go into the memory




19
Improving Performance ..2
     Use Drools only for decisions, not performing actual actions
           Let the decisions be communicated to a downstream component or by the caller to Rules Engine


     Avoid using evals(), --- use only as a last resort
           The java code inside eval is difficult to optimize into rete tree


     Work on aggregates where possible
           Rather than Checking Individual facts into the memory


     If you want to dig deeper
           Read more on the Rete Algorithm




20
Development Tips
     Use the IDE
          Syntax Validations
          DSL conversions
          Drools Debugging

     Use events
          Understanding how rules activate and fire
          Helpful for troubleshooting
          Remember to turn off in production


     Keep individual rules small, simple and atomic
          Avoid cyclic triggering of rules when you update the facts
          Use Agenda groups & Activation groups wherever applicable




21
Ajay Mahajan



     ajay.mahajan@wipro.com




22

More Related Content

PPTX
Business Process Optimization: Status and Perspectives
PPT
Scala Talk at FOSDEM 2009
PPT
DBMS PPT
PPTX
Data Governance Best Practices
PPTX
Le MDM selon Microsoft : Deep Dive dans Master Data Services
PPT
Sql operators & functions 3
PDF
Data Warehouse Basics
PPTX
UNIT II Lecture 3 Querying Relational Data Database Languages.pptx
Business Process Optimization: Status and Perspectives
Scala Talk at FOSDEM 2009
DBMS PPT
Data Governance Best Practices
Le MDM selon Microsoft : Deep Dive dans Master Data Services
Sql operators & functions 3
Data Warehouse Basics
UNIT II Lecture 3 Querying Relational Data Database Languages.pptx

What's hot (20)

ODP
Big Data Testing Strategies
PDF
Graph in Apache Cassandra. The World’s Most Scalable Graph Database
PPTX
JBoss Drools - Pure Java Rule Engine
PDF
Data Migration with Spark to Hive
PPTX
OLTP+OLAP=HTAP
 
PPTX
Free Training: How to Build a Lakehouse
PPTX
Using business rules to make processes simpler, smarter and more agile
PPT
4 lexical and syntax
PPT
Application Logging Good Bad Ugly ... Beautiful?
PDF
Introducing Kogito
PDF
Haystack 2019 - Query relaxation - a rewriting technique between search and r...
PPTX
Google cloud Dataflow & Apache Flink
PDF
Developing a Knowledge Graph of your Competency, Skills, and Knowledge at NASA
PPT
Building a Data Quality Program from Scratch
PPTX
Data Governance and MDM | Profisse, Microsoft, and CCG
 
PPTX
How to build a business glossary linked with data dictionary
PPTX
Whole-enterprise architecture
PDF
Fraud Detection with Hadoop
PDF
AI & Big Data - Personalização da Jornada - PicPay - TDC
PDF
Data Catalogs Are the Answer – What Is the Question?
Big Data Testing Strategies
Graph in Apache Cassandra. The World’s Most Scalable Graph Database
JBoss Drools - Pure Java Rule Engine
Data Migration with Spark to Hive
OLTP+OLAP=HTAP
 
Free Training: How to Build a Lakehouse
Using business rules to make processes simpler, smarter and more agile
4 lexical and syntax
Application Logging Good Bad Ugly ... Beautiful?
Introducing Kogito
Haystack 2019 - Query relaxation - a rewriting technique between search and r...
Google cloud Dataflow & Apache Flink
Developing a Knowledge Graph of your Competency, Skills, and Knowledge at NASA
Building a Data Quality Program from Scratch
Data Governance and MDM | Profisse, Microsoft, and CCG
 
How to build a business glossary linked with data dictionary
Whole-enterprise architecture
Fraud Detection with Hadoop
AI & Big Data - Personalização da Jornada - PicPay - TDC
Data Catalogs Are the Answer – What Is the Question?
Ad

Viewers also liked (20)

PPTX
Rule Engine & Drools
ODP
Drools 6 deep dive
PDF
Drools 6.0 (Red Hat Summit)
PPTX
Developing Complex Business Rules with Drools Integration
PDF
Drools and jBPM 6 Overview
PDF
Cork JUG - Drools basics &amp; pitfalls
PDF
Rules Programming tutorial
PDF
Drools
PPTX
Rule Engine Evaluation for Complex Event Processing
PDF
#CPBR7 - Métricas para startups
PDF
Drools expert-docs
PDF
Melhores Práticas no Uso da Nuvem AWS
PDF
How a major industrial group automated its purchase order processes
PDF
How a turnpike commission manages client requests case study by WorkflowGen
PDF
Best practices webinar
PDF
Business Rule Engine
KEY
Geospatial Indexing and Querying with MongoDB
PDF
Getting Started With #Drools 6 Slides - JBUG Denmark
PPTX
IBM Smarter Business 2012 - Headless BPM
PDF
Drools Happenings 7.0 - Devnation 2016
Rule Engine & Drools
Drools 6 deep dive
Drools 6.0 (Red Hat Summit)
Developing Complex Business Rules with Drools Integration
Drools and jBPM 6 Overview
Cork JUG - Drools basics &amp; pitfalls
Rules Programming tutorial
Drools
Rule Engine Evaluation for Complex Event Processing
#CPBR7 - Métricas para startups
Drools expert-docs
Melhores Práticas no Uso da Nuvem AWS
How a major industrial group automated its purchase order processes
How a turnpike commission manages client requests case study by WorkflowGen
Best practices webinar
Business Rule Engine
Geospatial Indexing and Querying with MongoDB
Getting Started With #Drools 6 Slides - JBUG Denmark
IBM Smarter Business 2012 - Headless BPM
Drools Happenings 7.0 - Devnation 2016
Ad

Similar to Developing Configurable and High Performance Apps in Drools (20)

PPT
Flex 360 Rules Engine
PPT
Flex 360 Rules Engine
PPT
Obey The Rules: Implementing a Rules Engine in Flex
ODP
JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTE
PDF
Intro to Drools - St Louis Gateway JUG
ODP
JBoss Business Rules Management System (BRMS) Primer
PDF
SAP Sybase Event Streaming Processing
PDF
Brms best practices_2011_oct_final
DOC
Tibco business events (be) online training institute
PDF
Drools JBoss Rules 5 0 developer s guide develop rules based business logic u...
ODP
Buenos Aires Drools Expert Presentation
ODP
Business processes, business rules, complex event processing, the JBoss way
ODP
2011-03-29 London - drools
ODP
JBoss Drools
PPTX
Jboss drools 4 scope - benefits, shortfalls
PDF
Rules Engine - java(Drools) & ruby(ruleby)
PPTX
Jboss drools 3 key drools functionalities
PDF
Introducing Drools
PPTX
Examples, Examples, Examples!
PDF
Drools Introduction
Flex 360 Rules Engine
Flex 360 Rules Engine
Obey The Rules: Implementing a Rules Engine in Flex
JBoss Drools and Drools Fusion (CEP): Making Business Rules react to RTE
Intro to Drools - St Louis Gateway JUG
JBoss Business Rules Management System (BRMS) Primer
SAP Sybase Event Streaming Processing
Brms best practices_2011_oct_final
Tibco business events (be) online training institute
Drools JBoss Rules 5 0 developer s guide develop rules based business logic u...
Buenos Aires Drools Expert Presentation
Business processes, business rules, complex event processing, the JBoss way
2011-03-29 London - drools
JBoss Drools
Jboss drools 4 scope - benefits, shortfalls
Rules Engine - java(Drools) & ruby(ruleby)
Jboss drools 3 key drools functionalities
Introducing Drools
Examples, Examples, Examples!
Drools Introduction

Recently uploaded (20)

PPTX
en_2024t208.pptx Adult lesson study for sabbath
PDF
Printable Nepali Gospel Tract - Be Sure of Heaven.pdf
PDF
Printable Norwegian Gospel Tract - Be Sure of Heaven.pdf
PPTX
Joshua Through the Lens of Jesus: Part 8 - Ch.22-24
PDF
Heavenly Holy Spirit vs False Spirit: An Analysis of 1 Peter 1:12 by Matthews...
PPTX
ream Organic Floral Christianity Faith Sermon Church Presentation.pptx
PPTX
Has-Satans-Little-Season-Already-Begun.pptx
PPTX
Viral_A Study of Acts_Acts 9.19b-31_Slides.pptx
PDF
Printable Latvian Gospel Tract - Be Sure of Heaven.pdf
PDF
noticeanddeclarationoftruthjc-dkr-08022025-01signinglog-250802103439-0b8a8d39...
PDF
Printable Kinyarwanda Gospel Tract - Be Sure of Heaven.pdf
PDF
Printable Luxembourgish Gospel Tract - Be Sure of Heaven.pdf
PDF
Printable Macedonian Gospel Tract - Be Sure of Heaven.pdf
PPTX
389 Your troops shall be willing 390 This is the Day
PDF
Printable Khmer Gospel Tract - Be Sure of Heaven.pdf
PPTX
Tell it to the World. The things that will amaze them more.
PDF
Printable Maldivian Divehi Gospel Tract - Be Sure of Heaven.pdf
PPTX
The conversion of Saul to Paul according to the Bible
PDF
Chandogya_Upanishad_by_Swami_Swahananda.pdf
PPTX
Faith and Gratitude: Guide to the Baccalaureate Mass & Responses
en_2024t208.pptx Adult lesson study for sabbath
Printable Nepali Gospel Tract - Be Sure of Heaven.pdf
Printable Norwegian Gospel Tract - Be Sure of Heaven.pdf
Joshua Through the Lens of Jesus: Part 8 - Ch.22-24
Heavenly Holy Spirit vs False Spirit: An Analysis of 1 Peter 1:12 by Matthews...
ream Organic Floral Christianity Faith Sermon Church Presentation.pptx
Has-Satans-Little-Season-Already-Begun.pptx
Viral_A Study of Acts_Acts 9.19b-31_Slides.pptx
Printable Latvian Gospel Tract - Be Sure of Heaven.pdf
noticeanddeclarationoftruthjc-dkr-08022025-01signinglog-250802103439-0b8a8d39...
Printable Kinyarwanda Gospel Tract - Be Sure of Heaven.pdf
Printable Luxembourgish Gospel Tract - Be Sure of Heaven.pdf
Printable Macedonian Gospel Tract - Be Sure of Heaven.pdf
389 Your troops shall be willing 390 This is the Day
Printable Khmer Gospel Tract - Be Sure of Heaven.pdf
Tell it to the World. The things that will amaze them more.
Printable Maldivian Divehi Gospel Tract - Be Sure of Heaven.pdf
The conversion of Saul to Paul according to the Bible
Chandogya_Upanishad_by_Swami_Swahananda.pdf
Faith and Gratitude: Guide to the Baccalaureate Mass & Responses

Developing Configurable and High Performance Apps in Drools

  • 1. Developing Configurable and High Performance Apps in Drools Ajay Mahajan Lead Architect 1
  • 2. Agenda What, Where, Why, When Drools Eco-System & A Use Case Rule Definitions Usage - Deployment Modes Best Practices Value from Session 2
  • 4. What is a Rule Engine 4
  • 5. Where Does It Fit Parameterization Code Config Files Database Rules Engine 5
  • 6. Why Should I Bother • Many ways to define Rules Flexibility & • Group rules and define priorities Configurability • Plethora of functions that help in decisioning Rule Engine • User friendly and Business Like Manageability • Better Tooling Support • Easier Understanding & Visualization • Just define your rules not execution details Declarative v/s • Execution is handled by Rules Engine Imperial • Sequencing and Re-entry 6
  • 7. FUDs – Fear, Uncertainty and Doubt • True, as compared to if-else statements in code Slow • However, Rules are precompiled • In Some Cases, execution is faster if designed correctly • Yes, they do have a learning curve Difficult • Start small and Limit the features to those you really need • You don’t have to learn each feature and function offered More • Yes, rules engine do need more space than a java class file • Precompiled Rules form a Rete graph Memory • Use stateless models where use case allows • Stateful models – Follow the optimizations and mind your memory • Commercial Tools can get expensive, e.g. Blaze and Jrules Expensive • Open Source Drools has evolved over time, in its version 5.5 • Drools used in high volume, mission critical systems 7
  • 8. When Should I Use a Rule Engine IF (Requirements== expressed as rules) IF (Rules == many OR complex OR changing frequently) IF (Rules == managed separately from application code) IF (memory != very low) IF (Application == evolving) IF (Developers == have skills OR ok with learning curve) IF (Business Users == like to see / experiment with rules) IF ( Additional Complexity < Benefits in Flexibility + Configurability) THEN use Rules Engine 8
  • 10. Jboss - Drools Expert • Main Rules Engine Component • Have Stabilized after going through product cycles • Highly Successful and widely used Rule Flow (replaced by jBPM) • Group into Rule sets and define flow chart to execute them • Graphical Environment to define work flows • jBPM using BPMN 2.0 is the way to go for any serious BPM Guvnor • Web Based GUI to manage the Rules • Split out as separate component in V5 • Read Only in Production, but modify in test/UAT for business Planner • Resources– travelling salesman, scheduling, routing • Heuristic Rules • Relatively new Fusion • Event Processing- ESP / CEP use cases • Concept of Sliding Time window • Other products such as Esper and Twitter Storm 10
  • 11. Drools Expert – Steps • DRL, Decision Define Tables, DSL Compile • To Knowledge base Create • Uses Knowledge base Session Insert • Causes Activations Facts Fire • RHS Rules Executes 11
  • 12. Real Use Case Trades Matching Engine Match Statuses T1, T4, T3, T2 T1 C3 T2 C1 + C3 T3+T4 C4 Confirmation C1, C2, C3, C4 100’s of Trades and Confirmations inflowing per second at peak hr Flowing in any order, not necessarily one after the other One trade can exactly match to one confirmation A trade can match to more than one confirmation One or more trades can match to one Confirmation 12
  • 13. DRL – Drools Rules Language rule "Perfect Match" salience 100 when t:Trade() c:Confirm(qty == t.qty , confirmId == t.cusip , amt == t.amt , price == t.price ) then log("Perfect Match for " + t.toString() + c.toString()); Match perfectMatch = new Match(t,c, "Perfect"); // retract perfect matches retract(t); retract(c); end Trade to Confirm Matching Why is this The base language for Rules Definition blazing All other Forms compile to this language fast ?? Rich and Versatile Entire Syntax, features and Rules definition is available Least User Friendly 13
  • 14. DSL - Domain Specific Language expander Match.dsl rule "Exact Match Trade to Confirm" when Match Trade and Confirm - on cusip with confirmId - on amt - on price then Log "Perfect Match“ Create Match with Status “Perfect” Remove Matched Elements end This is real code not Pseudo code DSL combines with grammar definition and translates to DRL Very Easy to Understand for Users and Visualize Power of creating new business vocabulary Encourages reuse 14
  • 15. Decision Table RuleTable TradeRequests NAME CONDITION CONDITION ACTION ACTION ACTION ACTION ACTION ACTION event:Event event:Event eventGroup $param != null TradeRequest tr = ne tr.setStartCaptureDate(DateUtils.getBusinessDate(event.get$1(), $2+1)); tr.setEndCaptureDate(DateUtils.getBusinessDate(event.get$1(), $2+1)); tr.setStartTradeDate(DateUtils.getBusinessDate(event.get$1(), $2)); tr.setEndTradeDate(Date tr.setSettlementF Trade Condition Event Start Capture End Capture Settlement (Comment Column) Name Group Date Present Trade Type Date Date Traded After Traded Before Flag TD < ED ; F = F IncOpenFail I effectiveDate Open Fails FreezeDate, 0 EffectiveDate, -1 "F" TD < ED ; SD <= FD ; F = O IncRegOpen I effectiveDate Regular Open EffectiveDate, -1 FreezeDate, 0 EffectiveDate, -1 "O" TD < ED ; FD < SD IncExtSet I effectiveDate Extended Settle EffectiveDate, -1 FreezeDate, 0 EffectiveDate, -1 ED<=TD ; SD <=FD ; CD <= FD IncShortSet I effectiveDate Short Settle EffectiveDate, 0 FreezeDate, 0 EffectiveDate, 0 TD < ED ; FD < PD IncAsOf I effectiveDate As of Trades FreezeDate, 1 EffectiveDate, -1 Corporate Actions Excel columns are designated as Conditions or Actions Top few control rows are hidden from users, Control rows help translate the excel into DRL Easy to understand for Users, once basic Excel formats are given Fit for use cases where there is need for intense parameterization 15
  • 16. Learning & Best Practices Experiences, Usage Models, Performance 16
  • 17. Real Life Experiences Complex Matching Engines • Multiple Engines used for various functional matching • Performed at 600 transactions / sec on one instance of execution • If the I/o (messaging / database) were commented, got 8k executions / sec • Stateful models used, but memory was conversed through optimizations Corporate Actions – Event Validations, Trade Extraction • Stateless model that evaluates each event separately through set of rules • 100’s of rules based on event types defined in Decision Tables • Increase in number of rules barely dent the performance • For 10k executions, 2 rules take 320 ms, and 100 rules take 328 ms Risk Analysis & Calculations • Calculations have lot of parameters, such as credit rating, product type, etc. • Calculations segmented into small number of individual steps • The decision of which formulae to use, was done by a Rules Engine 17
  • 18. Usage Models Synchronous Execution Request – Response Style Your Rule Application Engine Can act on the decision immediately Asynchronous Pipeline Rule Messaging Style Events Actions Engine Very scalable and resilient In Process with the Application Jar file as part of the application Excellent for Stateless execution, as reduces I/o without increasing memory Stateful executions are challenge in clustered environment & need memory sizing Out of Process as a runtime component Central Deployment & Management Overheads in Communication, and hence affects performance Could become bottleneck / central point of failure Needs sophisticated scaling models (e.g. functional split based on Hash or some key) 18
  • 19. Improving Performance ..1 Keep Separate Deployable Units rather than a giant rule engine component Divide and Conquer Use Stateless Sessions where Business case allows You can cluster and load balance your services seamlessly You can use in-process deployments easily Limit the number of facts in Stateful Executions The degradation is exponential beyond 400k objects in memory If higher volumes anticipated, than plan for multi deployments using sharding concepts Limit the Size of the objects checked in memory Use DTO (Data Transfer Object) pattern Use Batched Mode of Execution Check in more objects if you can in one go into the memory 19
  • 20. Improving Performance ..2 Use Drools only for decisions, not performing actual actions Let the decisions be communicated to a downstream component or by the caller to Rules Engine Avoid using evals(), --- use only as a last resort The java code inside eval is difficult to optimize into rete tree Work on aggregates where possible Rather than Checking Individual facts into the memory If you want to dig deeper Read more on the Rete Algorithm 20
  • 21. Development Tips Use the IDE Syntax Validations DSL conversions Drools Debugging Use events Understanding how rules activate and fire Helpful for troubleshooting Remember to turn off in production Keep individual rules small, simple and atomic Avoid cyclic triggering of rules when you update the facts Use Agenda groups & Activation groups wherever applicable 21
  • 22. Ajay Mahajan ajay.mahajan@wipro.com 22