Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
- better synchronization in SortStack - better ThreadGroup organization - less worker threads for media search (64 was too much...)
orbiter23aef4378690
diff --git a/htroot/yacysearchitem.java b/htroot/yacysearchitem.javaindex d8d4c99af..5aefe32c0 100644--- a/htroot/yacysearchitem.java+++ b/htroot/yacysearchitem.java@@ -215,7 +215,7 @@ public class yacysearchitem {if (s.length() <= length) return s;final int p = s.lastIndexOf('.');if (p < 0) return s.substring(0, length - 3) + "...";- return s.substring(0, length - (s.length() - p) - 3) + "..." + s.substring(p);+ return s.substring(0, length - (s.length() - p) - 3) + "..." + s.substring(p); // TODO check oob}private static String sizename(int size) {diff --git a/source/de/anomic/search/DocumentIndex.java b/source/de/anomic/search/DocumentIndex.javaindex c8cf45ebf..831d76f81 100644--- a/source/de/anomic/search/DocumentIndex.java+++ b/source/de/anomic/search/DocumentIndex.java@@ -57,6 +57,8 @@ public class DocumentIndex extends Segment {private BlockingQueue<File> queue;private Worker[] worker;private CallbackListener callback;++ private static final ThreadGroup workerThreadGroup = new ThreadGroup("workerThreadGroup");public DocumentIndex(Log log, final File segmentPath, CallbackListener callback, int cachesize) throws IOException {super(log, segmentPath, cachesize, targetFileSize * 4 - 1, false, false);@@ -65,7 +67,7 @@ public class DocumentIndex extends Segment {this.queue = new LinkedBlockingQueue<File>(cores * 300);this.worker = new Worker[cores];for (int i = 0; i < cores; i++) {- this.worker[i] = new Worker();+ this.worker[i] = new Worker(i);this.worker[i].start();}}@@ -75,6 +77,10 @@ public class DocumentIndex extends Segment {}class Worker extends Thread {+ public Worker(int count) {+ super(workerThreadGroup, "query-" + count);+ }+public void run() {File f;URIMetadataRow resultRow;diff --git a/source/de/anomic/search/RankingProcess.java b/source/de/anomic/search/RankingProcess.javaindex b373fea41..acdfc415d 100644--- a/source/de/anomic/search/RankingProcess.java+++ b/source/de/anomic/search/RankingProcess.java@@ -245,6 +245,7 @@ public final class RankingProcess extends Thread {// kick out entries that are too bad according to current findingsr = Long.valueOf(order.cardinal(fEntry));+ assert maxentries != 0;if ((maxentries >= 0) && (stack.size() >= maxentries) && (stack.bottom(r.longValue()))) continue;// insertdiff --git a/source/de/anomic/search/ResultFetcher.java b/source/de/anomic/search/ResultFetcher.javaindex 56d2f4fd8..0a5f3dab1 100644--- a/source/de/anomic/search/ResultFetcher.java+++ b/source/de/anomic/search/ResultFetcher.java@@ -97,7 +97,7 @@ public class ResultFetcher {// start worker threads to fetch urls and snippetsthis.workerThreads = null;- deployWorker(query.itemsPerPage, query.neededResults());+ deployWorker(Math.min(10, query.itemsPerPage), query.neededResults());MemoryTracker.update("SEARCH", new ProfilingGraph.searchEvent(query.id(true), this.workerThreads.length + " online snippet fetch threads started", 0, 0), false);}@@ -302,7 +302,7 @@ public class ResultFetcher {(this.rankedCache.size() > this.result.size())) {// start worker threads to fetch urls and snippets- deployWorker(query.itemsPerPage, query.neededResults());+ deployWorker(Math.min(10, query.itemsPerPage), query.neededResults());}// finally wait until enough results are there produced from thediff --git a/source/de/anomic/server/serverCore.java b/source/de/anomic/server/serverCore.javaindex b8eb717fd..706c0bec1 100644--- a/source/de/anomic/server/serverCore.java+++ b/source/de/anomic/server/serverCore.java@@ -443,7 +443,7 @@ public final class serverCore extends AbstractBusyThread implements BusyThread {public List<Session> getJobList() {final Thread[] threadList = new Thread[sessionThreadGroup.activeCount()];- serverCore.sessionThreadGroup.enumerate(threadList);+ serverCore.sessionThreadGroup.enumerate(threadList, false);ArrayList<Session> l = new ArrayList<Session>();for (Thread t: threadList) {if (t == null) continue;diff --git a/source/de/anomic/yacy/yacySearch.java b/source/de/anomic/yacy/yacySearch.javaindex 9c7042c4a..63da5771e 100644--- a/source/de/anomic/yacy/yacySearch.java+++ b/source/de/anomic/yacy/yacySearch.java@@ -45,6 +45,8 @@ import de.anomic.yacy.dht.PeerSelection;public class yacySearch extends Thread {+ private static final ThreadGroup ysThreadGroup = new ThreadGroup("yacySearchThreadGroup");+final private String wordhashes, excludehashes, urlhashes, sitehash, authorhash;final private boolean global;final private int partitions;@@ -79,7 +81,7 @@ public class yacySearch extends Thread {final Blacklist blacklist,final RankingProfile rankingProfile,final Bitfield constraint) {- super("yacySearch_" + targetPeer.getName());+ super(ysThreadGroup, "yacySearch_" + targetPeer.getName());//System.out.println("DEBUG - yacySearch thread " + this.getName() + " initialized " + ((urlhashes.length() == 0) ? "(primary)" : "(secondary)"));assert wordhashes.length() >= 12;this.wordhashes = wordhashes;diff --git a/source/net/yacy/kelondro/util/SortStack.java b/source/net/yacy/kelondro/util/SortStack.javaindex ab1b83eee..259d756de 100644--- a/source/net/yacy/kelondro/util/SortStack.java+++ b/source/net/yacy/kelondro/util/SortStack.java@@ -26,28 +26,29 @@package net.yacy.kelondro.util;-import java.util.HashSet;import java.util.Iterator;import java.util.LinkedList;import java.util.List;import java.util.Map;import java.util.TreeMap;+import java.util.concurrent.ConcurrentHashMap;public class SortStack<E> {// implements a stack where elements 'float' on-top of the stack according to a weight value.// objects pushed on the stack must implement the hashCode() method to provide a handle// for a double-check.-++ private static final Object PRESENT = new Object(); // Dummy value to associate with an Object in the backing Mapprivate TreeMap<Long, List<E>> onstack; // object within the stack- private HashSet<E> instack; // keeps track which element has been on the stack+ private ConcurrentHashMap<E, Object> instack; // keeps track which element has been on the stackprotected int maxsize;public SortStack(final int maxsize) {// the maxsize is the maximum number of entries in the stack// if this is set to -1, the size is unlimitedthis.onstack = new TreeMap<Long, List<E>>();- this.instack = new HashSet<E>();+ this.instack = new ConcurrentHashMap<E, Object>();this.maxsize = maxsize;}@@ -61,7 +62,7 @@ public class SortStack<E> {* @param weight*/public void push(final E element, Long weight) {- if (!this.instack.add(element)) return;+ if (this.instack.put(element, PRESENT) != null) return;// put the element on the stacksynchronized (this.onstack) {@@ -147,6 +148,7 @@ public class SortStack<E> {public boolean bottom(final long weight) {// returns true if the element with that weight would be on the bottom of the stack after inserting+ if (this.onstack.size() == 0) return true;Long l;synchronized (this.onstack) {l = this.onstack.lastKey();diff --git a/source/net/yacy/kelondro/util/SortStore.java b/source/net/yacy/kelondro/util/SortStore.javaindex f37bd2606..8328691db 100644--- a/source/net/yacy/kelondro/util/SortStore.java+++ b/source/net/yacy/kelondro/util/SortStore.java@@ -27,8 +27,8 @@package net.yacy.kelondro.util;import java.util.ArrayList;-import java.util.HashSet;import java.util.Iterator;+import java.util.concurrent.ConcurrentHashMap;/*** extends the sortStack in such a way that it adds a list where objects, that had@@ -38,8 +38,9 @@ import java.util.Iterator;*/public class SortStore<E> extends SortStack<E> {+ private static final Object PRESENT = new Object(); // Dummy value to associate with an Object in the backing Mapprivate final ArrayList<stackElement> offstack; // objects that had been on the stack but had been removed- private HashSet<E> offset; // keeps track which element has been on the stack or is now in the offstack+ private ConcurrentHashMap<E, Object> offset; // keeps track which element has been on the stack or is now in the offstackprivate long largest;public SortStore() {@@ -50,7 +51,7 @@ public class SortStore<E> extends SortStack<E> {super(maxsize);this.largest = Long.MIN_VALUE;this.offstack = new ArrayList<stackElement>();- this.offset = new HashSet<E>();+ this.offset = new ConcurrentHashMap<E, Object>();}public int size() {@@ -61,8 +62,9 @@ public class SortStore<E> extends SortStack<E> {return this.offstack.size();}- public synchronized void push(final E element, final Long weight) {- if (this.offset.contains(element)) return;+ public void push(final E element, final Long weight) {+ if (this.offset.containsKey(element)) return;+ if (super.exists(element)) return;super.push(element, weight);this.largest = Math.max(this.largest, weight.longValue());if (this.maxsize <= 0) return;@@ -76,21 +78,20 @@ public class SortStore<E> extends SortStack<E> {* it is removed and added to the offstack list* this is exactly the same as element(offstack.size())*/- public synchronized stackElement pop() {+ public stackElement pop() {final stackElement se = super.pop();if (se == null) return null;+ this.offset.put(se.element, PRESENT);this.offstack.add(se);- this.offset.add(se.element);return se;}- public synchronized stackElement top() {+ public stackElement top() {return super.top();}- public synchronized boolean exists(final E element) {- if (super.exists(element)) return true;- return this.offset.contains(element);+ public boolean exists(final E element) {+ return super.exists(element) || this.offset.containsKey(element);}/**@@ -100,11 +101,11 @@ public class SortStore<E> extends SortStack<E> {* @param position* @return*/- public synchronized stackElement element(final int position) {+ public stackElement element(final int position) {if (position < this.offstack.size()) {return this.offstack.get(position);}- if (position >= size()) return null; // we don't have that element+ if (position >= super.size() + this.offstack.size()) return null; // we don't have that elementwhile (position >= this.offstack.size()) this.pop();return this.offstack.get(position);}@@ -116,24 +117,26 @@ public class SortStore<E> extends SortStack<E> {* @param count* @return*/- public synchronized ArrayList<stackElement> list(final int count) {+ public ArrayList<stackElement> list(final int count) {if (count < 0) {// shift all elements- while (super.size() > 0) this.offstack.add(this.pop());+ while (super.size() > 0) this.pop();return this.offstack;}- if (size() < count) throw new RuntimeException("list(" + count + ") exceeded avaiable number of elements (" + size() + ")");- while (this.offstack.size() < count) this.offstack.add(this.pop());+ if (count > super.size() + this.offstack.size()) throw new RuntimeException("list(" + count + ") exceeded avaiable number of elements (" + size() + ")");+ while (count > this.offstack.size()) this.pop();return this.offstack;}- public synchronized void remove(final E element) {+ public void remove(final E element) {super.remove(element);+ synchronized (this.offstack) {Iterator<stackElement> i = this.offstack.iterator();- while (i.hasNext()) {- if (i.next().element.equals(element)) {- i.remove();- return;+ while (i.hasNext()) {+ if (i.next().element.equals(element)) {+ i.remove();+ return;+ }}}}@@ -150,12 +153,6 @@ public class SortStore<E> extends SortStack<E> {a.push("abc", 2L);a.push("6s_7dfZk4xvc", 1L);a.push("6s_7dfZk4xvc", 1L);- a.push("6s_7dfZk4xvc", 1L);- a.push("6s_7dfZk4xvc", 1L);- a.push("6s_7dfZk4xvc", 1L);- a.push("6s_7dfZk4xvc", 1L);- a.push("6s_7dfZk4xvc", 1L);- a.push("6s_7dfZk4xvc", 1L);a.pop();System.out.println("size = " + a.size());}