Class PooledMemoryManager

java.lang.Object
org.glassfish.grizzly.memory.PooledMemoryManager
All Implemented Interfaces:
MemoryManager<Buffer>, WrapperAware, MonitoringAware<MemoryProbe>

public class PooledMemoryManager extends Object implements MemoryManager<Buffer>, WrapperAware
A MemoryManager implementation based on a series of shared memory pools. Each pool contains multiple buffers of the fixed length specific for this pool. There are several tuning options for this MemoryManager implementation.
  • The base size of the buffer for the 1st pool, every next pool n will have buffer size equal to bufferSize(n-1) * 2^growthFactor
  • The number of pools, responsible for allocation of buffers of a pool-specific size
  • The buffer size growth factor, that defines 2^x multiplier, used to calculate buffer size for next allocated pool
  • The number of pool slices that every pool will stripe allocation requests across
  • The percentage of the heap that this manager will use when populating the pools
  • The percentage of buffers to be pre-allocated during MemoryManager initialization
  • The flag indicating whether direct or heap based Buffers will be allocated
If no explicit configuration is provided, the following defaults will be used: The main advantage of this manager over HeapMemoryManager or ByteBufferManager is that this implementation doesn't use ThreadLocal pools and as such, doesn't suffer from the memory fragmentation/reallocation cycle that can impact the ThreadLocal versions.
Since:
2.3.11
  • Field Details

    • DEFAULT_BASE_BUFFER_SIZE

      public static final int DEFAULT_BASE_BUFFER_SIZE
      See Also:
    • DEFAULT_NUMBER_OF_POOLS

      public static final int DEFAULT_NUMBER_OF_POOLS
      See Also:
    • DEFAULT_GROWTH_FACTOR

      public static final int DEFAULT_GROWTH_FACTOR
      See Also:
    • DEFAULT_HEAP_USAGE_PERCENTAGE

      public static final float DEFAULT_HEAP_USAGE_PERCENTAGE
      See Also:
    • DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE

      public static final float DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE
      See Also:
    • monitoringConfig

      protected final DefaultMonitoringConfig<MemoryProbe> monitoringConfig
      Basic monitoring support. Concrete implementations of this class need only to implement the createJmxManagementObject() method to plug into the Grizzly 2.0 JMX framework.
  • Constructor Details

    • PooledMemoryManager

      public PooledMemoryManager()
      Creates a new PooledMemoryManager using the following defaults:
      • 4 KiB base buffer size
      • 3 pools
      • 2 growth factor, which means 1st pool will contain buffers of size 4KiB, the 2nd - 16KiB, the 3rd - 64KiB
      • Number of pool slices based on Runtime.getRuntime().availableProcessors()
      • The initial allocation will use 3% of the heap
      • The percentage of buffers to be pre-allocated during MemoryManager initialization
    • PooledMemoryManager

      public PooledMemoryManager(boolean isDirect)
      Creates a new PooledMemoryManager using the specified parameters for configuration.
      Parameters:
      isDirect - flag, indicating whether direct or heap based Buffers will be allocated
    • PooledMemoryManager

      public PooledMemoryManager(int baseBufferSize, int numberOfPools, int growthFactor, int numberOfPoolSlices, float percentOfHeap, float percentPreallocated, boolean isDirect)
      Creates a new PooledMemoryManager using the specified parameters for configuration.
      Parameters:
      baseBufferSize - the base size of the buffer for the 1st pool, every next pool n will have buffer size equal to bufferSize(n-1) * 2^growthFactor
      numberOfPools - the number of pools, responsible for allocation of buffers of a pool-specific size
      growthFactor - the buffer size growth factor, that defines 2^x multiplier, used to calculate buffer size for next allocated pool
      numberOfPoolSlices - the number of pool slices that every pool will stripe allocation requests across
      percentOfHeap - percentage of the heap that will be used when populating the pools
      percentPreallocated - percentage of buffers to be pre-allocated during MemoryManager initialization
      isDirect - flag, indicating whether direct or heap based Buffers will be allocated
  • Method Details