`
sonic_yj
  • 浏览: 76892 次
  • 性别: Icon_minigender_1
  • 来自: CD
社区版块
存档分类
最新评论

[转贴] Drools 3.1 milestone 1 is comming

阅读更多

As some of you already know, Drools 3.1m1 will be out of the door any minute now. The Drools name is used for project development releases, which are also unsupported - eventually the code is hardened and released to production as JBoss Rules 3.2. This new release is a a big improvement over the 3.0.x production branch in many ways and it will be intersting to see where we will go from there.

For those curious about it, I will briefly talk about the major changes one expect to see when moving to it, from a core/compiler perspective.

Performance

After about 5-6 weeks of struggling led by Mark himself, most of the anchors slowing down JBRules 3.0 were simply left behind. By this I mean, no more internal structures for remembering matches, no more reference linking hell, no more overuse of array copies. Core was basically streamlined with a huge reduction on memory consumption and a significant performance boost. Benchmarks like manners, that stress the engine pattern matching algorithm are seeing improvements in the order of 300%, while memory comsuption is down to 20% of the original.
Does that means that 3.0 performance was bad? I would say not at all! Performance was actually good on 3.0, specially when compared with previous drools versions and other open source engines. But no big improvement was possible in the 3.1 version without breaking some paradigms we had before. And Mark did an amazing job pushing every little aspect to the limit to find exactly what we needed to change.
Does that mean real world applications will see improvements like that? Probably not in that order of magnitude, as benchmarks are designed to stress engines to its maximum, consequently generating extreme cases. Real world applications will certanly see great improvements, specially in the memory consumption side, but not in that order of magnitude. Actually I'm quite curious to test it in real use cases and see what will be the improvements.

Mark has provided a quick summary of the main enhancements:

  • Unrolled loops for constraint evaluation
  • High performance custom collections implementation
  • Tuple is now the entry, avoid Entry object creation.
  • Tuple, a wrapper for FactHandle[] during propagations, now uses a linked list as per Jess from "Implementing A High-Performance Symbolic Reasoning Engine In Java"
  • Composite key indexing for left and right memory
  • Left and right value caching for join nodes, to avoid repeated value retrieval
  • Improved alpha node hashing
  • Extensive use of Single/Composite design to avoid setting up a for loop when there is only 1 child
  • Primitive support, avoids continuous primitive wrapping

Primitive type support

As users know, JBRules 3.0 automatically wraps any primitive types he needs to work with in its respective Object Wrappers. That was a limitation that was causing 2 undesired side effects:
  1. Performance really suffers when one needs to wrap/unwrap primitives.
  2. Code using primitive wrappers is much more verbose and cluttered.
Example:
rule "return value"
when
$person1 : Person( $age1 : age )
person2 : Person( age == ( new Integer( $age1.intValue() + 2 ) ) )
then
...
end

As you can see in the above example, the rule's writer needs to be aware and keep wrapping/unwrapping primitive values to work with the engine.

JBRules 3.1m1 has now full support to primitive types, not only helping it to perform better and consume less memory but also making rules much more clear. Look at the same rule in 3.1m1:
rule "return value"
when
$person1 : Person( $age1 : age )
person2 : Person( age == ( $age1 + 2 ) )
then
...
end
It is now clear and straight forward to understand what the rule writer wanted his rule to do.

Shadow Facts support

As it is well known, JBRules uses POJO as its first and preferred fact representation structure. We design the engine targeting it to perform most efficiently on beans, as we understand that this is the most simple and productive way of integrating a rules engine in real world applications: work with user's own business objects model. Although, this kind of integration demands a carefull planing on the engine side to avoid collateral effects, as the engine do not own the beans. The application or the user can change any bean property on the fly and not notify the engine.
So it is mandatory that the engine implements some kind of control over the values being used for reasoning, keeping the whole engine state consistent. This is implemented by Shadow Facts, that are shallow copies (cache) of the bean values while reasoning over it, allowing updates only on safe points.
Shadow Facts are implemented in JBRules 3.1m1 as dynamic proxies and besides being mandatory to have from an engine perspective, they are almost invisible for the engine users. I say almost, because being dynamic proxies, there is only one requirement users need to meet: a nonarg default constructor for the classes asserted into the engine. Besides that, users don't have to worry about it. Only to know, their facts are being taken care appropriatelly. The proxy is not exposed to users, not even in consequence block.

New nodes

Evolving the engine also requires support to some new conditional expression elements. Three new CEs are included in 3.1m1, being them:

FROM: allows reasoning over facts not previously asserted into the engine. Specially useful for retrieval of facts on the fly from database tables or any other external source. Example:
rule "From"
when
$cheese : Cheese(type == "stilton" ) from cheesery.getCheeses()
then
// do stuff
end
COLLECT: allows reasoning over collections of objects from working memory. Example:
rule "Collect"
when
$cheeseList : ArrayList(size > 2) from collect( Cheese( price < 30 ) ) ;
then
// do stuff
end

ACCUMULATE: a more flexible and customizable version of Collect, allows to iterate and calculate values from a set of facts in the working memory. Example:
rule "Accumulate"
when
$person      : Person( $likes : likes )
$cheesery    : Cheesery( totalAmount > 100 )
                          from accumulate( $cheese : Cheese( type == $likes ),
                                           init( Cheesery cheesery = new Cheesery(); ),
                                           action( cheesery.addCheese( $cheese ); ),
                                           result( cheesery ) );
then
// do stuff
end
Conclusion

These are the main features you will se in this milestone from a core/compiler perspective. New milestones will bring even more news, specially related to the Rule Server under development as described in a previous post.

So, stay tunned, enjoy, and please provide us your feedback.

Edson

 

分享到:
评论

相关推荐

    drools drools drools drools drools

    1. LICENSE-ASL-2.0.txt:这通常表示项目遵循Apache Software License 2.0,这是一个开源许可协议,允许用户自由使用、修改和分发软件,但可能需要保留原始版权信息和许可声明。 2. JBossORG-EULA.txt:这可能是指...

    规则引擎处理复杂对象论坛1

    1. 使用`eval`:`eval`是Drools中一个通用的表达式执行器,它可以执行任何Java代码,因此可以用来处理复杂的逻辑。然而,`eval`的使用往往被建议避免,因为它降低了规则的可读性和可维护性,同时也可能影响性能。 2...

    Drools5.3官网手册

    Drools 可以像任何常规 Camel 组件一样配置,但需要注意的是策略会包装与 Drools 相关的部分,这将把所有有效载荷路由到 ksession1。 **示例**: ```xml &lt;bean id="droolsPolicy" class="org.drools.camel....

    drools7.25中文文档+drools技术指南.zip

    1. **Drools概述**:这部分将介绍Drools的基本概念,包括什么是规则引擎,为什么需要规则引擎,以及Drools在业务流程中的作用。它会阐述Drools如何帮助开发者将业务逻辑从核心应用程序中分离出来,实现灵活的、可...

    Drools

    Drools是一款强大的Java规则引擎,它为业务规则管理提供了高效、灵活且可扩展的解决方案。作为基于模型的决策自动化工具,Drools允许开发者将复杂的业务逻辑编码为一系列易于理解和维护的规则,这些规则可以独立于...

    droolsdroolsdrools

    1. 规则定义:Drools的规则通常使用DRL(Drools Rule Language)编写。例如,一个简单的DRL规则可能如下: ```drl rule "Age Check" when $person : Person(age ) then System.out.println($person.getName() +...

    Drools6.5 部署Drools Workbench和Kie Server笔记

    1. **下载Drools Workbench**:从官方网站下载kie-drools-wb-6.5.0.Final-tomcat7.war文件,这是适用于Tomcat7的Drools Workbench的WAR包。 2. **配置Tomcat**:将WAR包重命名为kie-drools-wb,并将其放入Tomcat的...

    Drools应用.doc

    3.1 导入drools依赖包 在使用Drools时,需要在项目中引入相应的Maven或Gradle依赖,以获取Drools的运行时库和API。 3.2 Hello Drools 创建一个简单的Drools项目通常包括定义规则文件(.drl),创建KieSession,加载...

    规则引擎Drools.NET移植版

    **规则引擎Drools.NET移植版** Drools是一款强大的业务规则管理系统,源自Java社区,以其灵活、高效和可扩展的特性而广受赞誉。它允许开发者将业务逻辑以规则的形式编写,使得业务规则可以独立于应用程序代码进行...

    Drools6 和 Drools7技术指南-中文文档.zip

    Drools开发最全中文版技术指南。 Drools开发最全中文版技术指南,介绍了常见的drools如何进行开发,注意是:中文版中文版中文版! drools 中文文档 规则引擎 drools6 drools7 Java

    [Drools]JAVA规则引擎 -- Drools

    【Drools】JAVA规则引擎 -- Drools Drools 是一个开源的业务规则管理系统(BRMS),它基于Java语言,提供了强大的规则引擎,帮助企业快速实现业务规则的编写、管理和执行。Drools 受到了广泛的欢迎,尤其在那些需要...

    5.6drools基础包

    1. **Drools Engine**: Drools引擎是整个框架的核心,它负责执行规则。规则是由一系列条件和行动组成的,当条件满足时,就会执行相应的行动。Drools引擎采用rete算法来高效地处理大量的规则。 2. **Drools工作记忆...

    drools安装与配置

    1. **Drools简介** Drools的核心概念是规则引擎,它允许程序员编写业务规则,这些规则可以在运行时动态地插入、修改和删除。规则引擎根据给定的事实(数据)来触发规则的执行,从而实现复杂的业务逻辑。 2. **安装...

    Drools workbench文件及DEMO项目代码

    1. **Drools规则语言(DRL)**:Drools的规则定义语言,用于编写业务规则。 2. **KieWorkbench**:Drools工作台的一部分,提供了规则的可视化编辑工具。 3. **Guvnor**:Drools早期版本中的规则仓库,现在通常被...

    drools flow分析报告

    **Drools Flow 分析报告** **第一章 Drools Flow 简介** Drools Flow 是 Drools 项目的一部分,它提供了一套完整的业务流程管理(BPM)和工作流解决方案。Drools 是一个开源的规则引擎,主要用于决策管理和业务...

    drools动态生成规则文件

    1. 使用Java API:drools提供了API,如KnowledgeBuilder,可以用来构建和加载规则。通过添加RuleBuilder对象,我们可以构建规则,然后将其添加到KnowledgeBase,使得规则能够在运行时被应用。 2. 字符串模板:可以...

    Drools6-笔记

    1. **添加Drools和JUnit库**:在项目的类路径中添加Drools和JUnit库。 2. **建立Drools的UserLibraries**:在IDE中配置UserLibraries,将Drools和JUnit添加进去。 ##### 2.3 创建测试用例 1. **编写测试类**:使用...

    Drools规则引擎使用demo

    1. **Drools核心概念**: - **规则(Rule)**:是Drools中的基本单位,包含条件(LHS,左侧)和行动(RHS,右侧)。条件是触发规则执行的事件或状态,行动则是当条件满足时执行的操作。 - **事实(Fact)**:是...

    drools实现demo

    1. **Drools基本功能**:Drools的核心是其规则引擎,它能解析、验证和执行由Drools Rule Language (DRL)编写的规则。DRL是一种声明式的语言,类似于SQL,但用于表达业务规则。在第一个demo中,很可能演示了如何创建...

Global site tag (gtag.js) - Google Analytics