Project

General

Profile

Cache sizes

Cache sizes can be defined in directory.xml and will be configured only once at the server bootstrap through initialization methods. As of the latest update, the location for configuring cache sizes is under /server/{default|<serverID>}/cache-size instead of the older location /server/{default|<serverID>}/persistence/cache-size. The old location is still supported for backward compatibility, but using it will trigger a log warning like:

The cache size for <className> is initialized from a deprecated location. Please move it from /server/{default|<serverID>}/persistent/cache-size to /server/{default|<serverID>}/cache-size.

If a cache size is configured in both locations, the value from the new location takes precedence. Here's an example of the new format:
<node class="container" name="server">
    <node class="container" name="default">
        <node class="container" name="cache-size">

        </node>
    </node>
</node>

There are two types of caches that can be configured:
  1. LRUCache: The name of the cache will be the class name used when configuring the cache size (if a discriminator is provided, it will also be included in the name). Alongside the name, the cache can be provided with a function which confirms whether an expiration candidate element may actually be expired and a policy to follow when capacity cannot be ensured, due to the function vetoing expiration candidates.
  2. HashMap: Only the capacity (cache size) is used to create it.
  3. LinkedHashMap: Similar to HashMap but maintains insertion order. Only the capacity (cache size) is used to create it.
  4. IdentityHashMap: Useful for specialized identity-based caching scenarios. Only the capacity (cache size) is used to create it.
  5. Array: A fixed-size array used as a cache. The array is created using the configured or default size and supports typed values via Java reflection.
Configurations containers and attributes:
  • cache-size: Main container which stores all the cache size configurations. Cache size are read by iterating over all the containers inside cache-size.
  • size container: Container that stores a single cache-size configuration. It does not have a specific name set.
  • class-name: The name of the class used to identify which cache the size belongs to.
  • size: The size that will be used by the cache.
  • discriminator: An identifier used to get the correct cache size when multiple cache sizes are defined for the same class. A discriminator can be used even if there is a single cache that needs to be configured in a class, but it has to be used when initializing to create the cache with the configured value.

To configure a single cache size for a class, use the following structure in the /server/{default|<serverID>}/cache-size container:

<node class="container" name="01"> <!-- container name is unrelated and it doesn't affect the configuration -->
    <node class="string" name="class-name">
      <node-attribute name="value" value="com.goldencode.p2j.persist.BufferManager"/>
    </node>
    <node class="integer" name="size">
      <node-attribute name="value" value="10000"/>
    </node>
</node>

To configure multiple cache sizes for a class, the same structure as above is used, but an additional discriminator node is added.

<node class="container" name="08">
    <node class="string" name="class-name">
        <node-attribute name="value" value="com.goldencode.p2j.persist.FastFindCache"/>
    </node>
    <node class="integer" name="size">
        <node-attribute name="value" value="16"/>
    </node>
    <node class="string" name="discriminator">
        <node-attribute name="value" value="L2"/>
    </node>
</node>
Note that a container needs to be defined for each cache size and the discriminator will be used to make the difference between multiple cache sizes defined for the same class.

The list of caches that can have their size configured:
  • com.goldencode.p2j.persist.BufferManager: convertedNames default size is 10000;
  • com.goldencode.p2j.persist.DynamicTablesHelper: cache default size is 8192;
  • com.goldencode.p2j.persist.DmoMetadataManager: dynamicTables default size is 16384;
  • com.goldencode.p2j.persist.FQLHelperCache: cache default size is 8192;
  • com.goldencode.p2j.persist.FQLPreprocessor: cache default size is 2048 (without a discriminator) and astCache default size is 8192 (the discriminator is "ast");
  • com.goldencode.p2j.persist.Persistence: staticQueryCache default size is 1024;
  • com.goldencode.p2j.persist.orm.Persister: updateCache default size is 4096;
  • com.goldencode.p2j.persist.orm.Session: cache default size is 1024;
  • com.goldencode.p2j.persist.FastFindCache: l2Cache default size is 10 (the discriminator is "L2") and l3Cache default size is 100 (the discriminator is "L3");
  • com.goldencode.p2j.persist.SortCriterion: cache default size is 65536;
  • com.goldencode.p2j.persist.DynamicQueryHelper: lvl1Cache default size is 65536 (the discriminator is "lvl1") and lvl2Cache default size is 16384 (the discriminator is "lvl2");
  • com.goldencode.p2j.persist.DynamicValidationHelper: cache default size is 65536;
  • com.goldencode.p2j.persist.orm.TempTableDataSourceProvider: psCache default size is 8192;
  • com.goldencode.p2j.util.SourceNameMapper: sourceCache default size is 8 (the discriminator is "source"), searchPathCache default size is 64 (the discriminator is "search"), SourceNameMapperCache.convertedNames default size is 16384 (the discriminator is "names").
  • com.goldencode.p2j.util.integer:
    • STATIC_CACHE — default size: 12000 (discriminator: "static-cache")
    • DYNAMIC_CACHE — default size: 2048 (discriminator: "dynamic-cache")
  • com.goldencode.p2j.util.int64:
    • STATIC_CACHE — default size: 12000 (discriminator: "static-cache")
    • DYNAMIC_CACHE — default size: 2048 (discriminator: "dynamic-cache")
  • com.goldencode.p2j.util.character: CHARACTER_CONSTANTS — default size: 1024 (discriminator: "character-cache")

Note that even if the cache belongs to an inner class, the configuration will always use the main class when configuring the cache size.

The following caches will be configured through CacheManager after #8281 is finished and not be available anymore:
  • com.goldencode.p2j.persist.DynamicQueryHelper: lvl1Cache default size is 65536 and lvl2Cache default size is 16384;
    lvl1Cache and lvl2Cache can be configured in the /server/default/standard/runtime/default/ container. lvl1Cache needs to be configured using the dynamic-query-cache-lvl1-size node and lvl2Cache with the dynamic-query-cache-lvl2-size node:
      <node class="container" name="server">
        <node class="container" name="default">
          <node class="container" name="standard">
            <node class="container" name="runtime">
              <node class="container" name="default">
                ...
                <node class="integer" name="dynamic-query-cache-lvl1-size">
                  <node-attribute name="value" value="65536"/>
                </node>
                <node class="integer" name="dynamic-query-cache-lvl2-size">
                  <node-attribute name="value" value="16384"/>
                </node>
              </node>
            </node>
            ...
          </node>
        </node>
      </node>
    
  • com.goldencode.p2j.persist.DynamicValidationHelper: cache default size is 65536;
    cache can be configured in the /server/default/standard/runtime/default/ container. cache needs to be configured using the dynamic-valexp-cache-size node:
      <node class="container" name="server">
        <node class="container" name="default">
          <node class="container" name="standard">
            <node class="container" name="runtime">
              <node class="container" name="default">
                ...
                <node class="integer" name="dynamic-valexp-cache-size">
                  <node-attribute name="value" value="65536"/>
                </node>
              </node>
            </node>
            ...
          </node>
        </node>
      </node>
    

All DynamicQueryHelper and DynamicValidationHelper caches can be configured in the /server/default/runtime/default/ container which is the default when no configuration is found in the /server/default/standard/runtime/default/ container.