some enhancements to caching

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2233 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 19 years ago
parent d4645062bc
commit 650c7e9e55

@ -56,6 +56,10 @@ public class kelondroBytesIntMap extends kelondroRowBufferedSet {
}
public int removei(byte[] key) {
if (size() == 0) {
if (System.currentTimeMillis() - this.lastTimeWrote > 10000) this.trim();
return -1;
}
kelondroRow.Entry indexentry = remove(key);
if (indexentry == null) return -1;
return (int) indexentry.getColLongB256(1);

@ -56,6 +56,10 @@ public class kelondroIntBytesMap extends kelondroRowBufferedSet {
}
public byte[] removeb(int ii) {
if (size() == 0) {
if (System.currentTimeMillis() - this.lastTimeWrote > 10000) this.trim();
return null;
}
kelondroRow.Entry indexentry = super.remove(kelondroNaturalOrder.encodeLong((long) ii, 4));
if (indexentry == null) return null;
return indexentry.getColBytes(1);

@ -427,7 +427,7 @@ public class kelondroRecords {
this.cacheScore = new kelondroMScoreCluster(); // cache control of CP_HIGH caches
}
this.cacheHeaders = new kelondroIntBytesMap[]{
new kelondroIntBytesMap(this.headchunksize, 0),
new kelondroIntBytesMap(this.headchunksize, this.cacheSize / 2),
new kelondroIntBytesMap(this.headchunksize, 0),
new kelondroIntBytesMap(this.headchunksize, 0)
};
@ -916,7 +916,7 @@ public class kelondroRecords {
// we simply clear the cache
String error = "cachScore error: " + e.getMessage() + "; cachesize=" + cacheSize + ", cache.size()=[" + cacheHeaders[0].size() + "," + cacheHeaders[1].size() + "," + cacheHeaders[2].size() + "], cacheScore.size()=" + cacheScore.size();
cacheScore = new kelondroMScoreCluster();
cacheHeaders[CP_LOW] = new kelondroIntBytesMap(headchunksize, 0);
cacheHeaders[CP_LOW] = new kelondroIntBytesMap(headchunksize, cacheSize / 2);
cacheHeaders[CP_MEDIUM] = new kelondroIntBytesMap(headchunksize, 0);
cacheHeaders[CP_HIGH] = new kelondroIntBytesMap(headchunksize, 0);
cacheHeaders[0].setOrdering(kelondroNaturalOrder.naturalOrder, 0);

@ -47,6 +47,8 @@ public class kelondroRowCollection {
this.sortColumn = 0;
this.sortOrder = null;
this.sortBound = 0;
this.lastTimeRead = System.currentTimeMillis();
this.lastTimeWrote = System.currentTimeMillis();
}
public kelondroRowCollection(kelondroRow rowdef, int objectCount, byte[] cache) {
@ -56,6 +58,8 @@ public class kelondroRowCollection {
this.sortColumn = 0;
this.sortOrder = null;
this.sortBound = 0;
this.lastTimeRead = System.currentTimeMillis();
this.lastTimeWrote = System.currentTimeMillis();
}
private final void ensureSize(int elements) {
@ -68,6 +72,7 @@ public class kelondroRowCollection {
}
public void trim() {
if (chunkcache.length == 0) return;
synchronized (chunkcache) {
int needed = chunkcount * rowdef.objectsize();
if (chunkcache.length == needed) return;
@ -92,6 +97,7 @@ public class kelondroRowCollection {
synchronized (chunkcache) {
System.arraycopy(chunkcache, index * rowdef.objectsize(), a, 0, rowdef.objectsize());
}
this.lastTimeRead = System.currentTimeMillis();
return rowdef.newEntry(a);
}
@ -141,6 +147,7 @@ public class kelondroRowCollection {
public final void remove(int p) {
assert ((p >= 0) && (p < chunkcount) && (chunkcount > 0));
//System.out.println("REMOVE at pos " + p + ", chunkcount=" + chunkcount + ", sortBound=" + sortBound);
synchronized (chunkcache) {
System.arraycopy(chunkcache, (p + 1) * rowdef.objectsize(), chunkcache, p * rowdef.objectsize(), (chunkcount - p - 1) * rowdef.objectsize());
chunkcount--;
@ -160,6 +167,7 @@ public class kelondroRowCollection {
this.chunkcache = new byte[0];
this.chunkcount = 0;
this.sortBound = 0;
this.lastTimeWrote = System.currentTimeMillis();
}
public int size() {
@ -211,7 +219,7 @@ public class kelondroRowCollection {
protected final void sort() {
assert (this.sortOrder != null);
if (this.sortBound == this.chunkcount) return; // this is already sorted
//System.out.println("SORT(chunkcount=" + this.chunkcount + ", sortbound=" + this.sortbound + ")");
//System.out.println("SORT(chunkcount=" + this.chunkcount + ", sortBound=" + this.sortBound + ")");
if (this.sortBound > 1) {
qsort(0, this.sortBound, this.chunkcount);
} else {

Loading…
Cancel
Save