Replication of StatefulSessionBeans in an EAP cluster

Solution Verified - Updated -

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6
    • 7

Issue

  • What is the requirement to replicate the state of a StatefullSessionBean (SFSB) in an EAP cluster?
  • After migrate from EAP6 to EAP7 we get a huge performance drop when using SFSB's, what is the reason?
  • How to disable replication for SFSB's ?
  • Is it possible to exclude one SFSB from the replication in a cluster?

Resolution

To have failover the internal state of a SFSB needs to be replicated in a cluster to have other instances which can continue with the process.
From EAP6 to EAP7 there are substantial changes as the @org.jboss.ejb3.annotation.Clustered annotation has been deprecated and the internal implementation changed also.

Because of the change it is possible that the replication was not enabled for EAP6 but get enabled by default when deployed at EAP7. This might be noticed as performance issue if there are huge SFSB's in use.

Note If SFSB's are used from web applications consider to have both, the web http session and the SFSB, replicated because the failover will not work otherwise.

The EJB proxy for such SFSB will take care of the routing to the correct server, as after the lookup is done the proxy is bound to a dedicated SFSB and is marked to use the server where the bean was created as long as the server is responsive. Also it will prefer the local instance if possible.

StatefullSessionBean replication with EAP6

To enable the replication it is indispensable to have a server configuration with ha, this will enable the cluster functionality. Additional each SFSB needs to be annotated by @Clustered or the deployment descriptor jboss-ejb3.xml need to enable this for the bean.

StatefulSessionBean replication with EAP7

Since EAP7 the @Clustered annotation is not longer necessary, it is still in the API but this is for code compatibility only and it will be ignored at runtime.
If the server is configured with a ha profile the cluster is enabled if an application contains EJB's or distributed web applications.
Because of this all SFSB's are replicated by default!
If this is not wanted the EJB specification allow to supress this with the following attribute for the @Stateful annotation

@Stateful(passivationCapable=false)

For the EAP server instance this has the effect of using the ejb cache defined by passivation-disabled-cache-ref, instead of the ejb cache defined by cache-ref, so in fact the state is not replicated over the wire to any other node.

To disable the SFSB replication completly the cache-ref attribute can be set to simple - similar to passivation-disabled-cache-ref - which has the same effect as setting passivationCapable=false for all SFSB's. This is the same as the non ha configuration.

<stateful default-access-timeout="5000" cache-ref="simple" passivation-disabled-cache-ref="simple"/>

See Documentation Developing Jakarta Enterprise Beans Applications for more information.

Root Cause

Due to changes within the spec it is sometimes necesary to change the behaviour of the implementation or the related annotation which might was vendor specific but later defined (different) by the EJB specification.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments