com.sleepycat.je.dbi
Class MemoryBudget

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

public class MemoryBudget
extends java.lang.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_OVERHEAD
           
static int ARRAY_SIZE_INCLUDED
           
static int BIN_FIXED_OVERHEAD
           
static int CHECKPOINT_REFERENCE_SIZE
           
static int DBIN_FIXED_OVERHEAD
           
static int DIN_FIXED_OVERHEAD
           
static int DUPCOUNTLN_OVERHEAD
           
static int FILESUMMARYLN_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_INFO_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 MAPLN_OVERHEAD
           
static long MIN_MAX_MEMORY_SIZE
           
static java.lang.String MIN_MAX_MEMORY_SIZE_STRING
           
static int OBJECT_ARRAY_ITEM_OVERHEAD
           
static int OBJECT_OVERHEAD
           
static int PRIMITIVE_LONG_ARRAY_ITEM_OVERHEAD
           
static int TFS_LIST_INITIAL_OVERHEAD
           
static int TFS_LIST_SEGMENT_OVERHEAD
           
static int TREEMAP_ENTRY_OVERHEAD
           
static int TREEMAP_OVERHEAD
           
static int TWOHASHMAPS_OVERHEAD
           
static int TXN_OVERHEAD
           
static int UTILIZATION_PROFILE_ENTRY
           
static int WRITE_LOCKINFO_OVERHEAD
           
 
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()
           
 long getMinTreeMemoryUsage()
          For unit tests.
 long getMiscMemoryUsage()
          Used for unit testing.
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.
static int intArraySize(int arrayLen)
           
 boolean isTreeUsageAboveMinimum()
          Returns whether eviction of INList information is allowed.
(package private)  void loadStats(StatsConfig config, EnvironmentStats stats)
           
static int objectArraySize(int arrayLen)
           
 void refreshTreeMemoryUsage(long newSize)
           
static int shortArraySize(int arrayLen)
           
 void updateLockMemoryUsage(long increment, int lockTableIndex)
           
 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.
 
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

ARRAY_OVERHEAD

public static final int ARRAY_OVERHEAD

ARRAY_SIZE_INCLUDED

public static final int ARRAY_SIZE_INCLUDED

OBJECT_OVERHEAD

public static final int OBJECT_OVERHEAD

OBJECT_ARRAY_ITEM_OVERHEAD

public static final int OBJECT_ARRAY_ITEM_OVERHEAD

HASHMAP_OVERHEAD

public static final int HASHMAP_OVERHEAD

HASHMAP_ENTRY_OVERHEAD

public static final int HASHMAP_ENTRY_OVERHEAD

HASHSET_OVERHEAD

public static final int HASHSET_OVERHEAD

HASHSET_ENTRY_OVERHEAD

public static final int HASHSET_ENTRY_OVERHEAD

TWOHASHMAPS_OVERHEAD

public static final int TWOHASHMAPS_OVERHEAD

TREEMAP_OVERHEAD

public static final int TREEMAP_OVERHEAD

TREEMAP_ENTRY_OVERHEAD

public static final int TREEMAP_ENTRY_OVERHEAD

MAPLN_OVERHEAD

public static final int MAPLN_OVERHEAD

LN_OVERHEAD

public static final int LN_OVERHEAD

DUPCOUNTLN_OVERHEAD

public static final int DUPCOUNTLN_OVERHEAD

BIN_FIXED_OVERHEAD

public static final int BIN_FIXED_OVERHEAD

DIN_FIXED_OVERHEAD

public static final int DIN_FIXED_OVERHEAD

DBIN_FIXED_OVERHEAD

public static final int DBIN_FIXED_OVERHEAD

IN_FIXED_OVERHEAD

public static final int IN_FIXED_OVERHEAD

KEY_OVERHEAD

public static final int KEY_OVERHEAD

LOCK_OVERHEAD

public static final int LOCK_OVERHEAD

LOCKINFO_OVERHEAD

public static final int LOCKINFO_OVERHEAD

WRITE_LOCKINFO_OVERHEAD

public static final int WRITE_LOCKINFO_OVERHEAD

TXN_OVERHEAD

public static final int TXN_OVERHEAD

CHECKPOINT_REFERENCE_SIZE

public static final int CHECKPOINT_REFERENCE_SIZE

UTILIZATION_PROFILE_ENTRY

public static final int UTILIZATION_PROFILE_ENTRY

TFS_LIST_INITIAL_OVERHEAD

public static final int TFS_LIST_INITIAL_OVERHEAD

TFS_LIST_SEGMENT_OVERHEAD

public static final int TFS_LIST_SEGMENT_OVERHEAD

LN_INFO_OVERHEAD

public static final int LN_INFO_OVERHEAD

FILESUMMARYLN_OVERHEAD

public static final int FILESUMMARYLN_OVERHEAD

LONG_LIST_PER_ITEM_OVERHEAD

public static final int LONG_LIST_PER_ITEM_OVERHEAD

PRIMITIVE_LONG_ARRAY_ITEM_OVERHEAD

public static final int PRIMITIVE_LONG_ARRAY_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 java.lang.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

isTreeUsageAboveMinimum

public boolean isTreeUsageAboveMinimum()
Returns whether eviction of INList information is allowed. To prevent extreme cache churn, eviction of Btree information is prohibited unless the tree memory usage is above this minimum value.


getMinTreeMemoryUsage

public long getMinTreeMemoryUsage()
For unit tests.


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,
                                  int lockTableIndex)

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.


getMiscMemoryUsage

public long getMiscMemoryUsage()
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. All arrays (regardless of element type) have the same overhead for a zero length array. On 32b Java, there are 4 bytes included in that fixed overhead that can be used for the first N elements -- however many fit in 4 bytes. On 64b Java, there is no extra space included. In all cases, space is allocated in 8 byte chunks.


shortArraySize

public static int shortArraySize(int arrayLen)

intArraySize

public static int intArraySize(int arrayLen)

objectArraySize

public static int objectArraySize(int arrayLen)

loadStats

void loadStats(StatsConfig config,
               EnvironmentStats stats)


Copyright 2004,2008 Oracle. All rights reserved.