comparison src/org/dancres/blitz/entry/SleeveCache.java @ 21:8417eaebf5ab

Fix partitioning to size caches properly
author Dan Creswell <dan.creswell@gmail.com>
date Sat, 22 Aug 2009 23:28:55 +0100
parents 62b11f04d859
children b7e52953b7a6
comparison
equal deleted inserted replaced
20:66c7bfc3e89e 21:8417eaebf5ab
61 try { 61 try {
62 DESIRED_ENTRIES_PER_PARTITION = 62 DESIRED_ENTRIES_PER_PARTITION =
63 ((Integer) ConfigurationFactory.getEntry("cacheEntriesPerPartition", int.class, 63 ((Integer) ConfigurationFactory.getEntry("cacheEntriesPerPartition", int.class,
64 new Integer(128))).intValue(); 64 new Integer(128))).intValue();
65 65
66 theLogger.log(Level.SEVERE, "Loaded config: " + ((Integer) ConfigurationFactory.getEntry("cacheEntriesPerPartition", int.class, 66 theLogger.log(Level.SEVERE, "Loaded config: " +
67 new Integer(128))).intValue()); 67 ((Integer) ConfigurationFactory.getEntry("cacheEntriesPerPartition", int.class,
68 new Integer(32))).intValue());
68 69
69 } catch (ConfigurationException aCE) { 70 } catch (ConfigurationException aCE) {
70 theLogger.log(Level.SEVERE, "Failed to source partition setup", aCE); 71 theLogger.log(Level.SEVERE, "Failed to source partition setup", aCE);
71 } 72 }
72 } 73 }
145 } 146 }
146 147
147 CacheSize myCacheSize = (CacheSize) theConstraints.get(CacheSize.class); 148 CacheSize myCacheSize = (CacheSize) theConstraints.get(CacheSize.class);
148 149
149 int myNumPartitions; 150 int myNumPartitions;
150 151 int myEntriesPerCache;
151 if (DESIRED_ENTRIES_PER_PARTITION == -1) 152
153 if (DESIRED_ENTRIES_PER_PARTITION == -1) {
152 myNumPartitions = 1; 154 myNumPartitions = 1;
153 else 155 myEntriesPerCache = myCacheSize.getSize();
156 } else {
154 myNumPartitions = (myCacheSize.getSize() / DESIRED_ENTRIES_PER_PARTITION); 157 myNumPartitions = (myCacheSize.getSize() / DESIRED_ENTRIES_PER_PARTITION);
158 myEntriesPerCache = DESIRED_ENTRIES_PER_PARTITION;
159 }
155 160
156 // Find nearest power of 2 > or = 161 // Find nearest power of 2 > or =
157 // 162 //
158 int myPower; 163 int myPower;
159 for (myPower = 1; myPower < myNumPartitions; myPower = myPower << 1); 164 for (myPower = 1; myPower < myNumPartitions; myPower = myPower << 1);
160 theNumPartitions = myPower; 165 theNumPartitions = myPower;
161 166
162 thePartitionsMask = theNumPartitions - 1; 167 thePartitionsMask = theNumPartitions - 1;
163 168
164 theLogger.log(Level.INFO, aStore.getType() + " cache size = " 169 theLogger.log(Level.INFO, aStore.getType() + " cache size = "
165 + myCacheSize.getSize() + " partitions = " + theNumPartitions + " mask = " + Integer.toHexString(thePartitionsMask)); 170 + myCacheSize.getSize() + " partitions = " + theNumPartitions +
171 " mask = " + Integer.toHexString(thePartitionsMask) + " partition size = " + myEntriesPerCache);
166 172
167 theStoreCaches = new ArcCache[theNumPartitions]; 173 theStoreCaches = new ArcCache[theNumPartitions];
168 174
169 for (int i = 0; i < theNumPartitions; i++) { 175 for (int i = 0; i < theNumPartitions; i++) {
170 theStoreCaches[i] = new ArcCache(aStore, theNumPartitions); 176 theStoreCaches[i] = new ArcCache(aStore, myEntriesPerCache);
171 177
172 theIndexer = CacheIndexer.getIndexer(theStore.getType()); 178 theIndexer = CacheIndexer.getIndexer(theStore.getType());
173 179
174 theStoreCaches[i].add(new CacheListenerImpl(theIndexer)); 180 theStoreCaches[i].add(new CacheListenerImpl(theIndexer));
175 } 181 }