/** * Returns the OffHeapMemoryStats for this VM. */ private OffHeapMemoryStats getOffHeapStats() { OffHeapMemoryStats stats = null; MemoryAllocator offHeap = this.cache.getOffHeapStore(); if(null != offHeap) { stats = offHeap.getStats(); } return stats; }
/** * Returns the OffHeapMemoryStats for this VM. */ private OffHeapMemoryStats getOffHeapStats() { OffHeapMemoryStats stats = null; MemoryAllocator offHeap = this.cache.getOffHeapStore(); if(null != offHeap) { stats = offHeap.getStats(); } return stats; }
private void calculateEvictionBurst() { float evictionBurstPercentage = Float.parseFloat(System.getProperty(ResourceManager.EVICTION_BURST_PERCENT_PROP, "0.4")); MemoryAllocator allocator = ((GemFireCacheImpl) this.cache).getOffHeapStore(); /* * Bail if there is no off-heap memory to evict. */ if(null == allocator) { throw new IllegalStateException(LocalizedStrings.MEMSCALE_EVICTION_INIT_FAIL.toLocalizedString()); } bytesToEvictWithEachBurst = (long)(allocator.getTotalMemory() * 0.01 * evictionBurstPercentage); }
private void calculateEvictionBurst() { float evictionBurstPercentage = Float.parseFloat(System.getProperty("gemfire.HeapLRUCapacityController.evictionBurstPercentage", "0.4")); MemoryAllocator allocator = ((GemFireCacheImpl) this.cache).getOffHeapStore(); /* * Bail if there is no off-heap memory to evict. */ if(null == allocator) { throw new IllegalStateException(LocalizedStrings.MEMSCALE_EVICTION_INIT_FAIL.toLocalizedString()); } bytesToEvictWithEachBurst = (long)(allocator.getTotalMemory() * 0.01 * evictionBurstPercentage); }
/** * Consumes off off-heap memory until the allocation size cannot be satisfied. * @param allocationSize the number of bytes for each allocation * @return the number of successful puts */ protected int doConsumeOffHeapMemory(int allocationSize) { // TODO:KIRK: change this to handle new OutOfOffHeapMemoryException OffHeapMemoryStats stats = ((GemFireCacheImpl) getCache()).getOffHeapStore().getStats(); int i = 0; // Loop until we fail try { while(true) { doPut("KEY" + (i++),new byte[allocationSize],OFF_HEAP_REGION_NAME, false); } } catch (OutOfOffHeapMemoryException e) { } return i; }
OffHeapMemoryMonitor(final InternalResourceManager resourceManager, final GemFireCacheImpl cache, final ResourceManagerStats stats) { this.resourceManager = resourceManager; this.resourceAdvisor = (ResourceAdvisor) cache.getDistributionAdvisor(); this.cache = cache; this.stats = stats; this.memoryAllocator = cache.getOffHeapStore(); if (this.memoryAllocator != null) { this.thresholds = new MemoryThresholds(this.memoryAllocator.getTotalMemory()); } this.log = cache.getLoggerI18n(); }
public void run2() throws CacheException { Region region = getRootRegion().getSubregion(name); region.destroy(key, arg); assertEquals(1, region.size()); if (region.getAttributes().getEnableOffHeapMemory() && !(region instanceof PartitionedRegion)) { GemFireCacheImpl gfc = (GemFireCacheImpl) getCache(); SimpleMemoryAllocatorImpl ma = (SimpleMemoryAllocatorImpl) gfc.getOffHeapStore(); assertEquals(1, ma.getStats().getObjects()); } } });
GemFireCacheImpl gfc = GemFireCacheImpl.getInstance(); if (gfc != null) { if (gfc.getOffHeapStore() != null) { gfc.getOffHeapStore().setCompressor(getCompressor());
public void run2() throws CacheException { Region region = getRootRegion().getSubregion(name); region.put(key, newValue, arg); assertEquals(2, region.size()); if (region.getAttributes().getEnableOffHeapMemory() && !(region instanceof PartitionedRegion)) { GemFireCacheImpl gfc = (GemFireCacheImpl) getCache(); SimpleMemoryAllocatorImpl ma = (SimpleMemoryAllocatorImpl) gfc.getOffHeapStore(); assertEquals(2, ma.getStats().getObjects()); } } });
public void run2() throws CacheException { Region region = getRootRegion().getSubregion(name); assertEquals(1, region.size()); if (region.getAttributes().getEnableOffHeapMemory() && !(region instanceof PartitionedRegion)) { GemFireCacheImpl gfc = (GemFireCacheImpl) getCache(); SimpleMemoryAllocatorImpl ma = (SimpleMemoryAllocatorImpl) gfc.getOffHeapStore(); assertEquals(1, ma.getStats().getObjects()); } region.destroyRegion(arg); if (region.getAttributes().getEnableOffHeapMemory() && !(region instanceof PartitionedRegion)) { GemFireCacheImpl gfc = (GemFireCacheImpl) getCache(); SimpleMemoryAllocatorImpl ma = (SimpleMemoryAllocatorImpl) gfc.getOffHeapStore(); assertEquals(0, ma.getStats().getObjects()); } } });
public void run2() throws CacheException { Region region = getRootRegion().getSubregion(name); try { region.put(key, oldValue, exception); fail("Should have thrown a CacheWriterException"); } catch (CacheWriterException ex) { assertNull(region.getEntry(key)); assertEquals(1, region.size()); if (region.getAttributes().getEnableOffHeapMemory() && !(region instanceof PartitionedRegion)) { GemFireCacheImpl gfc = (GemFireCacheImpl) getCache(); SimpleMemoryAllocatorImpl ma = (SimpleMemoryAllocatorImpl) gfc.getOffHeapStore(); assertEquals(1, ma.getStats().getObjects()); } } } });
public void run2() throws CacheException { Region region = getRootRegion().getSubregion(name); try { region.destroy(key, exception); fail("Should have thrown a CacheWriterException"); } catch (CacheWriterException ex) { assertNotNull(region.getEntry(key)); assertEquals(2, region.size()); if (region.getAttributes().getEnableOffHeapMemory() && !(region instanceof PartitionedRegion)) { GemFireCacheImpl gfc = (GemFireCacheImpl) getCache(); SimpleMemoryAllocatorImpl ma = (SimpleMemoryAllocatorImpl) gfc.getOffHeapStore(); assertEquals(2, ma.getStats().getObjects()); } } } });
public void run2() throws CacheException { Region region = createRegion(name); // Put key2 in the region before any callbacks are // registered, so it can be destroyed later region.put(key2, value2); assertEquals(1, region.size()); if (region.getAttributes().getEnableOffHeapMemory() && !(region instanceof PartitionedRegion)) { GemFireCacheImpl gfc = (GemFireCacheImpl) getCache(); SimpleMemoryAllocatorImpl ma = (SimpleMemoryAllocatorImpl) gfc.getOffHeapStore(); LocalRegion reRegion; reRegion = (LocalRegion) region; RegionEntry re = reRegion.getRegionEntry(key2); MemoryChunkWithRefCount mc = (MemoryChunkWithRefCount) re._getValue(); assertEquals(1, mc.getRefCount()); assertEquals(1, ma.getStats().getObjects()); } } };
public void run2() throws CacheException { Region region = getRootRegion().getSubregion(name); region.put(key, oldValue, arg); assertEquals(2, region.size()); if (region.getAttributes().getEnableOffHeapMemory() && !(region instanceof PartitionedRegion)) { GemFireCacheImpl gfc = (GemFireCacheImpl) getCache(); SimpleMemoryAllocatorImpl ma = (SimpleMemoryAllocatorImpl) gfc.getOffHeapStore(); assertEquals(2, ma.getStats().getObjects()); LocalRegion reRegion; reRegion = (LocalRegion) region; MemoryChunkWithRefCount mc = (MemoryChunkWithRefCount) reRegion.getRegionEntry(key)._getValue(); assertEquals(1, mc.getRefCount()); } } });
public void run2() throws CacheException { Region region = getRootRegion().getSubregion(name); try { region.destroyRegion(exception); fail("Should have thrown a CacheWriterException"); } catch (CacheWriterException ex) { if (region.isDestroyed()) { fail("should not have an exception if region is destroyed", ex); } assertEquals(1, region.size()); if (region.getAttributes().getEnableOffHeapMemory() && !(region instanceof PartitionedRegion)) { GemFireCacheImpl gfc = (GemFireCacheImpl) getCache(); SimpleMemoryAllocatorImpl ma = (SimpleMemoryAllocatorImpl) gfc.getOffHeapStore(); assertEquals(1, ma.getStats().getObjects()); } } } });
public void run2() throws CacheException { Region region = getRootRegion().getSubregion(name); try { region.put(key, newValue, exception); fail("Should have thrown a CacheWriterException"); } catch (CacheWriterException ex) { Region.Entry entry = region.getEntry(key); assertEquals(oldValue, entry.getValue()); assertEquals(2, region.size()); if (region.getAttributes().getEnableOffHeapMemory() && !(region instanceof PartitionedRegion)) { GemFireCacheImpl gfc = (GemFireCacheImpl) getCache(); SimpleMemoryAllocatorImpl ma = (SimpleMemoryAllocatorImpl) gfc.getOffHeapStore(); assertEquals(2, ma.getStats().getObjects()); LocalRegion reRegion; reRegion = (LocalRegion) region; MemoryChunkWithRefCount mc = (MemoryChunkWithRefCount) reRegion.getRegionEntry(key)._getValue(); assertEquals(1, mc.getRefCount()); } } } });
/** Get the current number of bytes in the region. * */ protected long getRegionSizeInBytes() { Region workRegion = getWorkRegion(); int numKeys = workRegion.keys().size(); CapConBB.getBB().getSharedCounters().setIfLarger(CapConBB.MAX_NUM_KEYS, numKeys); if (workRegion.getAttributes().getEnableOffHeapMemory()) { GemFireCacheImpl gfCache = (GemFireCacheImpl)(CacheUtil.getCache()); return gfCache.getOffHeapStore().getStats().getUsedMemory(); } else { return memLRUParams.getTotalBytesPerEntry() * numKeys; } }
public void testSizeAllocation() { // prevent cache from closing in reaction to ooom System.setProperty(OffHeapStorage.STAY_CONNECTED_ON_OUTOFOFFHEAPMEMORY_PROPERTY, "true"); GemFireCacheImpl gfc = createCache(); try { MemoryAllocator ma = gfc.getOffHeapStore(); assertNotNull(ma); final long offHeapSize = ma.getFreeMemory(); assertEquals(0, ma.getUsedMemory()); MemoryChunk mc1 = ma.allocate(64, null); assertEquals(64+perObjectOverhead(), ma.getUsedMemory()); assertEquals(offHeapSize-(64+perObjectOverhead()), ma.getFreeMemory()); mc1.release(); assertEquals(offHeapSize, ma.getFreeMemory()); assertEquals(0, ma.getUsedMemory()); // do an allocation larger than the slab size try { ma.allocate(1024*1024*10, null); fail("Expected an out of heap exception"); } catch (OutOfOffHeapMemoryException expected) { } assertEquals(0, ma.getUsedMemory()); assertFalse(gfc.isClosed()); } finally { System.clearProperty(OffHeapStorage.STAY_CONNECTED_ON_OUTOFOFFHEAPMEMORY_PROPERTY); closeCache(gfc); SimpleMemoryAllocatorImpl.freeOffHeapMemory(); } }
public void testByteArrayAllocation() { GemFireCacheImpl gfc = createCache(); try { MemoryAllocator ma = gfc.getOffHeapStore(); assertNotNull(ma); final long offHeapSize = ma.getFreeMemory();
MemoryAllocator allocator = ((GemFireCacheImpl) cache).getOffHeapStore(); if((null != allocator) ) { OffHeapMemoryStats offHeapStats = allocator.getStats();