more performance hacks

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7148 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 15 years ago
parent 39f409a7bb
commit 14c843d364

@ -173,7 +173,6 @@ public final class RankingProcess extends Thread {
timer = System.currentTimeMillis(); timer = System.currentTimeMillis();
String domhash; String domhash;
boolean nav_hosts = this.query.navigators.equals("all") || this.query.navigators.indexOf("hosts") >= 0; boolean nav_hosts = this.query.navigators.equals("all") || this.query.navigators.indexOf("hosts") >= 0;
final ArrayList<WordReferenceVars> filteredEntries = new ArrayList<WordReferenceVars>();
// apply all constraints // apply all constraints
try { try {
@ -222,24 +221,18 @@ public final class RankingProcess extends Thread {
this.hostNavigator.inc(domhash, uhb); this.hostNavigator.inc(domhash, uhb);
} }
// accept // accept; insert to ranked stack with double-check
filteredEntries.add(iEntry);
// increase counter for statistics
if (local) this.local_indexCount++; else this.remote_indexCount++;
}
// do the ranking
for (WordReferenceVars fEntry: filteredEntries) {
// insert with double-check
try { try {
if (!urlhashes.put(fEntry.metadataHash())) { if (!urlhashes.put(iEntry.metadataHash())) {
stack.put(new ReverseElement<WordReferenceVars>(fEntry, this.order.cardinal(fEntry))); // inserts the element and removes the worst (which is smallest) stack.put(new ReverseElement<WordReferenceVars>(iEntry, this.order.cardinal(iEntry))); // inserts the element and removes the worst (which is smallest)
} }
} catch (RowSpaceExceededException e) { } catch (RowSpaceExceededException e) {
Log.logException(e); Log.logException(e);
} }
}
// increase counter for statistics
if (local) this.local_indexCount++; else this.remote_indexCount++;
}
} catch (InterruptedException e) {} } catch (InterruptedException e) {}

