Weblogic中关于缓存跟钝化有状态会话EJB

Weblogic中关于缓存和钝化有状态会话EJB

在前些天的项目里,发现一个关于WebLogic 缓存和钝化有状态会话EJB 的问题。

简单描述下:

===========================================

cache-type 设置为NRU 的时候,按照官方文档上的描述:

 

Lazy Passivation ( NRU )

When lazy passivation is configured by setting cache-type to NRU , the container avoids passivating beans, because of the associated systems overhead—pressure on the cache is the only event that causes passivation or eager removal of beans.

The container:

  • Removes a bean instance from cache when idle-timeout-seconds expires, and does not passivate it to disk. This is referred to as a eager remove . An eager remove ensures that an inactive instance does not consume memory or disk resources.
  • Passivates instances to disk when max-beans-in-cache is reached, even though idle-timeout-seconds has not expired.
懒 钝化 (NRU )

cache-type 被配置为NRU 的时候,容器会回避钝化Bean,因为关系到关联的系统的缓存开销,导致钝化或渴望删除Beans。

The container:

  • 当经过idle-timeout-seconds (闲置时间)时从Cache里直接删除bean,而不是钝化到硬盘上。这被作为一个渴望删除。 一个渴望删除保证了不会耗尽内存和硬盘资源。
  • 当达到max-beans-in-cache 时 钝化硬盘上的bean实例,即使没有超过idle-timeout-seconds (闲置时间)

 

 

详见:摸我 图5-2 之后

=============================================================

也就是说设置成NRU时 如果超过idle-timeout-seconds 时间就会把Cache中的Bean直接干掉。图5-2 也是这么画的。

但项目中始终没有验证出这个结论----即使经过闲置时间,不管超没超过max-beans-in-cache ,也不会从Cache中删除-------开始以为项目本身的框架有一些特殊的实现导致的,后来就做了一个纯净版的ejb sample(见附件)。发现结果还是这样。

 

难道是Oracle的文档的问题 还是Bug,还是自己在验证中出现了什么差错? 不解!!!

 

后来添附上Sample 问了一下Oracle。一个月过去了,还是没有答复。

想请教一下大家,原因是什么?

为什么超过 idle-timeout-seconds 时间后没有像官方文档上描述的"直接从内存中删除Bean"?

 

 

****************************************************************************

附上相关文档说明:

cache-type

功能

指定从缓存中删除 EJB 的顺序。值包括:

  • 最近最少使用(Least recently used,简称 LRU)
  • 最近未使用(Not recently used,简称 NRU)
  • NRU 缓存大小的最小值为 8。如果 max-beans-in-cache 小于 3,WebLogic Server 会对 max-beans-in-cache 使用 8 这个值。

示例

<stateful-session-cache>
    <cache-type>NRU</cache-type>
</stateful-session-cache>

 

Controlling Passivation

The rules that govern the passivation of stateful session beans vary, based on the value of the beans cache-type element, which can be:

  • LRU —least recently used, or eager passivation.
  • NRU —not recently used, or as lazy passivation
****************************************************************************
1 楼 <>++< 2011-10-27  
Oracle公司终于给出回答了。
说在NRU的场合,EJB经过idle-timeout-seconds之后也可能不会从cache中直接删除,原因是从cache直接删除的时机话,还要看Cache的剩余容量;而关于EJB的缓存管理有复杂的内部运算和行为。这个操作是很难的部分。
=========================================
说白了,等于没回答一样,坑爹的回答。。。再次对Oracle失望。。。

所以官方文档上的描述也未必是正确的,实践是检验真理的唯一标准啊。。。
2 楼 <>++< 2011-11-01  
补充: 这个问题在weblogic培训的时候问了一下王超www.beansoft.biz 他不建议用10g3版本的weblogic 说在这版本发布的期间 正是oracle对其收购的时候,但是此问题的具体原因还是没有完全解决。
3 楼 <>++< 2011-11-07  
remove idle bean only when pressure on cache
也就是说 NRU时只有当缓存有压力的情况下,才会直接从Cache里删除闲置Bean。
这个说明的比较详细:
http://www.oracle.com/us/products/database/perf-tune-session-beans-093360.html

另外还有关于NRU和LRU的选择 上边的文章里也写了。
首先Ejb的钝化和激活是很耗性能的,因为调用了昂贵的序列化和反序列化操作。
为了造成不必要的钝化和激活的开销。
当内存资源是稀缺的时候,还是使用LRU策略比较好。
因为此时此刻NRU的状态下,还会始终对有状态的EJB调用ejbRemove()