Tuning EJB cache using trace service

The size of your Enterprise JavaBeans™ (EJB) cache can effect the performance of the application server. One of the steps in tuning your EJB container to optimum performance levels is to fine tune the EJB cache.

About this task

The following describes how to use the diagnostic trace service to help you determine the best cache size for you.

Procedure

  1. Enable the EJB cache trace. To learn about working with the trace service, see the topic Working with trace. For information about the trace service settings, see the topic Diagnostic trace service settings.
    Set up your trace to use this trace string:
    com.ibm.ejs.util.cache.BackgroundLruEvictionStrategy=all=enabled:com.ibm.ejs.util.cache.CacheElementEnumerator=
    all=enabled

    Set Maximum File Size to 200MB or more. If you leave the default value of 20MB, you could fill up the single 20MB trace log and lose some data because of trace wrapping.

    Set Maximum Number of Historical Files to 5. Five files should be sufficient, but if you see that all five files are full and trace wrapping occurs, increase this value.

  2. Stop your server, delete existing logs, then start your server.
  3. Run typical scenarios to capture cache trace data. By running a typical scenario with the trace enabled, you will get the EJB cache trace data to analyze in the following steps.
  4. View and analyze the trace output.
    1. Open your trace log. Look for either or both of the following trace strings to appear:

      BackgroundLru 3  EJB Cache: Sweep (1,40) - Cache limit not reached : 489/2053
      BackgroundLru >  EJB Cache: Sweep (16,40) - Cache limit exceeded : 3997/2053 Entry

      In the trace strings that include the words Cache limit you find a ratio. For example, 3997/2053. The first number is the number of enterprise beans currently in the EJB cache (called the capacity). The second number is the EJB cache setting (more about this in later steps). You will use this ratio, particularly the capacity, in your analysis.

      Also look for the statements Cache limit not reached and Cache limit exceeded.
      Cache limit not reached
      Your cache is equal to or larger than what is appropriate. If it is larger, you are wasting memory, and should reduce the cache size to a more appropriate value, as described below.
      Cache limit exceeded
      The number of beans currently being used is greater than the capacity you have specified, indicating that your cache is not properly tuned. The capacity can exceed the EJB Cache setting because the setting is not a hard limit. The EJB Container does not stop adding beans to the cache when the limit is reached. Doing so could mean that when the cache is full, a request for a bean would not be fulfilled, or would at least be delayed until the cache fell below the limit. Instead, the cache limit can be exceeded, but the EJB Container attempts to clean up the cache and keep it below the EJB Cache size.
      In the case where the cache limit is exceeded, you might see a trace point similar to this:

      BackgroundLru <  EJB Cache: Sweep (64,38) - Evicted = 50 : 3589/2053 Exit

      Notice the Evicted = string. If you see this string, you are using either Stateful Session Beans or Entity Beans configured for Option A or B caching. Evicted objects mean you are not taking full advantage of the caching option that you have chosen. Your first step is to try increasing the EJB Cache size. If continued running of your application results in more evictions, it means that the application is accessing or creating more new beans between EJB Cache sweeps than the cache can hold, and NOT re-using existing beans. At this point, you might want to consider using Option C caching for your entity beans, or checking your application to see if it is not removing Stateful Session Beans after they are no longer needed.
      Note: Entity beans configured with Option C caching are only in the cache while in a transaction, and are required to be held in the cache for the entire transaction. Therefore, they are never evicted during a cache sweep, but are removed from the cache when the transaction completes. In addition, if you are using only Stateless Session Beans or Entity Beans with Option C caching (or both), then you might want to increase your EJB Cache cleanup interval to a larger number. The cleanup interval can be set as described in EJB cache settings. Stateless Session Beans are NOT in the EJB Cache, and since Entity Beans using Option C caching are never evicted by the caching (LRU) strategy, there is really no need to sweep very often. When using only Stateless Session Beans or Option C caching, you should only see "Evicted = 0" in the trace example shown above.
    2. Analyze your trace log. Look for the trace string Cache limit exceeded.
      • You might find more than one instance of this string. Examine them all to find the highest capacity value of beans in the EJB Cache. Re-set your EJB Cache size to about 110% of this number. Setting the EJB Cache size is explained in a later step.
      • You might find no instances of this string. This means that you have not exceeded the capacity of the EJB Cache (which is your end goal), but not seeing it during your initial analysis could also mean that your cache is too large and using unnecessary memory. In this case, you still need to tune your cache by reducing the cache size until your cache limit is exceeded, then increasing it to the optimum value. Setting the EJB Cache size is explained in a later step.
      Your ultimate goal is to set the cache limit to a value that does not waste resources, but also does not get exceeded. So, a good set-up gives you a trace with only the Cache limit not reached message, and a ratio where the capacity number can be near, but below, 100% of the EJB Cache setting.
      Note: It is recommended that you do not set your cache size to anything less than the default of 2053.
  5. Modify the cache settings based on your analysis. See EJB cache settings for information on how to do this.
  6. Stop your server, delete all logs, and restart your server.
  7. Repeat the above steps until you are satisfied with your settings.
  8. Disable the EJB Cache trace. With the cache properly tuned, you can remove the trace, remove old logs, and restart your server.

What to do next

From your analysis, it is possible to set the EJB cache optimally from an EJB Container perspective, but perhaps not optimally from a WebSphere® Application Server perspective. A larger cache size provides more hits and better EJB cache performance, but uses more memory. Memory used by the cache is not available to other areas of the product, potentially causing the overall performance to suffer. In a system with ample memory, this might not be an issue and properly tuning the EJB cache might increase overall performance. However, you should take into account this system performance versus EJB cache performance when configuring the cache.




In this information ...


Related tasks
Related reference

IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic    

Terms of Use | Feedback

Last updated: Oct 21, 2010 1:44:59 AM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=compass&product=was-express-dist&topic=tejb_tunecash
File name: tejb_tunecash.html