From 4f45605f04a36e379aa315202cb72f4d5b2e040c Mon Sep 17 00:00:00 2001 From: orbiter Date: Fri, 9 Jan 2009 15:28:45 +0000 Subject: [PATCH] small update for timing in search result processing git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5460 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- htroot/yacysearchitem.java | 2 -- .../de/anomic/plasma/plasmaSearchEvent.java | 36 ++++++++++++++----- 2 files changed, 28 insertions(+), 10 deletions(-) diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.java index a50d7c77c..14c6a42c3 100644 --- a/htroot/yacysearchitem.java +++ b/htroot/yacysearchitem.java @@ -88,8 +88,6 @@ public class yacysearchitem { prop.put("remoteResourceSize", yFormatter.number(theSearch.getRankingResult().getRemoteResourceSize(), true)); prop.put("remoteIndexCount", yFormatter.number(theSearch.getRankingResult().getRemoteIndexCount(), true)); prop.put("remotePeerCount", yFormatter.number(theSearch.getRankingResult().getRemotePeerCount(), true)); - - prop.put("rss", "0"); if (theQuery.contentdom == plasmaSearchQuery.CONTENTDOM_TEXT) { // text search diff --git a/source/de/anomic/plasma/plasmaSearchEvent.java b/source/de/anomic/plasma/plasmaSearchEvent.java index 656674888..cce8e1738 100644 --- a/source/de/anomic/plasma/plasmaSearchEvent.java +++ b/source/de/anomic/plasma/plasmaSearchEvent.java @@ -200,7 +200,7 @@ public final class plasmaSearchEvent { // start worker threads to fetch urls and snippets this.workerThreads = new resultWorker[workerThreadCount]; for (int i = 0; i < workerThreadCount; i++) { - this.workerThreads[i] = new resultWorker(i, 6000, 2); + this.workerThreads[i] = new resultWorker(i, 10000, 2); this.workerThreads[i].start(); } serverProfiling.update("SEARCH", new plasmaProfiling.searchEvent(query.id(true), "online snippet fetch threads started", 0, 0)); @@ -375,6 +375,15 @@ public final class plasmaSearchEvent { return false; } + private int countWorkerFinished() { + if (this.workerThreads == null) return 0; + int c = 0; + for (int i = 0; i < workerThreadCount; i++) { + if (this.workerThreads[i] == null || !this.workerThreads[i].isAlive()) c++; + } + return c; + } + boolean anyRemoteSearchAlive() { // check primary search threads if ((this.primarySearchThreads != null) && (this.primarySearchThreads.length != 0)) { @@ -547,6 +556,10 @@ public final class plasmaSearchEvent { } public ResultEntry oneResult(final int item) { + return oneResult(item, System.currentTimeMillis() + 100); + } + + public ResultEntry oneResult(final int item, long timeout) { // check if we already retrieved this item (happens if a search pages is accessed a second time) serverProfiling.update("SEARCH", new plasmaProfiling.searchEvent(query.id(true), "obtain one result entry - start", 0, 0)); if (this.result.sizeStore() > item) { @@ -557,21 +570,28 @@ public final class plasmaSearchEvent { if ((query.domType == plasmaSearchQuery.SEARCHDOM_GLOBALDHT) || (query.domType == plasmaSearchQuery.SEARCHDOM_CLUSTERALL)) { // this is a search using remote search threads. Also the local search thread is started as background process - if ((localSearchThread != null) && (localSearchThread.isAlive())) { + while ( + localSearchThread != null && + localSearchThread.isAlive() && + System.currentTimeMillis() < timeout) { // in case that the local search takes longer than some other remote search requests, // do some sleeps to give the local process a chance to contribute - try {Thread.sleep(item * 100L);} catch (final InterruptedException e) {} + try {Thread.sleep(10);} catch (final InterruptedException e) {} } // now wait until as many remote worker threads have finished, as we want to display results - while ((this.primarySearchThreads != null) && (this.primarySearchThreads.length > item) && (anyWorkerAlive()) && - ((result.size() <= item) || (countFinishedRemoteSearch() <= item))) { - try {Thread.sleep(100);} catch (final InterruptedException e) {} + while ( + this.primarySearchThreads != null && + anyWorkerAlive() && + countWorkerFinished() <= item && + System.currentTimeMillis() < timeout && + (result.size() <= item || countFinishedRemoteSearch() <= item)) { + try {Thread.sleep(10);} catch (final InterruptedException e) {} } } // finally wait until enough results are there produced from the snippet fetch process - while ((anyWorkerAlive()) && (result.size() <= item)) { - try {Thread.sleep(100);} catch (final InterruptedException e) {} + while (anyWorkerAlive() && result.size() <= item) { + try {Thread.sleep(10);} catch (final InterruptedException e) {} } // finally, if there is something, return the result