public boolean mustEvict(LRUStatistics stats, Region region, int delta) { return stats.getCounter() + delta > stats.getLimit(); } };
public boolean done() { return cc.getStats().getEvictions() > 0; }
public LRUStatistics initStats(Object region, StatisticsFactory sf) { setRegionName(region); final LRUStatistics stats = new LRUStatistics(sf, getRegionName(), this); stats.setLimit( LRUAlgorithm.this.getLimit() ); stats.setDestroysLimit( 1000 ); setStats(stats); return stats; }
/** * Releases resources obtained by this <code>LRUAlgorithm</code> */ public void close() { if (this.stats != null) { if (bucketRegion != null) { this.stats.incEvictions(bucketRegion.getEvictions() * -1); this.stats.decrementCounter(bucketRegion.getCounter()); bucketRegion.close(); } else { this.stats.close(); } } }
/** * This test does the following :<br> * 1)Perform put operation <br> * 2)Verify count of evicted entries <br> */ public void testEntryEvictionCount() { try { assertNotNull(cache); Region rgn = cache.getRegion(Region.SEPARATOR + regionName); assertNotNull(rgn); assertTrue("Entry count not 0 ", new Long(0).equals(new Long(lifoStats .getCounter()))); // put four entries into the region for (int i = 0; i < 8; i++) { rgn.put(new Long(i), new Long(i)); } assertTrue("1)Total eviction count is not correct ", new Long(3) .equals(new Long(lifoStats.getEvictions()))); rgn.put(new Long(8), new Long(8)); rgn.get(new Long(5)); assertTrue("2)Total eviction count is not correct ", new Long(4) .equals(new Long(lifoStats.getEvictions()))); } catch (Exception ex) { ex.printStackTrace(); fail("Test failed"); } }
public long getEntrySize() { if (lruMemoryStats != null) { return lruMemoryStats.getCounter(); } return ManagementConstants.NOT_AVAILABLE_LONG; }
@Override public void run2() throws CacheException { PartitionedRegion pr1 = (PartitionedRegion)cache.getRegion("PR1"); getLogWriter().info("dddd local"+pr1.getLocalMaxMemory()); getLogWriter().info("dddd local evi"+((AbstractLRURegionMap)pr1.entries)._getLruList().stats() .getEvictions()); getLogWriter().info("dddd local entries"+((AbstractLRURegionMap)pr1.entries)._getLruList().stats() .getCounter()/(1024*1024)); HeapMemoryMonitor hmm = ((InternalResourceManager) cache.getResourceManager()).getHeapMonitor(); long memused=hmm.getBytesUsed()/(1024*1024); getLogWriter().info("dddd local memused= "+memused); assertTrue(((AbstractLRURegionMap)pr1.entries)._getLruList().stats() .getEvictions() >= extraEntries / 2); assertEquals(((AbstractLRURegionMap)pr1.entries)._getLruList().stats() .getDestroys(), ((AbstractLRURegionMap)pr1.entries)._getLruList() .stats().getEvictions()); PartitionedRegion pr2 = (PartitionedRegion)cache.getRegion("PR2"); assertTrue(((AbstractLRURegionMap)pr2.entries)._getLruList().stats() .getEvictions() >= extraEntries / 2); assertEquals(((AbstractLRURegionMap)pr2.entries)._getLruList().stats() .getDestroys(), 0); assertTrue(pr2.getDiskRegionStats().getNumOverflowOnDisk()>= extraEntries / 2); } });
@Override public void run2() throws CacheException { PartitionedRegion pr1 = (PartitionedRegion)cache.getRegion("PR1"); assertEquals(((AbstractLRURegionMap)pr1.entries)._getLruList().stats() .getEvictions(), (extraEnteries-maxEnteries) / 2); assertEquals(((AbstractLRURegionMap)pr1.entries)._getLruList().stats() .getDestroys(), ((AbstractLRURegionMap)pr1.entries)._getLruList() .stats().getEvictions()); PartitionedRegion pr2 = (PartitionedRegion)cache.getRegion("PR2"); assertEquals(((AbstractLRURegionMap)pr2.entries)._getLruList().stats() .getEvictions(), (extraEnteries-maxEnteries) / 2); assertEquals(((AbstractLRURegionMap)pr2.entries)._getLruList().stats() .getDestroys(), 0); assertEquals(pr2.getDiskRegionStats().getNumOverflowOnDisk(), (extraEnteries-maxEnteries) / 2); } });
String s = "Limit is " + lruStats.getLimit() + " evictions are " + lruStats.getEvictions(); throw new RuntimeException(s);
public LRUStatistics initStats(Object region, StatisticsFactory sf) { String regionName; if (region instanceof Region) { regionName = ((Region)region).getName(); } else if (region instanceof PlaceHolderDiskRegion) { regionName = ((PlaceHolderDiskRegion)region).getName(); // @todo make it shorter (I think it is the fullPath } else { throw new IllegalStateException("expected Region or PlaceHolderDiskRegion"); } final LRUStatistics stats = new LRUStatistics(sf, "TestLRUStatistics" + regionName, this); stats.setLimit( limit() ); return stats; } }
@Override public void run2() throws CacheException { final PartitionedRegion pr1 = (PartitionedRegion)cache.getRegion("PR1"); final PartitionedRegion pr2 = (PartitionedRegion)cache.getRegion("PR2"); assertEquals(maxEnteries, ((AbstractLRURegionMap)pr1.entries) ._getLruList().stats().getLimit()); assertEquals(maxEnteries, ((AbstractLRURegionMap)pr2.entries) ._getLruList().stats().getLimit()); assertEquals(1000, ((AbstractLRURegionMap)pr1.entries)._getLruList() .stats().getDestroysLimit()); assertEquals(1000, ((AbstractLRURegionMap)pr2.entries)._getLruList() .stats().getDestroysLimit()); } });
} /** * called when an LRU map is cleared... resets stats and releases prev and next. */ public void clear(RegionVersionVector rvv) { if (rvv != null) { return; // when concurrency checks are enabled the clear operation removes entries iteratively } synchronized (this.lock ) { if (bucketRegion!=null) { this.stats.decrementCounter(bucketRegion.getCounter()); bucketRegion.resetCounter(); } else { this.stats.resetCounter(); } initHeadAndTail(); // LRUClockNode node = this.tail; // node.setEvicted(); // // // NYI need to walk the list and call unsetInList for each one. // // // tail's next should already be null. // setHead( node ); } }
public long limit() { if ( stats == null ) { throw new InternalGemFireException(LocalizedStrings.LRUAlgorithm_LRU_STATS_IN_EVICTION_CONTROLLER_INSTANCE_SHOULD_NOT_BE_NULL.toLocalizedString()); } if (bucketRegion != null) { return bucketRegion.getLimit(); } return stats.getLimit(); }
/** * Sets the limit on the number of entries allowed. This change takes place on * next region operation that could increase the region size. */ public void setMaximumEntries( int maximumEntries ) { if (maximumEntries <= 0 ) throw new IllegalArgumentException(LocalizedStrings.LRUCapacityController_MAXIMUM_ENTRIES_MUST_BE_POSITIVE.toLocalizedString()); this.maximumEntries = maximumEntries; if (bucketRegion != null) { bucketRegion.setLimit(this.maximumEntries); } else if (this.stats != null) { this.stats.setLimit(this.maximumEntries); } }
this.stats.incEvaluations(numEvals); return aNode; logger.trace(LogMarker.LRU_CLOCK, LocalizedMessage.create(LocalizedStrings.NewLRUClockHand_GREEDILY_PICKING_AN_AVAILABLE_ENTRY)); this.stats.incGreedyReturns(1); this.stats.incEvaluations(numEvals); return aNode;
public void removeLRUStats(LRUStatistics lruStats) { regionMonitor.removeLRUStatistics(lruStats.getStats()); }
public void closeStats() { LRUStatistics ls = this.stats; if( ls != null ) { ls.close(); } }
/** remove an entry from the pipe... (marks it evicted to be skipped later) */ public boolean unlinkEntry(LRUClockNode entry) { if (logger.isTraceEnabled(LogMarker.LRU_CLOCK)) { logger.trace(LogMarker.LRU_CLOCK, LocalizedMessage.create(LocalizedStrings.NewLRUClockHand_UNLINKENTRY_CALLED, entry)); } entry.setEvicted(); stats().incDestroys(); synchronized(lock) { LRUClockNode next = entry.nextLRUNode(); LRUClockNode prev = entry.prevLRUNode(); if(next == null || prev == null) { //not in the list anymore. return false; } next.setPrevLRUNode(prev); prev.setNextLRUNode(next); entry.setNextLRUNode(null); entry.setPrevLRUNode(null); this.size--; } return true; }
@Override public LRUClockNode getLRUEntry() { long numEvals = 0; LRUClockNode aNode = null; //search for entry to return from list for (;;) { aNode = getTailEntry(); //end of Lifo list stop searching if (aNode == null) { break; } numEvals++; synchronized (aNode) { //look for another entry if in transaction boolean inUseByTransaction = false; if (aNode instanceof AbstractRegionEntry) { if (((AbstractRegionEntry) aNode).isInUseByTransaction()) { inUseByTransaction=true; } } //if entry NOT used by transaction and NOT evicted return entry if (!inUseByTransaction && !aNode.testEvicted()) { break; } } } this.stats().incEvaluations(numEvals); return aNode; } }
.getCounter()))); .equals(new Long(lifoStats.getEvictions()))); rgn.put(new Long(60), newDummyObject(60)); rgn.get(new Long(55)); assertTrue("2)Total eviction count is not correct ", new Long(11) .equals(new Long(lifoStats.getEvictions())));