+

Search Tips   |   Advanced Search

Tuning the EJB cache using the trace service


The size of the EJBs cache can effect the performance of the appserver. One of the steps in tuning your EJB container to optimum performance levels is to fine tune the EJB cache.

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

 

  1. Enable the EJB cache trace. To learn about working with the trace service, see Working with trace. For information about the trace service settings, see Diagnostic trace service settings.Set up the 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 we 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 we see that all five files are full and trace wrapping occurs, increase this value.

  2. Stop the server, delete existing logs, then start the 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 the 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 the 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, we 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 we have specified, indicating that the 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, we might see a trace point similar to this:

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

      Notice the Evicted = string. If we see this string, we are using either Stateful Session Beans or Entity Beans configured for Option A or B caching. Evicted objects mean we are not taking full advantage of the caching option that we have chosen. Your first step is to try increasing the EJB Cache size. If continued running of the 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, we might want to consider using Option C caching for the entity beans, or checking the application to see if it is not removing Stateful Session Beans after they are no longer needed.

      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 we are using only Stateless Session Beans or Entity Beans with Option C caching (or both), then we might want to increase the EJB Cache cleanup interval to a larger number.

      The cleanup interval can be set

      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 the trace log. Look for the trace string Cache limit exceeded.

      • We 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 the EJB Cache size to about 110% of this number. Setting the EJB Cache size is explained in a later step.

      • We might find no instances of this string.

        This means that you have not exceeded the capacity of the EJB Cache (which is the end goal), but not seeing it during the initial analysis could also mean that the cache is too large and using unnecessary memory. In this case, you still need to tune the cache by reducing the cache size until the 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.

      IBM recommends that you do not set your cache size to anything less than the default of 2053.

  5. Modify the cache settings based on the analysis. See EJB cache settings for information on how to do this.

  6. Stop the server, delete all logs, and restart the server.

  7. Repeat the above steps until we are satisfied with the settings.

  8. Disable the EJB Cache trace. With the cache properly tuned, we can remove the trace, remove old logs, and restart your server.

 

Next steps

From the analysis, it is possible to set the EJB cache optimally from an EJB Container perspective, but perhaps not optimally from a WAS 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 WAS ND, 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.

 

Related tasks


Working with trace

 

Related


EJB cache settings