org.exist.storage
Class DefaultCacheManager

java.lang.Object
  extended by org.exist.storage.DefaultCacheManager
All Implemented Interfaces:
CacheManager

public class DefaultCacheManager
extends Object
implements CacheManager

CacheManager maintains a global memory pool available to all page caches. All caches start with a low default setting, but CacheManager can grow individual caches until the total memory is reached. Caches can also be shrinked if their "load" remains below a given threshold between check intervals.The check interval is determined by the global sync background thread. The class computes the available memory in terms of pages.

Author:
wolf

Field Summary
static String CACHE_SIZE_ATTRIBUTE
           
static int DEFAULT_CACHE_SIZE
           
static double MAX_MEM_USE
          The maximum fraction of the total memory that can be used by a single cache.
static double MIN_SHRINK_FACTOR
          The minimum size a cache needs to have to be considered for shrinking, defined in terms of a fraction of the overall memory.
static String PROPERTY_CACHE_SIZE
           
static double SHRINK_FACTOR
          The amount by which a large cache will be shrinked if other caches request a resize.
static int SHRINK_THRESHOLD
          The minimum number of pages that must be read from a cache between check intervals to be not considered for shrinking.
 
Fields inherited from interface org.exist.storage.CacheManager
BTREE_CACHE, DATA_CACHE
 
Constructor Summary
DefaultCacheManager(BrokerPool pool)
           
 
Method Summary
 void checkCaches()
          Called from the global major sync event to check if caches can be shrinked.
 void checkDistribution()
          Called from the global minor sync event to check if a smaller cache wants to be resized.
 void deregisterCache(Cache cache)
           
 long getCurrentSize()
           
 int getDefaultInitialSize()
          Returns the default initial size for all caches.
 long getMaxSingle()
           
 long getMaxTotal()
           
 long getSizeInBytes()
           
 long getTotalMem()
           
 void registerCache(Cache cache)
          Register a cache, i.e.
 int requestMem(Cache cache)
          Called by a cache if it wants to grow.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_MEM_USE

public static final double MAX_MEM_USE
The maximum fraction of the total memory that can be used by a single cache.

See Also:
Constant Field Values

MIN_SHRINK_FACTOR

public static final double MIN_SHRINK_FACTOR
The minimum size a cache needs to have to be considered for shrinking, defined in terms of a fraction of the overall memory.

See Also:
Constant Field Values

SHRINK_FACTOR

public static final double SHRINK_FACTOR
The amount by which a large cache will be shrinked if other caches request a resize.

See Also:
Constant Field Values

SHRINK_THRESHOLD

public static final int SHRINK_THRESHOLD
The minimum number of pages that must be read from a cache between check intervals to be not considered for shrinking. This is a measure for the "load" of the cache. Caches with high load will never be shrinked.

See Also:
Constant Field Values

DEFAULT_CACHE_SIZE

public static int DEFAULT_CACHE_SIZE

CACHE_SIZE_ATTRIBUTE

public static final String CACHE_SIZE_ATTRIBUTE
See Also:
Constant Field Values

PROPERTY_CACHE_SIZE

public static final String PROPERTY_CACHE_SIZE
See Also:
Constant Field Values
Constructor Detail

DefaultCacheManager

public DefaultCacheManager(BrokerPool pool)
Method Detail

registerCache

public void registerCache(Cache cache)
Description copied from interface: CacheManager
Register a cache, i.e. put it under control of the cache manager.

Specified by:
registerCache in interface CacheManager

deregisterCache

public void deregisterCache(Cache cache)
Specified by:
deregisterCache in interface CacheManager

requestMem

public int requestMem(Cache cache)
Description copied from interface: CacheManager
Called by a cache if it wants to grow. The cache manager will either deny the request, for example, if there are no spare pages left, or calculate a new cache size and call the cache's Cache.resize(int) method to resize the cache. The amount of pages by which the cache will grow is determined by the cache's growthFactor: Cache.getGrowthFactor().

Specified by:
requestMem in interface CacheManager
Returns:
new cache size, or -1 if no free pages available.

checkCaches

public void checkCaches()
Called from the global major sync event to check if caches can be shrinked. To be shrinked, the size of a cache needs to be larger than the factor defined by MIN_SHRINK_FACTOR and its load needs to be lower than SHRINK_THRESHOLD. If shrinked, the cache will be reset to the default initial cache size.

Specified by:
checkCaches in interface CacheManager

checkDistribution

public void checkDistribution()
Description copied from interface: CacheManager
Called from the global minor sync event to check if a smaller cache wants to be resized. If a huge cache is availabe, the method might decide to shrink this cache by a certain amount to make room for the smaller cache to grow.

Specified by:
checkDistribution in interface CacheManager

getMaxTotal

public long getMaxTotal()
Specified by:
getMaxTotal in interface CacheManager

getCurrentSize

public long getCurrentSize()
Specified by:
getCurrentSize in interface CacheManager

getSizeInBytes

public long getSizeInBytes()

getMaxSingle

public long getMaxSingle()
Specified by:
getMaxSingle in interface CacheManager

getTotalMem

public long getTotalMem()

getDefaultInitialSize

public int getDefaultInitialSize()
Returns the default initial size for all caches.

Returns:
Default initial size 64.


Copyright (C) Wolfgang Meier. All rights reserved.