/** * Start the configuration of a <code>lru-memory-size</code> eviction controller. Allow * for any of the attributes to be missing. Store the attributes on the stack * anticipating the declaration of an {@link ObjectSizer}. * @param atts */ private void startLRUMemorySize(Attributes atts) { String lruAction = atts.getValue(ACTION); EvictionAction action = EvictionAction.DEFAULT_EVICTION_ACTION; if(lruAction != null){ action = EvictionAction.parseAction(lruAction); } String maximum = atts.getValue(MAXIMUM); int max = MemLRUCapacityController.DEFAULT_MAXIMUM_MEGABYTES; if (maximum != null) { max = parseInt(maximum); } // Store for later addition of ObjectSizer, if any (the cast is for clarity sake) stack.push(EvictionAttributes.createLRUMemoryAttributes(max, null, action)); }
/** * Start the configuration of a <code>lru-memory-size</code> eviction controller. Allow * for any of the attributes to be missing. Store the attributes on the stack * anticipating the declaration of an {@link ObjectSizer}. * @param atts */ private void startLRUMemorySize(Attributes atts) { String lruAction = atts.getValue(ACTION); EvictionAction action = EvictionAction.DEFAULT_EVICTION_ACTION; if(lruAction != null){ action = EvictionAction.parseAction(lruAction); } String maximum = atts.getValue(MAXIMUM); int max = MemLRUCapacityController.DEFAULT_MAXIMUM_MEGABYTES; if (maximum != null) { max = parseInt(maximum); } // Store for later addition of ObjectSizer, if any (the cast is for clarity sake) stack.push(EvictionAttributes.createLRUMemoryAttributes(max, null, action)); }
public static void createDistRegionWithMemEvictionAttr() { final AttributesFactory factory = new AttributesFactory(); factory.setDataPolicy(DataPolicy.NORMAL); factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes( new ObjectSizerImpl(), EvictionAction.LOCAL_DESTROY)); DistributedRegion distRegion = (DistributedRegion)cache.createRegion("DR1", factory.create()); assertNotNull(distRegion); }
public void testEvictionLRUMemoryAttributes() throws Exception { final String rName = getUniqueName(); CacheCreation cache = new CacheCreation(); RegionAttributesCreation attrs = new RegionAttributesCreation(cache); attrs.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(10, new EvictionObjectSizer())); cache.createRegion(rName, attrs); testXml(cache); }
public void run2() throws CacheException { AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_NO_ACK); factory.setEvictionAttributes(EvictionAttributes .createLRUMemoryAttributes(2, null, EvictionAction.OVERFLOW_TO_DISK)); File d = new File("DiskRegions" + ProcessMgr.getProcessId()); d.mkdirs(); DiskStoreFactory dsf = getCache().createDiskStoreFactory(); dsf.setDiskDirs(new File[]{d}); DiskStore ds = dsf.create(name); factory.setDiskStoreName(ds.getName()); createRegion(name, factory.create()); } };
protected RegionAttributes getRegionAttributes() { AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_NO_ACK); File[] diskDirs = new File[1]; diskDirs[0] = new File("diskRegionDirs/" + ProcessMgr.getProcessId()); diskDirs[0].mkdirs(); factory.setDiskStoreName(getCache().createDiskStoreFactory() .setDiskDirs(diskDirs) .create("DiskDistributedNoAckSyncOverflowRegionTest") .getName()); factory.setEvictionAttributes(EvictionAttributes .createLRUMemoryAttributes(1, null, EvictionAction.OVERFLOW_TO_DISK)); factory.setDiskSynchronous(true); factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); return factory.create(); }
public void setEvictionAttributes(AttributesFactory afact) throws StandardException { EvictionAttributes evictAttr; ObjectSizer osizer = Misc.getMemStore().getObjectSizer(); if (this.evictAction == null) { this.evictAction = EvictionAction.DEFAULT_EVICTION_ACTION; } switch (this.lruType) { case EvictionTableAttribute.ID_MEMSIZE: evictAttr = EvictionAttributes.createLRUMemoryAttributes(this.count, osizer, this.evictAction); break; case EvictionTableAttribute.ID_HEAPPERCENT: evictAttr = EvictionAttributes.createLRUHeapAttributes(osizer, this.evictAction); break; case EvictionTableAttribute.ID_COUNT: evictAttr = EvictionAttributes.createLRUEntryAttributes(this.count, this.evictAction); break; default: throw StandardException.newException(SQLState.PROPERTY_SYNTAX_INVALID + ": unknown eviction type " + this.lruType); } afact.setEvictionAttributes(evictAttr); } }
public void setEvictionAttributes(AttributesFactory afact) throws StandardException { EvictionAttributes evictAttr; ObjectSizer osizer = Misc.getMemStore().getObjectSizer(); if (this.evictAction == null) { this.evictAction = EvictionAction.DEFAULT_EVICTION_ACTION; } switch (this.lruType) { case EvictionTableAttribute.ID_MEMSIZE: evictAttr = EvictionAttributes.createLRUMemoryAttributes(this.count, osizer, this.evictAction); break; case EvictionTableAttribute.ID_HEAPPERCENT: evictAttr = EvictionAttributes.createLRUHeapAttributes(osizer, this.evictAction); break; case EvictionTableAttribute.ID_COUNT: evictAttr = EvictionAttributes.createLRUEntryAttributes(this.count, this.evictAction); break; default: throw StandardException.newException(SQLState.PROPERTY_SYNTAX_INVALID + ": unknown eviction type " + this.lruType); } afact.setEvictionAttributes(evictAttr); } }
public void setEvictionAttributes(AttributesFactory afact) throws StandardException { EvictionAttributes evictAttr; ObjectSizer osizer = Misc.getMemStore().getObjectSizer(); if (this.evictAction == null) { this.evictAction = EvictionAction.DEFAULT_EVICTION_ACTION; } switch (this.lruType) { case EvictionTableAttribute.ID_MEMSIZE: evictAttr = EvictionAttributes.createLRUMemoryAttributes(this.count, osizer, this.evictAction); break; case EvictionTableAttribute.ID_HEAPPERCENT: evictAttr = EvictionAttributes.createLRUHeapAttributes(osizer, this.evictAction); break; case EvictionTableAttribute.ID_COUNT: evictAttr = EvictionAttributes.createLRUEntryAttributes(this.count, this.evictAction); break; default: throw StandardException.newException(SQLState.PROPERTY_SYNTAX_INVALID + ": unknown eviction type " + this.lruType); } afact.setEvictionAttributes(evictAttr); } }
private static void createExampleForMemLRUCapCon() { // DOCS: Begin docs snippet for memory evictor AttributesFactory factory = new AttributesFactory(); EvictionAttributes evAttr = EvictionAttributes.createLRUMemoryAttributes(8); factory.setEvictionAttributes(evAttr); RegionAttributes regAttr = factory.createRegionAttributes(); try { rootRegion.createSubregion("MemLRU_region", regAttr); } catch (CacheException e) { // handle CacheException here } // DOCS: End docs snippet for memory evictor Region aRegion = rootRegion.getSubregion("MemLRU_region"); hydra.Log.getLogWriter().info("Created new region " + aRegion.getFullPath() + " with region attributes " + regAttr); }
public void run() { Cache cache = getCache(); AttributesFactory<Integer, TestDelta> attr = new AttributesFactory<Integer, TestDelta>(); attr.setDiskSynchronous(true); attr.setDataPolicy(DataPolicy.REPLICATE); attr.setScope(Scope.DISTRIBUTED_ACK); attr.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(1, new TestObjectSizer(), EvictionAction.OVERFLOW_TO_DISK)); attr.setDiskDirs(getMyDiskDirs()); Region region = cache.createRegion("region", attr.create()); } });
protected RegionAttributes getRegionAttributes() { AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.DISTRIBUTED_NO_ACK); File[] diskDirs = new File[1]; diskDirs[0] = new File("diskRegionDirs/" + ProcessMgr.getProcessId()); diskDirs[0].mkdirs(); factory.setDiskStoreName(getCache().createDiskStoreFactory() .setDiskDirs(diskDirs) .setTimeInterval(1000) .setQueueSize(0) .create("DiskDistributedNoAckAsyncOverflowRegionTest") .getName()); factory.setEvictionAttributes(EvictionAttributes .createLRUMemoryAttributes(1, null, EvictionAction.OVERFLOW_TO_DISK)); factory.setDiskSynchronous(false); factory.setDataPolicy(DataPolicy.PERSISTENT_REPLICATE); return factory.create(); } }
/** * Validate that a custom {@link ObjectSizer} is called, configured propertly, * and actually limits the size of the <code>Region</code>. * * @throws Exception */ public void testCustomObjectSizer() throws Exception { final String name = this.getUniqueName(); final int entrySize = 1024 * 1024; final int numEntries = 3; AttributesFactory factory = new AttributesFactory(); CustomObjectSizer cs = new CustomObjectSizer(entrySize); factory.setScope(Scope.LOCAL); factory.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(1, cs)); Region r = createRegion(name, factory.create()); for (int size = 0; size < numEntries; size++) { r.put(new Integer(size), new byte[entrySize]); } assertTrue("ObjectSizer was not triggered", cs.wasCalled()); long actualSize = getLRUStats(r).getCounter(); int bytesPut = (entrySize * numEntries); assertTrue("Expected bytes put: " + bytesPut + " is not < " + actualSize, actualSize < bytesPut); }
/** * Prints out the number of bytes that a region entry occupies in the VM. */ public void testEntryOverHead() throws Exception { final String name = this.getUniqueName(); AttributesFactory factory = new AttributesFactory(); factory.setScope(Scope.LOCAL); factory.setEvictionAttributes(EvictionAttributes .createLRUMemoryAttributes(50)); Region region; region = createRegion(name, factory.create()); String s = "Each entry occupies " + getEntryOverhead(region) + " bytes"; region.getCache().getDistributedSystem().getLogWriter().info(s); }
factory.setScope(Scope.LOCAL); factory.setEvictionAttributes(EvictionAttributes .createLRUMemoryAttributes(20, new TestObjectSizerImpl(), EvictionAction.LOCAL_DESTROY));
public void run2() { final AttributesFactory factory = new AttributesFactory(); factory.setEnableOffHeapMemory(isOffHeap()); factory.setPartitionAttributes(new PartitionAttributesFactory() .setRedundantCopies(redundantCopies).setLocalMaxMemory(16).setTotalNumBuckets(maxBuckets) .create()); factory.setEvictionAttributes(EvictionAttributes .createLRUMemoryAttributes( new ObjectSizerImpl(), EvictionAction.LOCAL_DESTROY)); final PartitionedRegion pr = (PartitionedRegion)createRootRegion(name, factory.create()); assertNotNull(pr); } };
public void run() { try { final AttributesFactory factory = new AttributesFactory(); factory.setEnableOffHeapMemory(isOffHeap()); factory.setPartitionAttributes(new PartitionAttributesFactory() .setRedundantCopies(redundantCopies).setLocalMaxMemory(localMaxMem).setTotalNumBuckets( maxBuckets).create()); factory.setEvictionAttributes(EvictionAttributes .createLRUMemoryAttributes( new ObjectSizerImpl(), EvictionAction.OVERFLOW_TO_DISK)); factory.setDiskSynchronous(true); DiskStoreFactory dsf = getCache().createDiskStoreFactory(); final File[] diskDirs = new File[1]; diskDirs[0] = new File("overflowDir/" + uniqName + "_" + OSProcess.getId()); diskDirs[0].mkdirs(); dsf.setDiskDirs(diskDirs); DiskStore ds = dsf.create(name); factory.setDiskStoreName(ds.getName()); final PartitionedRegion pr = (PartitionedRegion)createRootRegion( name, factory.create()); assertNotNull(pr); } catch (final CacheException ex) { fail("While creating Partitioned region", ex); } } };
public void run() { Cache cache = getCache(); AttributesFactory<Integer, TestDelta> attr = new AttributesFactory<Integer, TestDelta>(); attr.setDiskSynchronous(true); PartitionAttributesFactory<Integer, TestDelta> paf = new PartitionAttributesFactory<Integer, TestDelta>(); paf.setRedundantCopies(1); if(enableLRU) { paf.setLocalMaxMemory(1); // memlru limit is 1 megabyte attr.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes(new TestObjectSizer(), EvictionAction.OVERFLOW_TO_DISK)); attr.setDiskDirs(getMyDiskDirs()); } PartitionAttributes<Integer, TestDelta> prAttr = paf.create(); attr.setPartitionAttributes(prAttr); attr.setDataPolicy(DataPolicy.PARTITION); attr.setSubscriptionAttributes(new SubscriptionAttributes(InterestPolicy.ALL)); Region<Integer, TestDelta> region = cache.createRegion("region", attr.create()); } });
public void testReplicatedRegionAttributesForMemLruWithoutMaxMem() throws CacheException { final int redundantCopies = 1; CacheCreation cache = new CacheCreation(); AttributesFactory fac = new AttributesFactory(); fac.setDataPolicy(DataPolicy.REPLICATE); fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes( null, EvictionAction.OVERFLOW_TO_DISK)); cache.createRegion("parRoot", fac.create()); testXml(cache); Cache c = getCache(); assertNotNull(c); Region region = c.getRegion("parRoot"); assertNotNull(region); RegionAttributes regionAttrs = region.getAttributes(); EvictionAttributes ea = regionAttrs.getEvictionAttributes(); assertEquals(ea.getAlgorithm(),EvictionAlgorithm.LRU_MEMORY); assertEquals(ea.getAction(), EvictionAction.OVERFLOW_TO_DISK); assertEquals(ea.getMaximum(), MemLRUCapacityController.DEFAULT_MAXIMUM_MEGABYTES); }
public void testReplicatedRegionAttributesForMemLruWithMaxMem() throws CacheException { final int redundantCopies = 1; final int maxMem=25; CacheCreation cache = new CacheCreation(); AttributesFactory fac = new AttributesFactory(); fac.setDataPolicy(DataPolicy.REPLICATE); fac.setEvictionAttributes(EvictionAttributes.createLRUMemoryAttributes( maxMem,null, EvictionAction.OVERFLOW_TO_DISK)); cache.createRegion("parRoot", fac.create()); testXml(cache); Cache c = getCache(); assertNotNull(c); Region region = c.getRegion("parRoot"); assertNotNull(region); RegionAttributes regionAttrs = region.getAttributes(); EvictionAttributes ea = regionAttrs.getEvictionAttributes(); assertEquals(ea.getAlgorithm(),EvictionAlgorithm.LRU_MEMORY); assertEquals(ea.getAction(), EvictionAction.OVERFLOW_TO_DISK); assertEquals(ea.getMaximum(), maxMem); }