fixed a bug in new caching

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2071 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent 35f9418117
commit 23ced30e83

@ -67,19 +67,26 @@ public class kelondroObjectCache {
private long maxAge;
private long minMem;
private int readHit, readMiss, writeUnique, writeDouble;
private String name;
public kelondroObjectCache(int maxSize, long maxAge, long minMem) {
public kelondroObjectCache(String name, int maxSize, long maxAge, long minMem) {
this.name = name;
this.cache = new TreeMap();
this.ages = new kelondroMScoreCluster();
this.startTime = System.currentTimeMillis();
this.maxAge = maxAge;
this.minMem = minMem;
this.maxSize = Math.max(maxSize, 1);
this.maxAge = Math.max(maxAge, 10000);
this.minMem = Math.max(minMem, 1024 * 1024);
this.readHit = 0;
this.readMiss = 0;
this.writeUnique = 0;
this.writeDouble = 0;
}
public String getName() {
return name;
}
public void setMaxAge(long maxAge) {
this.maxAge = maxAge;
}
@ -162,10 +169,11 @@ public class kelondroObjectCache {
String k;
synchronized(cache) {
while ((ages.size() > 0) &&
((k = bestFlush()) != null) &&
((size() > maxSize) ||
(longEmit(ages.getMinScore()) > maxAge) ||
(Runtime.getRuntime().freeMemory() < minMem)) &&
((k = bestFlush()) != null)) {
((System.currentTimeMillis() - longEmit(ages.getScore(k))) > maxAge) ||
(Runtime.getRuntime().freeMemory() < minMem))
) {
cache.remove(k);
ages.deleteScore(k);
if (Runtime.getRuntime().freeMemory() < minMem) System.gc(); // prevent unnecessary loops

@ -123,7 +123,7 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {
super.setLogger(log);
long objectbuffersize = objectCachePercent * buffersize / (nodeCachePercent + objectCachePercent);
long nodecachesize = objectbuffersize / (super.objectsize + 8 * columns.length);
this.objectCache = new kelondroObjectCache((int) nodecachesize, nodecachesize * 300 , 4*1024*1024);
this.objectCache = new kelondroObjectCache(this.filename, (int) nodecachesize, nodecachesize * 300 , 4*1024*1024);
}
public kelondroTree(kelondroRA ra, long buffersize, int[] columns, boolean exitOnFail) {
@ -149,7 +149,7 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {
super.setLogger(log);
long objectbuffersize = objectCachePercent * buffersize / (nodeCachePercent + objectCachePercent);
long nodecachesize = objectbuffersize / (super.objectsize + 8 * columns.length);
this.objectCache = new kelondroObjectCache((int) nodecachesize, nodecachesize * 300 , 4*1024*1024);
this.objectCache = new kelondroObjectCache(this.filename, (int) nodecachesize, nodecachesize * 300 , 4*1024*1024);
}
public kelondroTree(File file, long buffersize) throws IOException {
@ -159,7 +159,7 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {
super.setLogger(log);
long objectbuffersize = objectCachePercent * buffersize / (nodeCachePercent + objectCachePercent);
long nodecachesize = objectbuffersize / (super.objectsize + 8 * super.columns());
this.objectCache = new kelondroObjectCache((int) nodecachesize, nodecachesize * 300 , 4*1024*1024);
this.objectCache = new kelondroObjectCache(this.filename, (int) nodecachesize, nodecachesize * 300 , 4*1024*1024);
}
public kelondroTree(kelondroRA ra, long buffersize) throws IOException {
@ -169,7 +169,7 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {
super.setLogger(log);
long objectbuffersize = objectCachePercent * buffersize / (nodeCachePercent + objectCachePercent);
long nodecachesize = objectbuffersize / (super.objectsize + 8 * super.columns());
this.objectCache = new kelondroObjectCache((int) nodecachesize, nodecachesize * 300 , 4*1024*1024);
this.objectCache = new kelondroObjectCache(this.filename, (int) nodecachesize, nodecachesize * 300 , 4*1024*1024);
}
private void writeOrderType() {
@ -217,16 +217,19 @@ public class kelondroTree extends kelondroRecords implements kelondroIndex {
public byte[][] get(byte[] key) throws IOException {
// System.out.println("kelondroTree.get " + new String(key) + " in " + filename);
byte[][] result = (byte[][]) objectCache.get(key);
if (result != null) return result;
if (result != null) {
//System.out.println("cache hit in objectCache, db:" + super.filename);
return result;
}
// writeLock.stay(2000, 1000);
synchronized (writeSearchObj) {
writeSearchObj.process(key);
if (writeSearchObj.found()) {
result = writeSearchObj.getMatcher().getValues();
objectCache.put(key, result);
} else {
result = null;
}
objectCache.put(key, result);
}
// writeLock.release();
return result;

Loading…
Cancel
Save