From 09ba6814c0e6e126180482c66e9cb8a6b5f5bd46 Mon Sep 17 00:00:00 2001 From: orbiter Date: Thu, 26 May 2011 12:58:11 +0000 Subject: [PATCH] - non-blocking word hash computation with dynamic digest object generation (this was important!) - (very) small performance enhancement in did-you-mean git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@7740 6c8d7289-2bf4-0310-a012-ef5d649a1542 --- source/de/anomic/data/DidYouMean.java | 2 +- source/net/yacy/kelondro/order/Digest.java | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/source/de/anomic/data/DidYouMean.java b/source/de/anomic/data/DidYouMean.java index 12defa1b9..366610314 100644 --- a/source/de/anomic/data/DidYouMean.java +++ b/source/de/anomic/data/DidYouMean.java @@ -356,7 +356,7 @@ public class DidYouMean { public void run() { String s; try { - while (!(s = guessLib.take()).equals(POISON_STRING)) { + while ((s = guessLib.take()) != POISON_STRING) { if (s.length() >= MinimumOutputWordLength && index.has(Word.word2hash(s))) resultSet.add(s); if (System.currentTimeMillis() > timeLimit) return; } diff --git a/source/net/yacy/kelondro/order/Digest.java b/source/net/yacy/kelondro/order/Digest.java index 4d5dc592b..1958252ad 100644 --- a/source/net/yacy/kelondro/order/Digest.java +++ b/source/net/yacy/kelondro/order/Digest.java @@ -50,7 +50,7 @@ import net.yacy.kelondro.logging.Log; public class Digest { - private final static int digestThreads = Runtime.getRuntime().availableProcessors() * 2 + 1; + private final static int digestThreads = Runtime.getRuntime().availableProcessors() * 4; public static BlockingQueue digestPool = new ArrayBlockingQueue(digestThreads); static { for (int i = 0; i < digestThreads; i++) @@ -115,7 +115,17 @@ public class Digest { public static byte[] encodeMD5Raw(final String key) { MessageDigest digest = null; boolean fromPool = true; - try { + if (digestPool.size() == 0) { + // if there are no digest objects left, create some on the fly + // this is not the most effective way but if we wouldn't do that the encoder would block + try { + digest = MessageDigest.getInstance("MD5"); + digest.reset(); + fromPool = false; + } catch (NoSuchAlgorithmException e) { + } + } + if (digest == null) try { digest = digestPool.take(); } catch (InterruptedException e) { Log.logWarning("Digest", "using generic instead of pooled digest");