/** * compute the size of storing a key/value pair in the cache.. */ public int entrySize( Object key, Object value ) throws IllegalArgumentException { if (value == Token.TOMBSTONE) { return 0; } int size = 0; int keySize = 0; if (!MemLRUCapacityController.this.isOffHeap) { size += MemLRUCapacityController.this.getPerEntryOverhead(); keySize = sizeof(key); } // For off-heap we do not want to count the size of DataAsAddress objects since they are not stored off-heap. // But their implementation of Sizable always returns 0 so we don't need to special case them here. int valueSize = sizeof(value); // com.gemstone.gemfire.internal.cache.GemFireCacheImpl.getInstance().getLogger().info("DEBUG MemLRUCC: overhead=" + size // + " keySize=" + keySize // + " valueSize=" + valueSize); size += keySize; size += valueSize; return size; }
/** * Return the size of an object as stored in GemFire... Typically * this is the serialized size in bytes.. This implementation is * slow.... Need to add Sizer interface and call it for customer * objects. */ protected int sizeof( Object o ) throws IllegalArgumentException { return basicSizeof(o, this.sizer); }
/** * Returns a brief description of this capacity controller. * * @since 4.0 */ @Override public String toString() { return "MemLRUCapacityController with a capacity of " + this.getLimit() + " megabytes and and eviction action " + this.getEvictionAction(); } }
/** * Create an instance of the capacity controller the given settings. * * @param megabytes * the amount of memory allowed in this region specified in * megabytes.<br> * <p> * For a region with * {@link com.gemstone.gemfire.cache.DataPolicy#PARTITION}, it * is overridden by * {@link com.gemstone.gemfire.cache.PartitionAttributesFactory#setLocalMaxMemory(int) " local max memory "} * specified for the * {@link com.gemstone.gemfire.cache.PartitionAttributes}. It * signifies the amount of memory allowed in the region, * collectively for its primary buckets and redundant copies * for this VM. It can be different for the same region in * different VMs. * @param sizerImpl * classname of a class that implements ObjectSizer, used to * compute object sizes for MemLRU * @param isOffHeap true if the region that owns this cc is stored off heap */ public MemLRUCapacityController( int megabytes , ObjectSizer sizerImpl, EvictionAction evictionAction,Region region, boolean isOffHeap) { super(evictionAction,region); this.isOffHeap = isOffHeap; setMaximumMegabytes(megabytes); setSizer(sizerImpl); }
try { Class c = ClassPathLoader.getLatest().forName(sizerStr); setSizer((ObjectSizer)c.newInstance()); setEvictionAction(EvictionAction.parseAction(prop));
private int getEntryOverhead(Region region) { LocalRegion lRegion = (LocalRegion)region; return ((MemLRUCapacityController)lRegion.getEvictionController()) .getPerEntryOverhead(); }
@Override public void setLimit(int maximum) { setMaximumMegabytes(maximum); }
/** * Build the appropriate eviction controller using the attributes provided. * * @return the super of the eviction controller or null if no {@link EvictionAction} * is set. * * @see EvictionAttributes */ public LRUAlgorithm createEvictionController(Region region, boolean isOffHeap) { if (this.algorithm == EvictionAlgorithm.LRU_ENTRY) { this.evictionController = new LRUCapacityController(this.maximum, this.action,region); } else if (this.algorithm == EvictionAlgorithm.LRU_HEAP) { this.evictionController = new HeapLRUCapacityController(this.sizer,this.action,region); } else if (this.algorithm == EvictionAlgorithm.LRU_MEMORY) { this.evictionController = new MemLRUCapacityController(this.maximum, this.sizer, this.action,region, isOffHeap); } else if(this.algorithm == EvictionAlgorithm.LIFO_ENTRY){ this.evictionController = new LRUCapacityController(this.maximum, this.action,region); } else if(this.algorithm == EvictionAlgorithm.LIFO_MEMORY){ this.evictionController = new MemLRUCapacityController(this.maximum, this.sizer, this.action,region, isOffHeap); } else { // for all other algorithms, return null this.evictionController = null; } return this.evictionController; }
((MemLRUCapacityController) ec).setEntryOverHead(getEntryOverHead());
/** * Create an instance of the capacity controller the given settings. * * @param megabytes * the amount of memory allowed in this region specified in * megabytes.<br> * <p> * For a region with * {@link com.gemstone.gemfire.cache.DataPolicy#PARTITION}, it * is overridden by * {@link com.gemstone.gemfire.cache.PartitionAttributesFactory#setLocalMaxMemory(int) " local max memory "} * specified for the * {@link com.gemstone.gemfire.cache.PartitionAttributes}. It * signifies the amount of memory allowed in the region, * collectively for its primary buckets and redundant copies * for this VM. It can be different for the same region in * different VMs. * @param sizerImpl * classname of a class that implements ObjectSizer, used to * compute object sizes for MemLRU * @param isOffHeap true if the region that owns this cc is stored off heap */ public MemLRUCapacityController( int megabytes , ObjectSizer sizerImpl, EvictionAction evictionAction,Region region, boolean isOffHeap) { super(evictionAction,region); this.isOffHeap = isOffHeap; setMaximumMegabytes(megabytes); setSizer(sizerImpl); }
try { Class c = ClassPathLoader.getLatest().forName(sizerStr); setSizer((ObjectSizer)c.newInstance()); setEvictionAction(EvictionAction.parseAction(prop));
} else { MemLRUCapacityController capCon = (MemLRUCapacityController)algor; perEntryOverhead = capCon.getPerEntryOverhead();
@Override public void setLimit(int maximum) { setMaximumMegabytes(maximum); }
/** * Build the appropriate eviction controller using the attributes provided. * * @return the super of the eviction controller or null if no {@link EvictionAction} * is set. * * @see EvictionAttributes */ public LRUAlgorithm createEvictionController(Region region, boolean isOffHeap) { if (this.algorithm == EvictionAlgorithm.LRU_ENTRY) { this.evictionController = new LRUCapacityController(this.maximum, this.action,region); } else if (this.algorithm == EvictionAlgorithm.LRU_HEAP) { this.evictionController = new HeapLRUCapacityController(this.sizer,this.action,region); } else if (this.algorithm == EvictionAlgorithm.LRU_MEMORY) { this.evictionController = new MemLRUCapacityController(this.maximum, this.sizer, this.action,region, isOffHeap); } else if(this.algorithm == EvictionAlgorithm.LIFO_ENTRY){ this.evictionController = new LRUCapacityController(this.maximum, this.action,region); } else if(this.algorithm == EvictionAlgorithm.LIFO_MEMORY){ this.evictionController = new MemLRUCapacityController(this.maximum, this.sizer, this.action,region, isOffHeap); } else { // for all other algorithms, return null this.evictionController = null; } return this.evictionController; }
((MemLRUCapacityController) ec).setEntryOverHead(getEntryOverHead());
/** * compute the size of storing a key/value pair in the cache.. */ public int entrySize( Object key, Object value ) throws IllegalArgumentException { if (value == Token.TOMBSTONE) { return 0; } int size = 0; int keySize = 0; if (!MemLRUCapacityController.this.isOffHeap) { size += MemLRUCapacityController.this.getPerEntryOverhead(); keySize = sizeof(key); } int valueSize = sizeof(value); // com.gemstone.gemfire.internal.cache.GemFireCacheImpl.getInstance().getLogger().info("DEBUG MemLRUCC: overhead=" + size // + " keySize=" + keySize // + " valueSize=" + valueSize); size += keySize; size += valueSize; return size; }
/** * Returns a brief description of this capacity controller. * * @since 4.0 */ @Override public String toString() { return "MemLRUCapacityController with a capacity of " + this.getLimit() + " megabytes and and eviction action " + this.getEvictionAction(); } }
perEntryOverhead = ((MemLRUCapacityController)(((LocalRegion)aRegion).getEvictionController())).getPerEntryOverhead(); bytesPerEntry_keyOnly = TestHelper.calculateStringSize(getFixedLengthKeyForName("Object_1")) + perEntryOverhead; bytesPerEntry_keyValue = bytesPerEntry_keyOnly + valueSize + perEntryOverhead;
/** * Return the size of an object as stored in GemFire... Typically this is the * serialized size in bytes.. This implementation is slow.... Need to add * Sizer interface and call it for customer objects. */ protected int sizeof(Object o) throws IllegalArgumentException { return MemLRUCapacityController.basicSizeof(o, this.sizer); }
/** * Return the size of an object as stored in GemFire... Typically this is the * serialized size in bytes.. This implementation is slow.... Need to add * Sizer interface and call it for customer objects. */ protected int sizeof(Object o) throws IllegalArgumentException { return MemLRUCapacityController.basicSizeof(o, this.sizer); }