com.sleepycat.je.dbi
Class MemoryBudget

java.lang.Object
  extended by com.sleepycat.je.dbi.MemoryBudget
All Implemented Interfaces:
EnvConfigObserver

public class MemoryBudget
extends Object
implements EnvConfigObserver

MemoryBudget calculates the available memory for JE and how to apportion it between cache and log buffers. It is meant to centralize all memory calculations. Objects that ask for memory budgets should get settings from this class, rather than using the configuration parameter values directly.


Field Summary
static int ARRAY_ITEM_OVERHEAD
           
static int BIN_FIXED_OVERHEAD
           
static int BYTE_ARRAY_OVERHEAD
           
static int CHECKPOINT_REFERENCE_SIZE
           
static int DBIN_FIXED_OVERHEAD
           
static int DIN_FIXED_OVERHEAD
           
static int DUPCOUNTLN_OVERHEAD
           
static int HASHMAP_ENTRY_OVERHEAD
           
static int HASHMAP_OVERHEAD
           
static int HASHSET_ENTRY_OVERHEAD
           
static int HASHSET_OVERHEAD
           
static int IN_FIXED_OVERHEAD
           
static int KEY_OVERHEAD
           
static int LN_OVERHEAD
           
static int LOCK_OVERHEAD
           
static int LOCKINFO_OVERHEAD
           
static int LONG_LIST_PER_ITEM_OVERHEAD
           
static int LONG_OVERHEAD
           
static int LSN_ARRAY_BYTE_BASED_FIXED_OVERHEAD
           
static int LSN_ARRAY_LONG_BASED_FIXED_OVERHEAD
           
static int LSN_SIZE
           
static long MIN_MAX_MEMORY_SIZE
           
static String MIN_MAX_MEMORY_SIZE_STRING
           
static int OBJECT_OVERHEAD
           
static int TFS_LIST_INITIAL_OVERHEAD
           
static int TFS_LIST_SEGMENT_OVERHEAD
           
static int TWOHASHMAPS_OVERHEAD
           
static int TXN_OVERHEAD
           
static int UTILIZATION_PROFILE_ENTRY
           
 
Constructor Summary
MemoryBudget(EnvironmentImpl envImpl, DbConfigManager configManager)
           
 
Method Summary
 long accumulateNewUsage(IN in, long newSize)
           
static int byteArraySize(int arrayLen)
          Returns the memory size occupied by a byte array of a given length.
 long calcTreeCacheUsage()
          Public for testing.
 void envConfigUpdate(DbConfigManager configManager)
          Respond to config updates.
 long getBINOverhead()
           
 long getCacheBudget()
           
 long getCacheMemoryUsage()
           
 long getCriticalThreshold()
           
 long getDBINOverhead()
           
 long getDINOverhead()
           
 long getINOverhead()
           
 long getLogBufferBudget()
           
 long getMaxMemory()
           
static long getRuntimeMaxMemory()
          Returns Runtime.maxMemory(), accounting for a MacOS bug.
 long getTrackerBudget()
           
 long getTreeMemoryUsage()
          Used for unit testing.
(package private)  void initCacheMemoryUsage()
          Initialize the starting environment memory state
(package private)  void loadStats(StatsConfig config, EnvironmentStats stats)
           
 void refreshTreeMemoryUsage(long newSize)
           
 void updateLockMemoryUsage(long increment)
           
 void updateMiscMemoryUsage(long increment)
          Update the environment wide misc memory count, wake up the evictor if necessary.
 void updateTreeMemoryUsage(long increment)
          Update the environment wide tree memory count, wake up the evictor if necessary.
 void updateTxnMemoryUsage(long increment)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LONG_OVERHEAD

public static final int LONG_OVERHEAD
See Also:
Constant Field Values

BYTE_ARRAY_OVERHEAD

public static final int BYTE_ARRAY_OVERHEAD
See Also:
Constant Field Values

OBJECT_OVERHEAD

public static final int OBJECT_OVERHEAD
See Also:
Constant Field Values

ARRAY_ITEM_OVERHEAD

public static final int ARRAY_ITEM_OVERHEAD
See Also:
Constant Field Values

HASHMAP_OVERHEAD

public static final int HASHMAP_OVERHEAD
See Also:
Constant Field Values

HASHMAP_ENTRY_OVERHEAD

public static final int HASHMAP_ENTRY_OVERHEAD
See Also:
Constant Field Values

HASHSET_OVERHEAD

public static final int HASHSET_OVERHEAD
See Also:
Constant Field Values

HASHSET_ENTRY_OVERHEAD

public static final int HASHSET_ENTRY_OVERHEAD
See Also:
Constant Field Values

TWOHASHMAPS_OVERHEAD

public static final int TWOHASHMAPS_OVERHEAD
See Also:
Constant Field Values

LN_OVERHEAD

public static final int LN_OVERHEAD
See Also:
Constant Field Values

DUPCOUNTLN_OVERHEAD

public static final int DUPCOUNTLN_OVERHEAD
See Also:
Constant Field Values

