more performance hacks

git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4676 6c8d7289-2bf4-0310-a012-ef5d649a1542
pull/1/head
orbiter 17 years ago
parent 2c2dcd12a2
commit 444dce7e81

@ -177,6 +177,7 @@ public class IndexCreateIndexingQueue_p {
int j=0; int j=0;
for (int i = switchboard.crawlQueues.errorURL.stackSize() - 1; i >= (switchboard.crawlQueues.errorURL.stackSize() - showRejectedCount); i--) { for (int i = switchboard.crawlQueues.errorURL.stackSize() - 1; i >= (switchboard.crawlQueues.errorURL.stackSize() - showRejectedCount); i--) {
entry = switchboard.crawlQueues.errorURL.top(i); entry = switchboard.crawlQueues.errorURL.top(i);
if (entry == null) continue;
url = entry.url(); url = entry.url();
if (url == null) continue; if (url == null) continue;

@ -27,12 +27,12 @@ package de.anomic.http;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.io.OutputStreamWriter; import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.io.Writer;
import de.anomic.server.serverFileUtils; import de.anomic.server.serverFileUtils;
@ -103,8 +103,7 @@ public interface HttpResponse {
* @throws IOException * @throws IOException
* @throws UnsupportedEncodingException * @throws UnsupportedEncodingException
*/ */
public static void writeContent(HttpResponse res, BufferedOutputStream hfos, BufferedOutputStream byteStream) throws IOException, public static void writeContent(HttpResponse res, BufferedOutputStream hfos, BufferedOutputStream byteStream) throws IOException, UnsupportedEncodingException {
UnsupportedEncodingException {
try { try {
InputStream data = res.getDataAsStream(); InputStream data = res.getDataAsStream();
if (byteStream == null) { if (byteStream == null) {
@ -112,21 +111,20 @@ public interface HttpResponse {
} else { } else {
serverFileUtils.copyToStreams(new BufferedInputStream(data), hfos, byteStream); serverFileUtils.copyToStreams(new BufferedInputStream(data), hfos, byteStream);
} }
} finally { } finally {
res.closeStream(); res.closeStream();
} }
} }
public static void writeContent(HttpResponse res, Writer hfos, OutputStream byteStream) throws IOException, public static void writeContent(HttpResponse res, BufferedWriter hfos, OutputStream byteStream) throws IOException, UnsupportedEncodingException {
UnsupportedEncodingException {
try { try {
InputStream data = res.getDataAsStream(); InputStream data = res.getDataAsStream();
String charSet = httpHeader.getCharSet(res.getResponseHeader()); String charSet = httpHeader.getCharSet(res.getResponseHeader());
Writer[] writers = (byteStream == null ? new Writer[] { hfos } : new Writer[] { hfos, if (byteStream == null) {
new OutputStreamWriter(byteStream, charSet) }); serverFileUtils.copyToWriter(new BufferedInputStream(data), hfos, charSet);
serverFileUtils.copyToWriters(data, writers, charSet); } else {
serverFileUtils.copyToWriters(new BufferedInputStream(data), hfos, new BufferedWriter(new OutputStreamWriter(byteStream, charSet)) , charSet);
}
} finally { } finally {
res.closeStream(); res.closeStream();
} }

@ -283,9 +283,6 @@ public final class httpTemplate {
num=0; num=0;
} }
//System.out.println(multi_key + ": " + num); //DEBUG //System.out.println(multi_key + ": " + num); //DEBUG
}else{
//0 interations - no display
//System.out.println("_"+new String(multi_key)+" is null or does not exist"); //DEBUG
} }
//Enumeration enx = pattern.keys(); while (enx.hasMoreElements()) System.out.println("KEY=" + enx.nextElement()); // DEBUG //Enumeration enx = pattern.keys(); while (enx.hasMoreElements()) System.out.println("KEY=" + enx.nextElement()); // DEBUG
@ -336,8 +333,6 @@ public final class httpTemplate {
byName=true; byName=true;
patternName=patternId.getBytes("UTF-8"); patternName=patternId.getBytes("UTF-8");
} }
}else{
//System.out.println("Pattern \""+new String(prefix + key)+"\" is not set"); //DEBUG
} }
int currentPattern=0; int currentPattern=0;

@ -64,6 +64,7 @@ package de.anomic.http;
import java.io.BufferedOutputStream; import java.io.BufferedOutputStream;
import java.io.BufferedReader; import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.io.File; import java.io.File;
@ -634,7 +635,7 @@ public final class httpdProxyHandler {
{ {
// ok, we don't write actually into a file, only to RAM, and schedule writing the file. // ok, we don't write actually into a file, only to RAM, and schedule writing the file.
ByteArrayOutputStream byteStream = new ByteArrayOutputStream(); ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
Saver.writeContent(res, hfos, byteStream); Saver.writeContent(res, new BufferedWriter(hfos), byteStream);
// cached bytes // cached bytes
byte[] cacheArray; byte[] cacheArray;
if(byteStream.size() > 0) { if(byteStream.size() > 0) {
@ -669,7 +670,7 @@ public final class httpdProxyHandler {
// the file is too big to cache it in the ram, or the size is unknown // the file is too big to cache it in the ram, or the size is unknown
// write to file right here. // write to file right here.
cacheFile.getParentFile().mkdirs(); cacheFile.getParentFile().mkdirs();
Saver.writeContent(res, hfos, new FileOutputStream(cacheFile)); Saver.writeContent(res, new BufferedWriter(hfos), new FileOutputStream(cacheFile));
if (hfos instanceof htmlFilterWriter) ((htmlFilterWriter) hfos).finalize(); if (hfos instanceof htmlFilterWriter) ((htmlFilterWriter) hfos).finalize();
theLogger.logFine("for write-file of " + url + ": contentLength = " + contentLength + ", sizeBeforeDelete = " + sizeBeforeDelete); theLogger.logFine("for write-file of " + url + ": contentLength = " + contentLength + ", sizeBeforeDelete = " + sizeBeforeDelete);
plasmaHTCache.writeFileAnnouncement(cacheFile); plasmaHTCache.writeFileAnnouncement(cacheFile);
@ -699,7 +700,7 @@ public final class httpdProxyHandler {
" StoreHTCache=" + storeHTCache + " StoreHTCache=" + storeHTCache +
" SupportetContent=" + isSupportedContent); " SupportetContent=" + isSupportedContent);
Saver.writeContent(res, hfos, null); Saver.writeContent(res, new BufferedWriter(hfos), null);
if (hfos instanceof htmlFilterWriter) ((htmlFilterWriter) hfos).finalize(); if (hfos instanceof htmlFilterWriter) ((htmlFilterWriter) hfos).finalize();
if (sizeBeforeDelete == -1) { if (sizeBeforeDelete == -1) {
// no old file and no load. just data passing // no old file and no load. just data passing

@ -95,7 +95,7 @@ public class kelondroLock {
if (locked()) { if (locked()) {
lock = false; lock = false;
releaseTime = 0; releaseTime = 0;
notify(); notifyAll();
} }
} }

@ -145,7 +145,7 @@ public final class kelondroStack extends kelondroFullRecords {
} }
} }
public int size() { public synchronized int size() {
return super.size(); return super.size();
} }

@ -562,34 +562,36 @@ public final class serverFileUtils {
* @return * @return
* @throws IOException * @throws IOException
*/ */
public static int copyToWriters(final InputStream data, final Writer[] writers, final String charSet) throws IOException { public static int copyToWriter(final BufferedInputStream data, final BufferedWriter writer, final String charSet) throws IOException {
// the docs say: "For top efficiency, consider wrapping an InputStreamReader within a BufferedReader." // the docs say: "For top efficiency, consider wrapping an InputStreamReader within a BufferedReader."
final BufferedReader sourceReader = new BufferedReader(new InputStreamReader(data, charSet)); final Reader sourceReader = new InputStreamReader(data, charSet);
// check if buffer is used. From the documentation: int count = 0;
// "For top efficiency, consider wrapping an OutputStreamWriter within a BufferedWriter so as to avoid frequent // copy bytes
// converter invocations" int b;
int i = 0; while((b = sourceReader.read()) != -1) {
for(final Writer writer: writers) { count++;
if (!(writer instanceof BufferedWriter)) { writer.write(b);
// add buffer
writers[i] = new BufferedWriter(writer);
}
i++;
} }
writer.flush();
return count;
}
public static int copyToWriters(final BufferedInputStream data, final BufferedWriter writer0, final BufferedWriter writer1, final String charSet) throws IOException {
// the docs say: "For top efficiency, consider wrapping an InputStreamReader within a BufferedReader."
assert writer0 != null;
assert writer1 != null;
final Reader sourceReader = new InputStreamReader(data, charSet);
int count = 0; int count = 0;
// copy bytes // copy bytes
int b; int b;
while((b = sourceReader.read()) != -1) { while((b = sourceReader.read()) != -1) {
count++; count++;
for(final Writer writer: writers) { writer0.write(b);
writer.write(b); writer1.write(b);
}
}
for(final Writer writer: writers) {
writer.flush();
} }
writer0.flush();
writer1.flush();
return count; return count;
} }
} }

Loading…
Cancel
Save