Skip to main content

JBoss BRMS - JBoss Rules 的 RETE 演算法

恭喜發財!新年快樂 ! 放了年假回來才發現這篇遲遲沒有發,

JBoss Rules 是屬於JBoss BRMS 的其中一環。
JBoss BRMS 是一個給企業建制整合商業邏輯,商業流程以及商業事件的平台。


而同上圖一樣,JBoss Rules 就是負責建制商業邏輯的一部分。

很多人都會問我,請問JBoss Rules 的效能好不好,再好的效能,如果用了很差的寫法一樣都會差的。要寫得好,也要先了解JBoss Rules 的內部演算方式。

JBoss Rules 的演算方式,始使用類似google 搜尋的演算法,這個演算法是Dr. Charles Forgy 在1982年發表的。 RETE 這個名字在拉丁文的意思是"網路"。簡單來說,這個就是在計算Rules如何在記憶體裡面建立網路,然後如何在這個建立的網路中"過濾"到出現結果。

這種演算法比一般的Rules快速多了,以前,在我很"年輕"的時候,我也有想做過同樣的事情,因此,我設計了一套邏輯,讓那些負責制定晉升規則的非IT人也可以去定義,所謂的保險業務員升遷邏輯,例如說,在幾月幾日之前,第一年保險費累積超過XX, 且其中的健康險保費佔了xxx%,且屬下的保費累積大於xxx, 等等等複雜,它就可以晉升。
為了要確認每個條件都被跑過,必須要下很多次的迴圈確認。 唉~那時候如果有JBoss Rules 這種東西,應該省了不少功吧。


RETE 基本上有5個不同的部分,


Root Node
這沒啥好說的,就是開始的起始點。所以Fact 就是從這個起始點進入RETE的網路中。

Object Type Node
主要分類不同的物件,如這個範例中,有三個不同的物件,貓,食物與主人。

Alpha Network
初步的過濾,針對上一層OTN 的物件上面的限制,如範例分析貓這個物件,裡面的品種,市街貓還是波斯貓。


Beta Network
這是把兩個以上的過濾結果結合的步驟,Alpha node 後,會有個LeftInputAdapter 指引之後要連接的到Beta Network的位置。下面的範例則是把波斯貓以及飼料大於1,000元以上的結果結合在一起。

Terminal Node 
這就是結束的點,所有結束的點都代表著需要被執行的Activation,而這些Activation 就會被放在Agenda等待執行了。


JBoss Rules 為了效能的因素,必須要將許多資料暫存在memory 中,因此他最大的限制是在記憶體的消耗,反倒不是執行時候CPU的需求。而JBoss Rules 最慢的兩的點就在於一開始的網路建立,以及將Fact Load 進記憶體的時候。



相關技術參考網站:
wiki
salaboy 
drools
Red Hat

Comments

Popular posts from this blog

Red Hat JBoss Fuse/A-MQ - Fuse and A-MQ Version 6.3 GA is released!

Fuse and A-MQ 6.3 GA has just went out. Maybe, you would think this is just only a minor version release why should I care? Hold your thoughts on that! Because they have done a lot of improvements and also added many new features into this release.

Besides various bug fixes and making sure Fuse Fabric is much more stable. There are two major change in this version update:

New Tooling in JBoss Developer Studio (JBDS) 9.1 GA. Newer Apache Camel version – Camel v2.17. I was really impressed by the work put in to make developing Camel application much simpler. First is the installation of tooling itself. Now it has a all-in-one installer so you don't need to worry about which plugins you need to check. See the videos below to see the new "Getting Started" of Fuse 6.3.



And If you notice from the above video, the presentation of camel route in JBDS has also updated. It fixed some of the miss representation of logic and making it easier to read.

Old Camel Route
New Camel Route
On …

Fuse Integration Service - Setup JBDS and create first quickstart application

Before we go and start creating our first application, I want to show you how to setup your JBoss Developer Studio, create a small application from the quickstart example and then running it on Fuse Integration Service.

I am using JBoss Developer Studio version 9, you can find it here.
After download the

jboss-devstudio-9.0.0.GA-installer-eap.jar
double-click it, and start installing with default values.

After successful installation, we will need install the plugins for Fuse, on JBoss Central view, select software update, select enable early access.


And select JBoss Fuse Development for the plugin,


Click on install, and we are all set to go!

First thing first, we want to create a Fuse project to deploy on the base of Fuse Integration Service, which is OpenShift. If you have not installed it, please go back to my previous post for instructions. So on your JBDS, right click and start creating the project. Select new, maven project, if you have installed the plugin correctly, you should …

Red Hat JBoss Fuse - Getting Started with Fuse Integration Service 2.0 Tech preview

I just realized that I did not do a getting started for Fuse Integration Service 2.0 Tech preview before I did the pipeline demo, thanks for those of you who reminded me! :)

To get started with FIS 2.0, for people who has just getting to know the technology, here is how I interpret it. Basically, it's divide into two aspect,

1. Integration development, FIS uses Apache Camel as the core technology that creates, orchestrate, compose microservices into a super lightweight thin integration layer, and become the API provider and service orchestrator through exposing RESTful or messaging service endpoints. And you can choose to either package and run it with Spring-Boot or Karaf.


2. Application Deployment and Management, FIS takes advantages of OpenShift platform, and allows you to separately deploy the micro-integration service among distributed environment, at the same time takes care of the failover, high availability, load balancing and service lookup problem for you.


So, now we know …