Skip to content

Commit

Permalink
some enhancements to caching
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@2233 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Jun 21, 2006
1 parent d464506 commit 650c7e9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 4 additions & 0 deletions source/de/anomic/kelondro/kelondroBytesIntMap.java
Expand Up @@ -56,6 +56,10 @@ public void addi(byte[] key, int i) {
}

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);
Expand Down
4 changes: 4 additions & 0 deletions source/de/anomic/kelondro/kelondroIntBytesMap.java
Expand Up @@ -56,6 +56,10 @@ public void addb(int ii, byte[] value) {
}

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);
Expand Down
4 changes: 2 additions & 2 deletions source/de/anomic/kelondro/kelondroRecords.java
Expand Up @@ -427,7 +427,7 @@ private void initCache(long buffersize) {
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)
};
Expand Down Expand Up @@ -916,7 +916,7 @@ private boolean cacheSpace(int forPriority) {
// 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);
Expand Down
10 changes: 9 additions & 1 deletion source/de/anomic/kelondro/kelondroRowCollection.java
Expand Up @@ -47,6 +47,8 @@ public kelondroRowCollection(kelondroRow rowdef, int objectCount) {
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) {
Expand All @@ -56,6 +58,8 @@ public kelondroRowCollection(kelondroRow rowdef, int objectCount, byte[] cache)
this.sortColumn = 0;
this.sortOrder = null;
this.sortBound = 0;
this.lastTimeRead = System.currentTimeMillis();
this.lastTimeWrote = System.currentTimeMillis();
}

private final void ensureSize(int elements) {
Expand All @@ -68,6 +72,7 @@ private final void ensureSize(int elements) {
}

public void trim() {
if (chunkcache.length == 0) return;
synchronized (chunkcache) {
int needed = chunkcount * rowdef.objectsize();
if (chunkcache.length == needed) return;
Expand All @@ -92,6 +97,7 @@ public final kelondroRow.Entry get(int index) {
synchronized (chunkcache) {
System.arraycopy(chunkcache, index * rowdef.objectsize(), a, 0, rowdef.objectsize());
}
this.lastTimeRead = System.currentTimeMillis();
return rowdef.newEntry(a);
}

Expand Down Expand Up @@ -141,6 +147,7 @@ public final void addAll(kelondroRowCollection c) {

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--;
Expand All @@ -160,6 +167,7 @@ public void clear() {
this.chunkcache = new byte[0];
this.chunkcount = 0;
this.sortBound = 0;
this.lastTimeWrote = System.currentTimeMillis();
}

public int size() {
Expand Down Expand Up @@ -211,7 +219,7 @@ protected final void sort(kelondroOrder newOrder, int newColumn) {
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 {
Expand Down

0 comments on commit 650c7e9

Please sign in to comment.