What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference

2,737
-1

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
2,737
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
99
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

What is Drools, Guvnor and Planner? 2012 02-17 Brno Dev Conference

  1. 1. Geoffrey De Smet What are Drools, Guvnor and Planner?
  2. 2. Business Logic Integration Business Logic Integration Rule engine Workflow Complex event processing (CEP) Business Rule Management System (BRMS) Automated planning
  3. 3. When should I use them? Drools and Guvnor
  4. 4. A Drools rule rule &quot;No-risk mortgage&quot; when $m : Mortgage( amount < 5000.0 ) Applicant( age < 50 , income > 1000.0 , mortage == $m ) then $m .setApproved( true ); $m .setInterest( 2.00 ); end DRL pattern Java code
  5. 5. The myth <ul><li>Drools is a rule engine
  6. 6. So because </li><ul><li>Drools can fulfil business rules
  7. 7. Drools is Turing complete </li></ul><li>we should write the entire business layer in Drools? </li><ul><li>No!
  8. 8. Not imperative </li><ul><li>Not like Java, Scala, Groovy, ... </li></ul><li>Declarative </li><ul><li>Like RegEx, SQL, JPA-QL, …
  9. 9. Easier to read, better at scaling </li></ul></ul></ul>
  10. 10. When to use Drools <ul><li>Extract business decisions in Drools that either: </li><ul><li>Require schooled domain expertise
  11. 11. Change often/fast </li></ul></ul>
  12. 12. Use cases <ul><li>Financial decisions </li><ul><li>Mortgages acceptance and interest calculation
  13. 13. Insurances acceptance and fee calculation </li></ul></ul>
  14. 14. Use cases <ul><li>Financial decisions </li><ul><li>Mortgages acceptance and interest calculation
  15. 15. Insurances acceptance and fee calculation </li></ul><li>Price calculations </li><ul><li>Phone/Telecom bills </li></ul></ul>
  16. 16. Use cases <ul><li>Financial decisions </li><ul><li>Mortgages acceptance and interest calculation
  17. 17. Insurances acceptance and fee calculation </li></ul><li>Price calculations </li><ul><li>Phone/Telecom bills </li></ul><li>Diagnostics </li><ul><li>Possible diseases based on symptoms </li></ul></ul>
  18. 18. Use cases <ul><li>Financial decisions </li><ul><li>Mortgages acceptance and interest calculation
  19. 19. Insurances acceptance and fee calculation </li></ul><li>Price calculations </li><ul><li>Phone/Telecom bills </li></ul><li>Diagnostics </li><ul><li>Possible diseases based on symptoms </li></ul><li>Not a good use case: an XML parser </li><ul><li>Use Java code for that </li></ul></ul>
  20. 20. Mortgages example
  21. 21. Developers don't like data input from spreadsheets <ul><li>Before App 1.0: Mortgages rules in a spreadsheet </li><ul><li>Which version/copy of the spreadsheet file?
  22. 22. Which field has the result our application needs? </li></ul></ul>Version 1 Version 2
  23. 23. Mortgage experts like the flexibility of spreadsheets <ul><li>Since App 1.0: Mortgages rules in source code </li><ul><li>Changing business rules not flexible enough
  24. 24. Business rules are hard coded in Java </li></ul></ul>Invalid: must be a number
  25. 25. Mortgage experts change their mind a lot <ul><li>Flooded with new improvement requests: </li><ul><li>when income below 500
  26. 26. when income below 1000 and age above 50
  27. 27. when income below 1% of mortgage amount </li></ul></ul>Invalid: must be a number
  28. 28. Mortgage experts like the flexibility of Guvnor <ul><li>App 2.0: Mortgage rules in Guvnor repository </li><ul><li>Flexible like spreadsheet </li><ul><li>But backed by formal DRL and JavaBeans </li></ul><li>No spreadsheet versions/copies </li></ul></ul>
  29. 29. My business requires domain expertise Only mortgage managers understand mortgage rules
  30. 30. Schooled domain expertise <ul><li>Are we, the developers, domain experts? </li><ul><li>Yes, we've been working in this company for year(s). </li></ul></ul>
  31. 31. Schooled domain expertise <ul><li>Are we, the developers, domain experts? </li><ul><li>Yes, we've been working in this company for year(s). </li></ul><li>Do we have </li><ul><li>university's degree in economics? No
  32. 32. participated in mortgages conferences/courses? No
  33. 33. years of mortgage customer experience? No </li></ul></ul>
  34. 34. Schooled domain expertise <ul><li>Are we, the developers, domain experts? </li><ul><li>Yes, we've been working in this company for year(s). </li></ul><li>Do we have </li><ul><li>university's degree in economics? No
  35. 35. participated in mortgages conferences/courses? No
  36. 36. years of mortgage customer experience? No </li></ul><li>Do we have a clue when the mortgage rules need to change? No </li></ul>
  37. 37. Schooled domain expertise <ul><li>Are we, the developers, domain experts? </li><ul><li>Yes, we've been working in this company for year(s). </li></ul><li>Do we have </li><ul><li>university's degree in economics? No
  38. 38. participated in mortgages conferences/courses? No
  39. 39. years of mortgage customer experience? No </li></ul><li>Do we have a clue when the mortgage rules need to change? No
  40. 40. Are we, the developers, domain experts? No </li><ul><li>Mortgage manager is the domain expert </li></ul></ul>
  41. 41. Domain experts can not read/write Java source code <ul><li>Communication problem </li><ul><li>Domain expert can not read it: </li></ul></ul>for (Mortgage m : mortgages ) { for (Applicant a : m.getApplicants()) { if (a.getAge() > 70 ) { boolean existsGuarantor = false ; for (Guarantor g : m.getGuarantors() { if (g.getAge < 60 ) { existsGuarantor = true ; } } // Will they spot the bug in this code? if (existsGuarantor) { m.setApproved( false ); } } } }
  42. 42. Domain experts can read rules in the Guided Rule Editor
  43. 43. Domain experts can write rules in the Guided Rule Editor Change
  44. 44. Translated to DRL Executed on JavaBeans
  45. 45. Natural language (DSL) <ul><li>DSL is even easier to read/write </li></ul><ul><li>Developers create the building blocks
  46. 46. Domain experts make the building </li></ul>Source: wikipedia
  47. 47. My business rules change often This mortgage rule change must be released by noon
  48. 48. Deliver changes fast
  49. 49. Deliver changes fast
  50. 50. Deliver changes fast
  51. 51. Business rule change <ul><li>Not a data change </li><ul><li>Requires test and release lifecycle
  52. 52. Logic changes </li></ul><li>Not a software change </li><ul><li>Delivered in hours, not days
  53. 53. Self-service by mortgage manager </li></ul></ul>
  54. 54. Test before releasing <ul><li>Domain experts need to unit test too </li><ul><li>Example: mortgage of Erik must be disapproved </li></ul></ul>
  55. 55. Do more with less Planner
  56. 56. Demo Drools Planner TSP example
  57. 57. Every organization has planning problems.
  58. 58. What is a planning problem? <ul><li>Complete goals
  59. 59. With limited resources
  60. 60. Under constraints </li></ul>
  61. 61. Hospital bed scheduling <ul><li>Assign each </li><ul><li>Patient </li></ul><li>To </li><ul><li>Bed </li></ul><li>Constraints </li><ul><li>Length of stay
  62. 62. Room requirements
  63. 63. Room preferences </li></ul></ul>http://www.flickr.com/photos/markhillary/2227726759/
  64. 64. Hospital nurse rostering <ul><li>Assign each </li><ul><li>Shift </li></ul><li>To </li><ul><li>Nurse </li></ul><li>Constraints </li><ul><li>Employment contract
  65. 65. Free time preferences
  66. 66. Skills </li></ul></ul>http://www.flickr.com/photos/glenpooh/709704564/
  67. 67. School timetabling <ul><li>Assign each </li><ul><li>Course </li></ul><li>To </li><ul><li>Room
  68. 68. Timeslot </li></ul><li>Constraints </li><ul><li>No simultaneous courses </li><ul><li>Per room
  69. 69. Per teacher
  70. 70. Per student </li></ul></ul></ul>http://www.flickr.com/photos/phelyan/2281095105/
  71. 71. Airline routing <ul><li>Assign each </li><ul><li>Flight </li></ul><li>To </li><ul><li>Airplane
  72. 72. Crew </li></ul><li>Constraints </li><ul><li>Airplane/crew depart from where they arrive
  73. 73. Minimize mileage </li></ul></ul>http://www.flickr.com/photos/yorickr/3674349657/
  74. 74. Bin packing in the cloud <ul><li>Assign each </li><ul><li>Process </li></ul><li>To </li><ul><li>Server </li></ul><li>Constraints </li><ul><li>Hardware requirements
  75. 75. Minimize server cost </li></ul></ul>http://www.flickr.com/photos/torkildr/3462607995/
  76. 76. Bin packing in the cloud <ul><li>Assign each </li><ul><li>Process </li></ul><li>To </li><ul><li>Server </li></ul><li>Constraints </li><ul><li>Hardware requirements
  77. 77. Minimize server cost </li></ul></ul>http://www.flickr.com/photos/torkildr/3462607995/
  78. 78. Which processes do we assign to this server?
  79. 79. How did we find that solution?
  80. 80. First fit by decreasing size
  81. 81. First fit by decreasing size
  82. 82. First fit by decreasing size
  83. 83. First fit by decreasing size
  84. 84. Another case
  85. 85. Try FFD again
  86. 86. Try FFD again
  87. 87. Try FFD again
  88. 88. Try FFD again
  89. 89. FFD failure
  90. 90. NP complete
  91. 91. NP complete <ul><li>No silver bullet known </li><ul><li>Holy grail of computer science </li><ul><li>P == NP </li></ul><li>Probably does not exist </li><ul><li>P != NP </li></ul></ul><li>Root problem of all planning problems </li></ul>http://www.flickr.com/photos/annguyenphotography/3267723713/
  92. 92. Multiple servers...
  93. 93. Multiple servers...
  94. 94. Multiple servers...
  95. 95. Multiple servers...
  96. 96. Multiple constraints...
  97. 97. Multiple constraints...
  98. 98. Multiple constraints...
  99. 99. Multiple constraints...
  100. 100. Organizations rarely optimize planning problems.
  101. 101. Reuse optimization algorithms?
  102. 102. <ul><li>Open source (ASL 2.0)
  103. 103. Regular releases
  104. 104. Reference manual
  105. 105. Examples </li></ul>
  106. 106. Demo Drools Planner CloudBalance example
  107. 107. Optimization algorithms
  108. 108. Brute Force
  109. 109. Brute force scalability 6 processes = 15 ms 9 processes = 1.5 seconds * 100
  110. 110. Brute force scalability 12 processes = 17 minutes 6 processes = 15 ms 9 processes = 1.5 seconds * 100 * 680
  111. 111. Plan 1200 processes with brute force?
  112. 112. First Fit
  113. 113. First Fit scalability
  114. 114. First Fit results CPU: OK RAM: OK Network: OK Cost active servers: shown
  115. 115. First Fit Decreasing
  116. 116. First Fit Decreasing scalability
  117. 117. First Fit Decreasing results
  118. 118. Local Search
  119. 119. Local Search results
  120. 120. Cost ($) reduction <ul><li>Compared to First Fit </li><ul><li>First Fit Decreasing </li><ul><li>49 480 $ = 4 % </li></ul><li>Tabu Search </li><ul><li>160 860 $ = 14 % </li></ul><li>Simulated annealing </li><ul><li>128 950 $ = 11 % </li></ul></ul><li>Few constraints here </li><ul><li>=> low ROI </li></ul></ul>
  121. 121. Organizations rarely optimize planning problems.
  122. 122. http://www.flickr.com/photos/techbirmingham/345897594/ Organizations waste resources.
  123. 123. Summary
  124. 124. Summary <ul><li>Use Drools and Guvnor when your business decisions either </li><ul><li>Require domain expertise
  125. 125. Change often/fast </li></ul><li>Use Planner to optimize planning </li><ul><li>Adding constraints is easy and scalable
  126. 126. Switching/combining algorithms is easy </li></ul></ul>
  127. 127. Try an example!
  128. 128. Q&A <ul><li>Drools, Guvnor and Planner homepage </li><ul><li>http://www.jboss.org/drools </li></ul><li>Reference manual: </li><ul><li>http://www.jboss.org/drools/documentation </li></ul><li>Download this presentation </li><ul><li>http://www.jboss.org/drools/presentations </li></ul><li>Twitter: @geoffreydesmet
  129. 129. Google+: Geoffrey De Smet </li></ul>

×