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

@ -66,14 +66,16 @@ public final class ScoreCluster<E> {
* shrink the cluster to a demanded size
* @param maxsize
*/
public synchronized void shrinkToMaxSize(int maxsize) {
public void shrinkToMaxSize(int maxsize) {
if (maxsize < 0) return;
Long key;
while (refkeyDB.size() > maxsize) {
// find and remove smallest objects until cluster has demanded size
key = keyrefDB.firstKey();
if (key == null) break;
refkeyDB.remove(keyrefDB.remove(key));
synchronized (this) {
while (refkeyDB.size() > maxsize) {
// find and remove smallest objects until cluster has demanded size
key = keyrefDB.firstKey();
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
* @param minScore
*/
public synchronized void shrinkToMinScore(int minScore) {
public void shrinkToMinScore(int minScore) {
int score;
Long key;
while (keyrefDB.size() > 0) {
// find and remove objects where their score is smaller than the demanded minimum score
key = keyrefDB.firstKey();
if (key == null) break;
score = (int) ((key.longValue() & 0xFFFFFFFF00000000L) >> 32);
if (score >= minScore) break;
refkeyDB.remove(keyrefDB.remove(key));
synchronized (this) {
while (keyrefDB.size() > 0) {
// find and remove objects where their score is smaller than the demanded minimum score
key = keyrefDB.firstKey();
if (key == null) break;
score = (int) ((key.longValue() & 0xFFFFFFFF00000000L) >> 32);
if (score >= minScore) break;
refkeyDB.remove(keyrefDB.remove(key));
}
}
}
@ -197,36 +201,36 @@ public final class ScoreCluster<E> {
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;
//System.out.println("setScore " + obj.getClass().getName());
Long usk = refkeyDB.remove(obj); // get unique score key, old entry is not needed any more
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;
synchronized (this) {
Long usk = refkeyDB.remove(obj); // get unique score key, old entry is not needed any more
if (newScore < 0) throw new kelondroOutOfLimitsException(newScore);
// 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);
}
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
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
gcount += newScore;
}
@ -266,15 +270,17 @@ public final class ScoreCluster<E> {
gcount += incrementScore;
}
public synchronized int deleteScore(final E obj) {
public int deleteScore(final E obj) {
// deletes entry and returns previous score
if (obj == null) return 0;
//System.out.println("setScore " + obj.getClass().getName());
final Long 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);
final Long usk;
synchronized (this) {
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);
}
// get previous handle and score
final int oldScore = (int) ((usk.longValue() & 0xFFFFFFFF00000000L) >> 32);
@ -289,9 +295,12 @@ public final class ScoreCluster<E> {
return (refkeyDB.get(obj) != null);
}
public synchronized int getScore(final E obj) {
public int getScore(final E obj) {
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;
return (int) ((cs.longValue() & 0xFFFFFFFF00000000L) >> 32);
}

Loading…
Cancel
Save