EJB container tuning
If you use applications that affect the size of the Enterprise JavaBeans (EJB) container cache, it is possible that the performance of your applications can be affected by an incorrect size setting. Container managed persistence (CMP) is discussed in this topic; although it is important to know that entity beans are not supported in an EJB 3.x module.
This topic provides information about tuning the Enterprise JavaBeans 2.1 container.
EJB cache size
Monitor Tivoli® Performance Viewer to diagnose whether the EJB container cache size setting is tuned correctly for your application.
If the application has filled the cache causing evictions to occur, Tivoli Performance Viewer shows a high rate of the ejbStores method being called and probably a lower than expected processor utilization on the workstation machine.
- EJB_Cache_Size = (Largest number of Option B or C entity beans enlisted in a transaction * maximum number of concurrent transactions) + (Largest number of unique Option A entity beans expected to be accessed during typical application workload) + (Number of stateful session beans active during typical workload) + (Number of stateless session bean types used during typical workload)
- Option B and C entity beans are only held in the EJB cache during the lifetime of the transaction they are enlisted in. Therefore, the first term in the formula computes the average EJB cache requirements for these types of beans.
- Option A entity beans are held in the EJB cache indefinitely, and are only removed from the cache if there starts to become more beans in the cache than the cache size has been set to. If your application uses Read Only Beans, consider them to be Option A beans for this tuning calculation.
- Stateful session beans are held in the EJB cache until they are removed by the application, or until their session timeout value is reached.
- Only a single stateless session bean instance for each EJB type is held in the cache during the time any methods are running on that stateless session bean. If two or more methods are being implemented simultaneously on the same stateless session bean type, each method runs on its own bean instance, but only one cache location is used for all of these instances.
This formula calculates the upper bound on the maximum number of enterprise beans active at one time inside the application server. Because the cache of the EJB container is built to contain all these beans for performance optimizations, best performance can be achieved by setting this cache size to be larger than the number resulting from the previous formula.
You can set the EJB cache size in the administrative console under
.Also, while adjusting the EJB cache size, you can tune the EJB container management thread parameter to meet the needs of the application. The management thread is controlled through the Cleanup interval setting. This setting controls how frequently a daemon thread inside of the product attempts to remove bean instances from the cache that have not been used recently, attempting to keep the number of bean instances less than or equal to the cache size. This behavior ensures that the EJB container places and looks up items in the cache quickly. Leave this interval set to the default; however, in some cases, it might be worthwhile to see if there is a benefit to reducing this interval.
For information about tuning the EJB cache using the EJB cache trace service, read about tuning the EJB cache and using the trace service.
EJB stateful session bean tuning
Stateful session bean timeout is configured in different ways, with different scopes, depending on the version of WebSphere® Application Server.
WebSphere Application Server Version 6.1 and earlier supports configuration of stateful session bean timeout, per bean, using the ibm-ejb-jar-ext.xmi file.
WebSphere Application Server Version 7.0 supports configuration of stateful session bean timeout, per bean, using the ibm-ejb-jar-ext.xmi file (for EJB 2.x modules), and the ibm-ejb-jar-ext.xml file (for EJB 3.x modules).
WebSphere Application Server Version 8.x supports configuration of stateful session bean timeout, per bean, using the ibm-ejb-jar-ext.xmi (for EJB 2.x modules) and the ibm-ejb-jar-ext.xml (for EJB 3.x modules) files, and the stateful-timeout XML element and the @StatefulTimeout annotation. Additionally, you can configure a server-wide (global) stateful session timeout value using the com.ibm.websphere.ejbcontainer.defaultStatefulSessionTimeout system property.
However, a Java EE 5 or later module can exist within an application that includes pre-Java EE 5 files and uses the .xmi file name extension.
The ibm-webservices-ext.xmi, ibm-webservices-bnd.xmi, ibm-webservicesclient-bnd.xmi, ibm-webservicesclient-ext.xmi, and ibm-portlet-ext.xmi files continue to use the .xmi file extensions.
Stateless session beans do not have a timeout value because they have no conversational state and are not dedicated to any specific client.
You can use Rational® Application Developer to update the ibm-ejb-jar-ext.xmi file, which is used to configure the stateful session timeout value for beans in an EJB 2.x module. For more information, read about defining session timeout settings for a bean in the Rational Application Developer documentation.
<ejbExtensions xmi:type="ejbext:SessionExtension" xmi:id="SessionExtension_1"
timeout="900">
You can modify the ibm-ejb-jar-ext.xml file to set the stateful session timeout for beans in an EJB 3.x module. For example, the code to set a stateful session timeout value to 15 minutes (900 seconds) for the myBean bean is:
<ejbExtensions xmi:type="ejbext:SessionExtension" xmi:id="SessionExtension"
timeout="900">
<enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml#MyBean"/>
</ejbExtensions>
You can configure stateful session bean timeout using the @StatefulTimeout annotation. The @StatefulTimeout annotation takes a required value parameter representing the duration of the timeout, and an optional unit parameter. If the optional unit parameter is not specified, the default unit is minutes. The @StatefulTimeout annotation is introduced as part of EJB 3.1.
For example, use the @StatefulTimeout annotation to declare a timeout value of 100 seconds:
@StatefulTimeout(value=100 unit=java.util.concurrent.TimeUnit.SECONDS)
You can configure stateful session bean timeout using the stateful-timeout XML element in the ejb-jar.xml deployment descriptor. The stateful-timeout element is introduced as part of EJB 3.1.
For example, to set a timeout value of 100 seconds:
<stateful-timeout>
<timeout>100</timeout>
<unit>Seconds</unit>
</stateful-timeout>
The @StatefulTimeout annotation and the stateful-timeout XML element are the specification-defined mechanisms for declaring timeout values per bean, beginning with EJB 3.1. Prior to EJB 3.1, there is no specification-defined way for declaring stateful session timeout per bean. When using the stateful-timeout XML element or @StatefulTimeout annotation, a value of -1 means that the bean never times out, and a value of 0 means that the bean is immediately eligible for removal.
You can configure stateful session bean timeout on a global (server-wide) basis, using the com.ibm.websphere.ejbcontainer.defaultStatefulSessionTimeout system property. The unit of time for the com.ibm.websphere.ejbcontainer.defaultStatefulSessionTimeout is minutes. The specified value must be 0 or greater, and if an invalid value is specified, the default value of 10 minutes is used instead. The global timeout value cannot be configured using XML or annotations. The global timeout value applies to all stateful session beans running in the server, including stateful session beans in EJB 2.x or EJB 3.x modules.
- stateful-timeout XML element
- @StatefulTimeout annotation
- ibm-ejb-jar-ext.xml or ibm-ejb-jar-ext.xmi
- com.ibm.websphere.ejbcontainer.defaultStatefulSessionTimeout system property
- If no bean-level or server-wide timeout value is explicitly specified, then the default timeout value of 10 minutes is applied.
Dcom.ibm.websphere.ejbcontainer.poolSize
If the application is using most bean instances in the pool, the Tivoli Performance Viewer indicates this. When the majority of the bean instances are used, increase the size of those bean pools that are being exhausted by adding this parameter to the generic JVM arguments; for example:
-Dcom.ibm.websphere.ejbcontainer.poolSize=<application_name>#<module_name>#
<enterprisebean_name>=<minSize>,<maxSize>
Where:
- The <application_name> element is the Java EE application name as defined in the enterprise archive (EAR) file deployment descriptor, for the bean whose pool size is being set.
- The <module_name> element is the Java archive (JAR) file name of the EJB module, for the bean whose pool size is being set.
- The <bean_name> element is the Java EE enterprise bean name as defined in the EJB module deployment descriptor, for the bean whose pool size is being set
- The <minSize> element is the number of bean instances the container maintains in the pool, irrespective of how long the beans have been in the pool (beans greater than this number are cleared from the pool over time to optimize memory usage)
- The <maxSize> element is the number of bean instances in the pool where no more bean instances are placed in the pool once they are used (that is, when the pool is at this size, any additional beans are discarded rather than added into the pool, which ensures the number of beans in the pool have an upper limit so that memory usage does not grow in an unbounded way).
To keep the number of instances in the pool at a fixed size, the minSize and maxSize elements can be set to the same number. A separate instance pool for every EJB type running in the application server exists, and that every pool starts out with no instances; the number of instances grow as beans are used and then placed in the pool.
Dcom.ibm.websphere.ejbcontainer.poolSize=ivtApp#ivtEJB.jar#ivtEJBObject=125,1327
would
set a minSize of 125 and a maxSize of 1327 on the bean
named ivtEJBObject within the ivtEJB.jar file, in the application ivtApp.The application, ivtApp, is replaced by the actual application name, the ivtEJB.jar file is replaced by the JAR file that contains the bean that must have its pool size increased, and ivtEJBObject is the bean name of the enterprise bean whose pool size must be increased. The minimum number of beans that are held in the pool is 125. The maximum number of beans that are held in the pool is 1327. Set these so that no more evictions occur from the pool. In most cases these must be set equal if memory is plentiful because no growth and shrinkage of the pool occurs.
Dcom.ibm.websphere.ejbcontainer.noPrimaryKeyMutation
You must understand how your application handles the creation of primary key objects for use by CMP beans and bean-managed persistence (BMP) beans inside of the product.
-Dcom.ibm.websphere.ejbcontainer.noPrimaryKeyMutation=true
The performance benefit of this optimization depends on the application. If the application uses primitive types for the primary keys of enterprise beans, there is no gain because these objects are already immutable and the copy mechanism takes this into account. If, however, the application uses many complex primary keys, that is, an object for a primary key or multiple fields, this parameter can yield significant improvements.
Dcom.ibm.ws.pm.deferredcreate
The persistence manager is used by the EJB container to persist data to the database from CMP entity beans.
-Dcom.ibm.ws.pm.deferredcreate=true
The performance benefit of this optimization depends on the application. If the EJB applications transactions are insert intensive, the application can benefit from this optimization. If the application performs few inserts, the benefit of this optimization is less.
Dcom.ibm.ws.pm.batch
When an EJB application accesses multiple CMP beans inside of a single transaction, depending on the operations performed on the beans, such as updates, inserts, and reads, the number of operations issued to the database corresponds directly to the operations performed on the CMP beans. If the database system you are using supports batching of update statements, you can enable this flag and increase performance on all interactions with the database that involve more than two updates in a single transaction.
-Dcom.ibm.ws.pm.batch=true
The performance benefit of this optimization depends on the application. If the application never or infrequently updates CMP beans, or updates only a single bean per transaction, there is no performance gain. If the application updates multiple beans per transaction, this parameter benefits the applications performance.
Database | Supports batch update | Supports batch update with Optimistic Concurrency Control |
---|---|---|
DB2® | yes | no |
Oracle | yes | no |
DB2 Universal Driver | yes | yes |
Informix® | yes | yes |
SQLServer | yes | yes |
Apache Derby | yes | yes |
com.ibm.ws.pm.useLegacyCache
Specifies the name of the Java class that the product uses to implement the javax.rmi.CORBA.UtilDelegate interface.
com.ibm.ws.pm.useLegacyCache=false
com.ibm.ws.pm.grouppartialupdate and com.ibm.ws.pm.batch
The partial updates feature enhances the performance of applications with enterprise beans in certain scenarios. Persistence manager has two caching mechanisms available, legacy cache and two-level cache. Typically, two-level cache performs better than legacy cache because of the optimizations in this mode.
'com.ibm.ws.pm.grouppartialupdate=true' and 'com.ibm.ws.pm.batch=true'