@ -66,14 +66,16 @@ public final class ScoreCluster<E> {
* shrink the cluster to a demanded size * shrink the cluster to a demanded size
* @param maxsize * @param maxsize
*/ */
public synchronized void shrinkToMaxSize(int maxsize) { public void shrinkToMaxSize(int maxsize) {
if (maxsize < 0) return; if (maxsize < 0) return;
Long key; Long key;
while (refkeyDB.size() > maxsize) { synchronized (this) {
// find and remove smallest objects until cluster has demanded size while (refkeyDB.size() > maxsize) {
key = keyrefDB.firstKey(); // find and remove smallest objects until cluster has demanded size
if (key == null) break; key = keyrefDB.firstKey();
refkeyDB.remove(keyrefDB.remove(key)); if (key == null) break;
refkeyDB.remove(keyrefDB.remove(key));
}
} }
} }
@ -81,16 +83,18 @@ public final class ScoreCluster<E> {
* shrink the cluster in such a way that the smallest score is equal or greater than a given minScore * shrink the cluster in such a way that the smallest score is equal or greater than a given minScore
* @param minScore * @param minScore
*/ */
public synchronized void shrinkToMinScore(int minScore) { public void shrinkToMinScore(int minScore) {
int score; int score;
Long key; Long key;
while (keyrefDB.size() > 0) { synchronized (this) {
// find and remove objects where their score is smaller than the demanded minimum score while (keyrefDB.size() > 0) {
key = keyrefDB.firstKey(); // find and remove objects where their score is smaller than the demanded minimum score
if (key == null) break; key = keyrefDB.firstKey();
score = (int) ((key.longValue() & 0xFFFFFFFF00000000L) >> 32); if (key == null) break;
if (score >= minScore) break; score = (int) ((key.longValue() & 0xFFFFFFFF00000000L) >> 32);
refkeyDB.remove(keyrefDB.remove(key)); if (score >= minScore) break;
refkeyDB.remove(keyrefDB.remove(key));
}
} }
} }
@ -197,36 +201,36 @@ public final class ScoreCluster<E> {
addScore(obj, -1); addScore(obj, -1);
} }
public synchronized void setScore(final E obj, final int newScore) { public void setScore(final E obj, final int newScore) {
if (obj == null) return; if (obj == null) return;
//System.out.println("setScore " + obj.getClass().getName()); synchronized (this) {
Long usk = refkeyDB.remove(obj); // get unique score key, old entry is not needed any more Long usk = refkeyDB.remove(obj); // get unique score key, old entry is not needed any more
if (newScore < 0) throw new kelondroOutOfLimitsException(newScore); if (newScore < 0) throw new kelondroOutOfLimitsException(newScore);
if (usk == null) {
// set new value
usk = Long.valueOf(scoreKey(encnt++, newScore));
// put new value into cluster
refkeyDB.put(obj, usk);
keyrefDB.put(usk, obj);
} else {
// delete old entry
keyrefDB.remove(usk);
// get previous handle and score
final long c = usk.longValue();
final int oldScore = (int) ((c & 0xFFFFFFFF00000000L) >> 32);
final int oldHandle = (int) (c & 0xFFFFFFFFL);
gcount -= oldScore;
// set new value if (usk == null) {
usk = Long.valueOf(scoreKey(oldHandle, newScore)); // generates an unique key for a specific score // set new value
refkeyDB.put(obj, usk); usk = Long.valueOf(scoreKey(encnt++, newScore));
keyrefDB.put(usk, obj);
} // put new value into cluster
refkeyDB.put(obj, usk);
keyrefDB.put(usk, obj);
} else {
// delete old entry
keyrefDB.remove(usk);
// get previous handle and score
final long c = usk.longValue();
final int oldScore = (int) ((c & 0xFFFFFFFF00000000L) >> 32);
final int oldHandle = (int) (c & 0xFFFFFFFFL);
gcount -= oldScore;
// set new value
usk = Long.valueOf(scoreKey(oldHandle, newScore)); // generates an unique key for a specific score
refkeyDB.put(obj, usk);
keyrefDB.put(usk, obj);
}
}
// increase overall counter // increase overall counter
gcount += newScore; gcount += newScore;
} }
@ -266,15 +270,17 @@ public final class ScoreCluster<E> {
gcount += incrementScore; gcount += incrementScore;
} }
public synchronized int deleteScore(final E obj) { public int deleteScore(final E obj) {
// deletes entry and returns previous score // deletes entry and returns previous score
if (obj == null) return 0; if (obj == null) return 0;
//System.out.println("setScore " + obj.getClass().getName()); final Long usk;
final Long usk = refkeyDB.remove(obj); // get unique score key, old entry is not needed any more synchronized (this) {
if (usk == null) return 0; usk = refkeyDB.remove(obj); // get unique score key, old entry is not needed any more
if (usk == null) return 0;
// delete old entry
keyrefDB.remove(usk); // delete old entry
keyrefDB.remove(usk);
}
// get previous handle and score // get previous handle and score
final int oldScore = (int) ((usk.longValue() & 0xFFFFFFFF00000000L) >> 32); final int oldScore = (int) ((usk.longValue() & 0xFFFFFFFF00000000L) >> 32);
@ -289,9 +295,12 @@ public final class ScoreCluster<E> {
return (refkeyDB.get(obj) != null); return (refkeyDB.get(obj) != null);
} }
public synchronized int getScore(final E obj) { public int getScore(final E obj) {
if (obj == null) return 0; if (obj == null) return 0;
final Long cs = refkeyDB.get(obj); final Long cs;
synchronized (this) {
cs = refkeyDB.get(obj);
}
if (cs == null) return 0; if (cs == null) return 0;
return (int) ((cs.longValue() & 0xFFFFFFFF00000000L) >> 32); return (int) ((cs.longValue() & 0xFFFFFFFF00000000L) >> 32);
} }

Loading…
Cancel
Save