Skip to content

Commit

Permalink
more performance hacks
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@4676 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
orbiter committed Apr 10, 2008
1 parent 2c2dcd1 commit 444dce7
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 38 deletions.
1 change: 1 addition & 0 deletions htroot/IndexCreateIndexingQueue_p.java
Expand Up @@ -177,6 +177,7 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve
int j=0;
for (int i = switchboard.crawlQueues.errorURL.stackSize() - 1; i >= (switchboard.crawlQueues.errorURL.stackSize() - showRejectedCount); i--) {
entry = switchboard.crawlQueues.errorURL.top(i);
if (entry == null) continue;
url = entry.url();
if (url == null) continue;

Expand Down
18 changes: 8 additions & 10 deletions source/de/anomic/http/HttpResponse.java
Expand Up @@ -27,12 +27,12 @@

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.io.Writer;

import de.anomic.server.serverFileUtils;

Expand Down Expand Up @@ -103,30 +103,28 @@ public static class Saver {
* @throws IOException
* @throws UnsupportedEncodingException
*/
public static void writeContent(HttpResponse res, BufferedOutputStream hfos, BufferedOutputStream byteStream) throws IOException,
UnsupportedEncodingException {
public static void writeContent(HttpResponse res, BufferedOutputStream hfos, BufferedOutputStream byteStream) throws IOException, UnsupportedEncodingException {
try {
InputStream data = res.getDataAsStream();
if (byteStream == null) {
serverFileUtils.copyToStream(new BufferedInputStream(data), hfos);
} else {
serverFileUtils.copyToStreams(new BufferedInputStream(data), hfos, byteStream);
}


} finally {
res.closeStream();
}
}

public static void writeContent(HttpResponse res, Writer hfos, OutputStream byteStream) throws IOException,
UnsupportedEncodingException {
public static void writeContent(HttpResponse res, BufferedWriter hfos, OutputStream byteStream) throws IOException, UnsupportedEncodingException {
try {
InputStream data = res.getDataAsStream();
String charSet = httpHeader.getCharSet(res.getResponseHeader());
Writer[] writers = (byteStream == null ? new Writer[] { hfos } : new Writer[] { hfos,
new OutputStreamWriter(byteStream, charSet) });
serverFileUtils.copyToWriters(data, writers, charSet);
if (byteStream == null) {
serverFileUtils.copyToWriter(new BufferedInputStream(data), hfos, charSet);
} else {
serverFileUtils.copyToWriters(new BufferedInputStream(data), hfos, new BufferedWriter(new OutputStreamWriter(byteStream, charSet)) , charSet);
}
} finally {
res.closeStream();
}
Expand Down
5 changes: 0 additions & 5 deletions source/de/anomic/http/httpTemplate.java
Expand Up @@ -283,9 +283,6 @@ public static byte[] writeTemplate(InputStream in, OutputStream out, HashMap<Str
num=0;
}
//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
Expand Down Expand Up @@ -336,8 +333,6 @@ public static byte[] writeTemplate(InputStream in, OutputStream out, HashMap<Str
byName=true;
patternName=patternId.getBytes("UTF-8");
}
}else{
//System.out.println("Pattern \""+new String(prefix + key)+"\" is not set"); //DEBUG
}

int currentPattern=0;
Expand Down
7 changes: 4 additions & 3 deletions source/de/anomic/http/httpdProxyHandler.java
Expand Up @@ -64,6 +64,7 @@

import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
Expand Down Expand Up @@ -634,7 +635,7 @@ private static void fulfillRequestFromWeb(Properties conProp, yacyURL url,String
{
// ok, we don't write actually into a file, only to RAM, and schedule writing the file.
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
Saver.writeContent(res, hfos, byteStream);
Saver.writeContent(res, new BufferedWriter(hfos), byteStream);
// cached bytes
byte[] cacheArray;
if(byteStream.size() > 0) {
Expand Down Expand Up @@ -669,7 +670,7 @@ private static void fulfillRequestFromWeb(Properties conProp, yacyURL url,String
// the file is too big to cache it in the ram, or the size is unknown
// write to file right here.
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();
theLogger.logFine("for write-file of " + url + ": contentLength = " + contentLength + ", sizeBeforeDelete = " + sizeBeforeDelete);
plasmaHTCache.writeFileAnnouncement(cacheFile);
Expand Down Expand Up @@ -699,7 +700,7 @@ private static void fulfillRequestFromWeb(Properties conProp, yacyURL url,String
" StoreHTCache=" + storeHTCache +
" SupportetContent=" + isSupportedContent);

Saver.writeContent(res, hfos, null);
Saver.writeContent(res, new BufferedWriter(hfos), null);
if (hfos instanceof htmlFilterWriter) ((htmlFilterWriter) hfos).finalize();
if (sizeBeforeDelete == -1) {
// no old file and no load. just data passing
Expand Down
2 changes: 1 addition & 1 deletion source/de/anomic/kelondro/kelondroLock.java
Expand Up @@ -95,7 +95,7 @@ public synchronized void release() {
if (locked()) {
lock = false;
releaseTime = 0;
notify();
notifyAll();
}
}

Expand Down
2 changes: 1 addition & 1 deletion source/de/anomic/kelondro/kelondroStack.java
Expand Up @@ -145,7 +145,7 @@ public void remove() {
}
}

public int size() {
public synchronized int size() {
return super.size();
}

Expand Down
38 changes: 20 additions & 18 deletions source/de/anomic/server/serverFileUtils.java
Expand Up @@ -562,34 +562,36 @@ public static int copyToStreams(BufferedInputStream in, final BufferedOutputStre
* @return
* @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."
final BufferedReader sourceReader = new BufferedReader(new InputStreamReader(data, charSet));
final Reader sourceReader = new InputStreamReader(data, charSet);

// check if buffer is used. From the documentation:
// "For top efficiency, consider wrapping an OutputStreamWriter within a BufferedWriter so as to avoid frequent
// converter invocations"
int i = 0;
for(final Writer writer: writers) {
if (!(writer instanceof BufferedWriter)) {
// add buffer
writers[i] = new BufferedWriter(writer);
}
i++;
int count = 0;
// copy bytes
int b;
while((b = sourceReader.read()) != -1) {
count++;
writer.write(b);
}
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;
// copy bytes
int b;
while((b = sourceReader.read()) != -1) {
count++;
for(final Writer writer: writers) {
writer.write(b);
}
}
for(final Writer writer: writers) {
writer.flush();
writer0.write(b);
writer1.write(b);
}
writer0.flush();
writer1.flush();
return count;
}
}

0 comments on commit 444dce7

Please sign in to comment.