BIN_FIXED_OVERHEAD

public static final int BIN_FIXED_OVERHEAD
See Also:
Constant Field Values

DIN_FIXED_OVERHEAD

public static final int DIN_FIXED_OVERHEAD
See Also:
Constant Field Values

DBIN_FIXED_OVERHEAD

public static final int DBIN_FIXED_OVERHEAD
See Also:
Constant Field Values

IN_FIXED_OVERHEAD

public static final int IN_FIXED_OVERHEAD
See Also:
Constant Field Values

KEY_OVERHEAD

public static final int KEY_OVERHEAD
See Also:
Constant Field Values

LSN_SIZE

public static final int LSN_SIZE
See Also:
Constant Field Values

LSN_ARRAY_BYTE_BASED_FIXED_OVERHEAD

public static final int LSN_ARRAY_BYTE_BASED_FIXED_OVERHEAD
See Also:
Constant Field Values

LSN_ARRAY_LONG_BASED_FIXED_OVERHEAD

public static final int LSN_ARRAY_LONG_BASED_FIXED_OVERHEAD
See Also:
Constant Field Values

LOCK_OVERHEAD

public static final int LOCK_OVERHEAD
See Also:
Constant Field Values

LOCKINFO_OVERHEAD

public static final int LOCKINFO_OVERHEAD
See Also:
Constant Field Values

TXN_OVERHEAD

public static final int TXN_OVERHEAD
See Also:
Constant Field Values

CHECKPOINT_REFERENCE_SIZE

public static final int CHECKPOINT_REFERENCE_SIZE
See Also:
Constant Field Values

UTILIZATION_PROFILE_ENTRY

public static final int UTILIZATION_PROFILE_ENTRY
See Also:
Constant Field Values

TFS_LIST_INITIAL_OVERHEAD

public static final int TFS_LIST_INITIAL_OVERHEAD
See Also:
Constant Field Values

TFS_LIST_SEGMENT_OVERHEAD

public static final int TFS_LIST_SEGMENT_OVERHEAD
See Also:
Constant Field Values

LONG_LIST_PER_ITEM_OVERHEAD

public static final int LONG_LIST_PER_ITEM_OVERHEAD
See Also:
Constant Field Values

MIN_MAX_MEMORY_SIZE

public static final long MIN_MAX_MEMORY_SIZE
See Also:
Constant Field Values

MIN_MAX_MEMORY_SIZE_STRING

public static final String MIN_MAX_MEMORY_SIZE_STRING
Constructor Detail

MemoryBudget

MemoryBudget(EnvironmentImpl envImpl,
             DbConfigManager configManager)
       throws DatabaseException
Throws:
DatabaseException
Method Detail

envConfigUpdate

public void envConfigUpdate(DbConfigManager configManager)
                     throws DatabaseException
Respond to config updates.

Specified by:
envConfigUpdate in interface EnvConfigObserver
Throws:
DatabaseException

getRuntimeMaxMemory

public static long getRuntimeMaxMemory()
Returns Runtime.maxMemory(), accounting for a MacOS bug. May return Long.MAX_VALUE if there is no inherent limit. Used by unit tests as well as by this class.


initCacheMemoryUsage

void initCacheMemoryUsage()
                    throws DatabaseException
Initialize the starting environment memory state

Throws:
DatabaseException

calcTreeCacheUsage

public long calcTreeCacheUsage()
                        throws DatabaseException
Public for testing.

Throws:
DatabaseException

updateTreeMemoryUsage

public void updateTreeMemoryUsage(long increment)
Update the environment wide tree memory count, wake up the evictor if necessary.

Parameters:
increment - note that increment may be negative.

updateMiscMemoryUsage

public void updateMiscMemoryUsage(long increment)
Update the environment wide misc memory count, wake up the evictor if necessary.

Parameters:
increment - note that increment may be negative.

updateLockMemoryUsage

public void updateLockMemoryUsage(long increment)

updateTxnMemoryUsage

public void updateTxnMemoryUsage(long increment)

accumulateNewUsage

public long accumulateNewUsage(IN in,
                               long newSize)

refreshTreeMemoryUsage

public void refreshTreeMemoryUsage(long newSize)

getCacheMemoryUsage

public long getCacheMemoryUsage()

getTreeMemoryUsage

public long getTreeMemoryUsage()
Used for unit testing.


getLogBufferBudget

public long getLogBufferBudget()

getTrackerBudget

public long getTrackerBudget()

getMaxMemory

public long getMaxMemory()

getCriticalThreshold

public long getCriticalThreshold()

getCacheBudget

public long getCacheBudget()

getINOverhead

public long getINOverhead()

getBINOverhead

public long getBINOverhead()

getDINOverhead

public long getDINOverhead()

getDBINOverhead

public long getDBINOverhead()

byteArraySize

public static int byteArraySize(int arrayLen)
Returns the memory size occupied by a byte array of a given length.


loadStats

void loadStats(StatsConfig config,
               EnvironmentStats stats)


Copyright 2004-2005 Sleepycat, Inc. All Rights Reserved.