Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
some enhancements to caching
orbiter650c7e9e5519
diff --git a/source/de/anomic/kelondro/kelondroBytesIntMap.java b/source/de/anomic/kelondro/kelondroBytesIntMap.javaindex 70451da3c..2fbd8de3b 100644--- a/source/de/anomic/kelondro/kelondroBytesIntMap.java+++ b/source/de/anomic/kelondro/kelondroBytesIntMap.java@@ -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);diff --git a/source/de/anomic/kelondro/kelondroIntBytesMap.java b/source/de/anomic/kelondro/kelondroIntBytesMap.javaindex 104ab7156..952647522 100644--- a/source/de/anomic/kelondro/kelondroIntBytesMap.java+++ b/source/de/anomic/kelondro/kelondroIntBytesMap.java@@ -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);diff --git a/source/de/anomic/kelondro/kelondroRecords.java b/source/de/anomic/kelondro/kelondroRecords.javaindex 607cacb73..682cd64b5 100644--- a/source/de/anomic/kelondro/kelondroRecords.java+++ b/source/de/anomic/kelondro/kelondroRecords.java@@ -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 cacheString 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);diff --git a/source/de/anomic/kelondro/kelondroRowCollection.java b/source/de/anomic/kelondro/kelondroRowCollection.javaindex 760fcbd94..d24da88e3 100644--- a/source/de/anomic/kelondro/kelondroRowCollection.java+++ b/source/de/anomic/kelondro/kelondroRowCollection.java@@ -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 {