Skip to content

Commit

Permalink
*) bugfix for wrong proxy traffic accounting
Browse files Browse the repository at this point in the history
git-svn-id: https://svn.berlios.de/svnroot/repos/yacy/trunk@3484 6c8d7289-2bf4-0310-a012-ef5d649a1542
  • Loading branch information
theli committed Mar 16, 2007
1 parent 861f41e commit 91c2a04
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 14 deletions.
4 changes: 2 additions & 2 deletions htroot/Status.java
Expand Up @@ -298,8 +298,8 @@ else if (jobType.equals("globalCrawlTrigger"))
prop.put("processors", rt.availableProcessors());

// proxy traffic
prop.put("trafficIn",bytesToString(httpdByteCountInputStream.getGlobalCount()));
prop.put("trafficOut",bytesToString(httpdByteCountOutputStream.getGlobalCount()));
//prop.put("trafficIn",bytesToString(httpdByteCountInputStream.getGlobalCount()));
prop.put("trafficProxy",bytesToString(httpdByteCountOutputStream.getAccountCount("PROXY")));
prop.put("trafficCrawler",bytesToString(httpdByteCountInputStream.getAccountCount("CRAWLER")));

// connection information
Expand Down
2 changes: 1 addition & 1 deletion htroot/Status_p.inc
Expand Up @@ -59,7 +59,7 @@
</tr>
<tr class="TableCellDark">
<td>Traffic</td>
<td>Proxy: #[trafficOut]# | Crawler: #[trafficCrawler]#</td>
<td>Proxy: #[trafficProxy]# | Crawler: #[trafficCrawler]#</td>
<td>[<a href="Status.html?ResetTraffic=">Reset</a>]</td>
</tr>
<tr class="TableCellLight">
Expand Down
2 changes: 1 addition & 1 deletion htroot/xml/status_p.java
Expand Up @@ -75,7 +75,7 @@ public static serverObjects respond(httpHeader header, serverObjects post, serve

// proxy traffic
prop.put("trafficIn", httpdByteCountInputStream.getGlobalCount());
prop.put("trafficOut", httpdByteCountOutputStream.getGlobalCount());
prop.put("trafficProxy", httpdByteCountOutputStream.getAccountCount("PROXY"));
prop.put("trafficCrawler", httpdByteCountInputStream.getAccountCount("CRAWLER"));

// return rewrite properties
Expand Down
2 changes: 1 addition & 1 deletion htroot/xml/status_p.xml
Expand Up @@ -14,7 +14,7 @@
<processors>#[processors]#</processors>
<traffic>
<in>#[trafficIn]#</in>
<out>#[trafficOut]#</out>
<proxy>#[trafficProxy]#</proxy>
<crawler>#[trafficCrawler]#</crawler>
</traffic>
</status>
5 changes: 5 additions & 0 deletions source/de/anomic/http/httpc.java
Expand Up @@ -572,6 +572,7 @@ public static void flushMissNameCache() {

/**
* Returns the given date in an HTTP-usable format.
* (according to RFC822)
*
* @param date The Date-Object to be converted.
* @return String with the date.
Expand Down Expand Up @@ -696,6 +697,10 @@ void init(
if (incomingByteCountAccounting != null) {
this.clientInputByteCount = new httpdByteCountInputStream(this.socket.getInputStream(),incomingByteCountAccounting);
}
if (outgoingByteCountAccounting != null) {
this.clientOutputByteCount = new httpdByteCountOutputStream(this.socket.getOutputStream(),outgoingByteCountAccounting);
}


// getting input and output streams
this.clientInput = new PushbackInputStream((this.clientInputByteCount!=null)?
Expand Down
2 changes: 1 addition & 1 deletion source/de/anomic/http/httpdBoundedSizeOutputStream.java
Expand Up @@ -55,7 +55,7 @@ public httpdBoundedSizeOutputStream(OutputStream outputStream, long sizeLimit) {
}

public httpdBoundedSizeOutputStream(OutputStream outputStream, long initByteCount, long sizeLimit) {
super(outputStream,initByteCount);
super(outputStream,initByteCount,null);
this.maxSize = sizeLimit;
}

Expand Down
3 changes: 1 addition & 2 deletions source/de/anomic/http/httpdByteCountInputStream.java
Expand Up @@ -70,8 +70,7 @@ protected httpdByteCountInputStream(InputStream inputStream) {
* @param inputStream the {@link InputStream} to read from
*/
public httpdByteCountInputStream(InputStream inputStream, String accountName) {
super(inputStream);
this.byteCountAccountName = accountName;
this(inputStream,0,accountName);
}

/**
Expand Down
37 changes: 34 additions & 3 deletions source/de/anomic/http/httpdByteCountOutputStream.java
Expand Up @@ -47,31 +47,39 @@
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;

public class httpdByteCountOutputStream extends BufferedOutputStream {

private static final Object syncObject = new Object();
private static long globalByteCount = 0;
private boolean finished = false;

private static final HashMap byteCountInfo = new HashMap(2);
protected long byteCount;
protected String byteCountAccountName = null;

/**
* Constructor of this class
* @param outputStream the {@link OutputStream} to write to
*/
public httpdByteCountOutputStream(OutputStream outputStream) {
this(outputStream,0);
this(outputStream,null);
}

public httpdByteCountOutputStream(OutputStream outputStream, String accountName) {
this(outputStream,0,accountName);
}

/**
* Constructor of this class
* @param outputStream the {@link OutputStream} to write to
* @param initByteCount to initialize the bytecount with a given value
*/
public httpdByteCountOutputStream(OutputStream outputStream, long initByteCount) {
public httpdByteCountOutputStream(OutputStream outputStream, long initByteCount, String accountName) {
super(outputStream);
this.byteCount = initByteCount;
this.byteCountAccountName = accountName;
}

/** @see java.io.OutputStream#write(byte[]) */
Expand Down Expand Up @@ -100,15 +108,29 @@ public long getCount() {
return this.byteCount;
}

public String getAccountName() {
return this.byteCountAccountName;
}

public static long getGlobalCount() {
synchronized (syncObject) {
return globalByteCount;
}
}

public static long getAccountCount(String accountName) {
synchronized (syncObject) {
if (byteCountInfo.containsKey(accountName)) {
return ((Long)byteCountInfo.get(accountName)).longValue();
}
return 0;
}
}

public static void resetCount() {
synchronized (syncObject) {
globalByteCount = 0;
byteCountInfo.clear();
}
}

Expand All @@ -118,7 +140,16 @@ public void finish() {
this.finished = true;
synchronized (syncObject) {
globalByteCount += this.byteCount;
}
if (this.byteCountAccountName != null) {
long lastByteCount = 0;
if (byteCountInfo.containsKey(this.byteCountAccountName)) {
lastByteCount = ((Long)byteCountInfo.get(this.byteCountAccountName)).longValue();
}
lastByteCount += this.byteCount;
byteCountInfo.put(this.byteCountAccountName,new Long(lastByteCount));
}

}
}

protected void finalize() throws Throwable {
Expand Down
6 changes: 3 additions & 3 deletions source/de/anomic/http/httpdProxyHandler.java
Expand Up @@ -328,7 +328,7 @@ public void doGet(Properties conProp, httpHeader requestHeader, OutputStream res
switchboard.proxyLastAccess = System.currentTimeMillis();

// using an ByteCount OutputStream to count the send bytes (needed for the logfile)
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2);
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2,"PROXY");

String host = conProp.getProperty(httpHeader.CONNECTION_PROP_HOST);
String path = conProp.getProperty(httpHeader.CONNECTION_PROP_PATH); // always starts with leading '/'
Expand Down Expand Up @@ -893,7 +893,7 @@ public void doHead(Properties conProp, httpHeader requestHeader, OutputStream re
switchboard.proxyLastAccess = System.currentTimeMillis();

// using an ByteCount OutputStream to count the send bytes
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2);
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2,"PROXY");

String host = conProp.getProperty(httpHeader.CONNECTION_PROP_HOST);
String path = conProp.getProperty(httpHeader.CONNECTION_PROP_PATH);
Expand Down Expand Up @@ -998,7 +998,7 @@ public void doPost(Properties conProp, httpHeader requestHeader, OutputStream re
switchboard.proxyLastAccess = System.currentTimeMillis();

// using an ByteCount OutputStream to count the send bytes
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2);
respond = new httpdByteCountOutputStream(respond,conProp.getProperty(httpHeader.CONNECTION_PROP_REQUESTLINE).length() + 2,"PROXY");

String host = conProp.getProperty(httpHeader.CONNECTION_PROP_HOST);
String path = conProp.getProperty(httpHeader.CONNECTION_PROP_PATH);
Expand Down

0 comments on commit 91c2a04

Please sign in to comment.