some fixes and performance hacks

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@5845 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 16 years ago
parent dfb96ecb72
commit 8ffb9889e1

@ -220,8 +220,11 @@ public class httpClient {
* (non-Javadoc) * (non-Javadoc)
* @see de.anomic.http.HttpClient#setTimeout(int) * @see de.anomic.http.HttpClient#setTimeout(int)
*/ */
public void setTimeout(final int timeout) { @SuppressWarnings("deprecation")
public void setTimeout(final int timeout) {
apacheHttpClient.getParams().setIntParameter(HttpMethodParams.SO_TIMEOUT, timeout); apacheHttpClient.getParams().setIntParameter(HttpMethodParams.SO_TIMEOUT, timeout);
apacheHttpClient.getParams().setIntParameter(HttpMethodParams.HEAD_BODY_CHECK_TIMEOUT, timeout);
apacheHttpClient.setConnectionTimeout(timeout);
} }
/** /**

@ -103,7 +103,7 @@ public class IndexTest {
hm.clear(); hm = null; hm.clear(); hm = null;
long t5 = System.currentTimeMillis(); long t5 = System.currentTimeMillis();
System.out.println("time for HashMap<String> test: " + (t5 - t4) + ", " + bugs + " bugs"); System.out.println("time for HashMap<String> test: " + (t5 - t4) + ", " + bugs + " bugs");
System.out.println("memory for HashMap<byte[]>: " + (freeStartHash - freeEndHash) / mb + " MB\n"); System.out.println("memory for HashMap<String>: " + (freeStartHash - freeEndHash) / mb + " MB\n");
// test kelondro index // test kelondro index
Runtime.getRuntime().gc(); Runtime.getRuntime().gc();

@ -46,7 +46,19 @@ import java.util.concurrent.LinkedBlockingQueue;
public class Digest { public class Digest {
public static BlockingQueue<MessageDigest> digestPool = new ArrayBlockingQueue<MessageDigest>(10);
static {
for (int i = 0; i < 10; i++)
try {
MessageDigest digest = MessageDigest.getInstance("MD5");
digest.reset();
digestPool.add(digest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
public static String encodeHex(final long in, final int length) { public static String encodeHex(final long in, final int length) {
String s = Long.toHexString(in); String s = Long.toHexString(in);
while (s.length() < length) s = "0" + s; while (s.length() < length) s = "0" + s;
@ -98,8 +110,7 @@ public class Digest {
public static byte[] encodeMD5Raw(final String key) { public static byte[] encodeMD5Raw(final String key) {
try { try {
final MessageDigest digest = MessageDigest.getInstance("MD5"); final MessageDigest digest = digestPool.take();
digest.reset();
byte[] keyBytes; byte[] keyBytes;
try { try {
keyBytes = key.getBytes("UTF-8"); keyBytes = key.getBytes("UTF-8");
@ -107,10 +118,13 @@ public class Digest {
keyBytes = key.getBytes(); keyBytes = key.getBytes();
} }
digest.update(keyBytes); digest.update(keyBytes);
return digest.digest(); byte[] result = digest.digest();
} catch (final java.security.NoSuchAlgorithmException e) { digest.reset();
System.out.println("Internal Error at md5:" + e.getMessage()); digestPool.put(digest);
} return result;
} catch (InterruptedException e) {
System.out.println("Internal Error at md5:" + e.getMessage());
}
return null; return null;
} }

@ -86,7 +86,6 @@ public class Word {
if (h != null) return h; if (h != null) return h;
h = Base64Order.enhancedCoder.encodeSubstring(Digest.encodeMD5Raw(word.toLowerCase(Locale.ENGLISH)), yacySeedDB.commonHashLength); h = Base64Order.enhancedCoder.encodeSubstring(Digest.encodeMD5Raw(word.toLowerCase(Locale.ENGLISH)), yacySeedDB.commonHashLength);
assert h[2] != '@'; assert h[2] != '@';
String s = new String(h);
hashCache.put(word, h); // prevent expensive MD5 computation and encoding hashCache.put(word, h); // prevent expensive MD5 computation and encoding
return h; return h;
} }

Loading…
Cancel
Save