comparison src/org/dancres/blitz/entry/SleeveCache.java @ 22:b7e52953b7a6

Add some cache/memory statistics to help spot potential exhaustion and other tuning issues.
author Dan Creswell <dan.creswell@gmail.com>
date Fri, 28 Aug 2009 17:23:33 +0100
parents 8417eaebf5ab
children
comparison
equal deleted inserted replaced
21:8417eaebf5ab 22:b7e52953b7a6
12 import org.dancres.blitz.mangler.MangledEntry; 12 import org.dancres.blitz.mangler.MangledEntry;
13 13
14 import org.dancres.blitz.Logging; 14 import org.dancres.blitz.Logging;
15 import org.dancres.blitz.stats.StatGenerator; 15 import org.dancres.blitz.stats.StatGenerator;
16 import org.dancres.blitz.stats.Stat; 16 import org.dancres.blitz.stats.Stat;
17 import org.dancres.blitz.stats.SearchStat; 17 import org.dancres.blitz.stats.StoreStat;
18 import org.dancres.blitz.stats.StatsBoard; 18 import org.dancres.blitz.stats.StatsBoard;
19 19
20 import org.dancres.blitz.oid.OID; 20 import org.dancres.blitz.oid.OID;
21 21
22 import org.dancres.blitz.arc.ArcCache; 22 import org.dancres.blitz.arc.ArcCache;
71 theLogger.log(Level.SEVERE, "Failed to source partition setup", aCE); 71 theLogger.log(Level.SEVERE, "Failed to source partition setup", aCE);
72 } 72 }
73 } 73 }
74 74
75 private final ArcCache[] theStoreCaches; 75 private final ArcCache[] theStoreCaches;
76 private final CacheSize theCacheSize;
76 private final int theNumPartitions; 77 private final int theNumPartitions;
77 private final int thePartitionsMask; 78 private final int thePartitionsMask;
78 79
79 private Storage theStore; 80 private Storage theStore;
80
81 private CountersImpl theCounters; 81 private CountersImpl theCounters;
82
83 private EntryConstraints theConstraints; 82 private EntryConstraints theConstraints;
84
85 private CacheIndexer theIndexer; 83 private CacheIndexer theIndexer;
86 84
87 private long theId = StatGenerator.UNSET_ID; 85 private long theId = StatGenerator.UNSET_ID;
88 86
89 private static class OfferTracker { 87 private static class OfferTracker {
143 theStore.getType()); 141 theStore.getType());
144 myIOE.initCause(aCE); 142 myIOE.initCause(aCE);
145 throw myIOE; 143 throw myIOE;
146 } 144 }
147 145
148 CacheSize myCacheSize = (CacheSize) theConstraints.get(CacheSize.class); 146 theCacheSize = (CacheSize) theConstraints.get(CacheSize.class);
149 147
150 int myNumPartitions; 148 int myNumPartitions;
151 int myEntriesPerCache; 149 int myEntriesPerCache;
152 150
153 if (DESIRED_ENTRIES_PER_PARTITION == -1) { 151 if (DESIRED_ENTRIES_PER_PARTITION == -1) {
154 myNumPartitions = 1; 152 myNumPartitions = 1;
155 myEntriesPerCache = myCacheSize.getSize(); 153 myEntriesPerCache = theCacheSize.getSize();
156 } else { 154 } else {
157 myNumPartitions = (myCacheSize.getSize() / DESIRED_ENTRIES_PER_PARTITION); 155 myNumPartitions = (theCacheSize.getSize() / DESIRED_ENTRIES_PER_PARTITION);
158 myEntriesPerCache = DESIRED_ENTRIES_PER_PARTITION; 156 myEntriesPerCache = DESIRED_ENTRIES_PER_PARTITION;
159 } 157 }
160 158
161 // Find nearest power of 2 > or = 159 // Find nearest power of 2 > or =
162 // 160 //
165 theNumPartitions = myPower; 163 theNumPartitions = myPower;
166 164
167 thePartitionsMask = theNumPartitions - 1; 165 thePartitionsMask = theNumPartitions - 1;
168 166
169 theLogger.log(Level.INFO, aStore.getType() + " cache size = " 167 theLogger.log(Level.INFO, aStore.getType() + " cache size = "
170 + myCacheSize.getSize() + " partitions = " + theNumPartitions + 168 + theCacheSize.getSize() + " partitions = " + theNumPartitions +
171 " mask = " + Integer.toHexString(thePartitionsMask) + " partition size = " + myEntriesPerCache); 169 " mask = " + Integer.toHexString(thePartitionsMask) + " partition size = " + myEntriesPerCache);
172 170
173 theStoreCaches = new ArcCache[theNumPartitions]; 171 theStoreCaches = new ArcCache[theNumPartitions];
174 172
175 for (int i = 0; i < theNumPartitions; i++) { 173 for (int i = 0; i < theNumPartitions; i++) {
212 myTitles[i] = theTrackers[i].getTitle(); 210 myTitles[i] = theTrackers[i].getTitle();
213 myMisses[i] = theTrackers[i].getMisses(); 211 myMisses[i] = theTrackers[i].getMisses();
214 myDeld[i] = theTrackers[i].getDeld(); 212 myDeld[i] = theTrackers[i].getDeld();
215 } 213 }
216 214
217 return new SearchStat(theId, theStore.getType(), myTitles, 215 int myActiveCache = 0;
218 myMisses, myDeld); 216
217 for (int i = 0; i < theStoreCaches.length; i++)
218 myActiveCache += theStoreCaches[i].getActiveSize();
219
220 return new StoreStat(theId, theStore.getType(), myTitles,
221 myMisses, myDeld, myActiveCache, theCacheSize.getSize());
219 } 222 }
220 223
221 private int getPartition(CacheBlockDescriptor aCBD) { 224 private int getPartition(CacheBlockDescriptor aCBD) {
222 OID myOID = (OID) aCBD.getId(); 225 OID myOID = (OID) aCBD.getId();
223 226