Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup RunningAverage implementations #989

Open
wants to merge 4 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions src/freenet/io/xfer/BlockReceiver.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@
import freenet.support.Ticker;
import freenet.support.TimeUtil;
import freenet.support.io.NativeThread;
import freenet.support.math.MedianMeanRunningAverage;
import freenet.support.math.RunningAverage;
import freenet.support.math.TrivialRunningAverage;

/**
* IMPORTANT: The receiver can cancel the incoming transfer. This may or may not,
Expand Down Expand Up @@ -306,10 +307,8 @@ public void onMatched(Message m1) {
long endTime = System.currentTimeMillis();
long transferTime = (endTime - startTime);
if(logMINOR) {
synchronized(avgTimeTaken) {
avgTimeTaken.report(transferTime);
Logger.minor(this, "Block transfer took "+transferTime+"ms - average is "+avgTimeTaken);
}
avgTimeTaken.report(transferTime);
Logger.minor(this, "Block transfer took "+transferTime+"ms - average is "+avgTimeTaken.currentValue());
}
complete(_prb.getBlock());
return;
Expand Down Expand Up @@ -534,7 +533,7 @@ public void receiveAborted(int reason, String description) {
}
}

private static MedianMeanRunningAverage avgTimeTaken = new MedianMeanRunningAverage();
private static final RunningAverage avgTimeTaken = new TrivialRunningAverage();

private void maybeResetDiscardFilter() {
long timeleft=discardEndTime-System.currentTimeMillis();
Expand Down
17 changes: 8 additions & 9 deletions src/freenet/io/xfer/BlockTransmitter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
*/
package freenet.io.xfer;

import java.util.HashSet;
import java.util.Deque;
import java.util.HashSet;

import freenet.io.comm.AsyncMessageCallback;
import freenet.io.comm.AsyncMessageFilterCallback;
Expand All @@ -32,18 +32,19 @@
import freenet.io.comm.NotConnectedException;
import freenet.io.comm.PeerContext;
import freenet.io.comm.RetrievalException;
import freenet.node.MessageItem;
import freenet.io.comm.SlowAsyncMessageFilterCallback;
import freenet.node.MessageItem;
import freenet.node.PrioRunnable;
import freenet.support.BitArray;
import freenet.support.Executor;
import freenet.support.LogThresholdCallback;
import freenet.support.Logger;
import freenet.support.Logger.LogLevel;
import freenet.support.Ticker;
import freenet.support.TimeUtil;
import freenet.support.Logger.LogLevel;
import freenet.support.io.NativeThread;
import freenet.support.math.MedianMeanRunningAverage;
import freenet.support.math.RunningAverage;
import freenet.support.math.TrivialRunningAverage;

/**
* @author ian
Expand Down Expand Up @@ -471,10 +472,8 @@ public void onMatched(Message m) {
if(logMINOR) {
long endTime = System.currentTimeMillis();
long transferTime = (endTime - startTime);
synchronized(avgTimeTaken) {
avgTimeTaken.report(transferTime);
Logger.minor(this, "Block send took "+transferTime+" : "+avgTimeTaken+" on "+BlockTransmitter.this);
}
avgTimeTaken.report(transferTime);
Logger.minor(this, "Block send took "+transferTime+" : average "+avgTimeTaken.currentValue()+" on "+BlockTransmitter.this);
}
synchronized(_senderThread) {
_receivedSendCompletion = true;
Expand Down Expand Up @@ -764,7 +763,7 @@ else if(logMINOR)

private long lastSentPacket = -1;

private static MedianMeanRunningAverage avgTimeTaken = new MedianMeanRunningAverage();
private static final RunningAverage avgTimeTaken = new TrivialRunningAverage();

/** LOCKING: Must be called with _senderThread held. */
private int getNumSent() {
Expand Down
19 changes: 9 additions & 10 deletions src/freenet/node/RequestSender.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
import freenet.support.SimpleFieldSet;
import freenet.support.TimeUtil;
import freenet.support.io.NativeThread;
import freenet.support.math.MedianMeanRunningAverage;
import freenet.support.math.RunningAverage;
import freenet.support.math.TrivialRunningAverage;

/**
* @author amphibian
Expand Down Expand Up @@ -1542,9 +1543,9 @@ public synchronized short waitUntilStatusChange(short mask) {
}
}

private static MedianMeanRunningAverage avgTimeTaken = new MedianMeanRunningAverage();
private static final RunningAverage avgTimeTaken = new TrivialRunningAverage();

private static MedianMeanRunningAverage avgTimeTakenTransfer = new MedianMeanRunningAverage();
private static final RunningAverage avgTimeTakenTransfer = new TrivialRunningAverage();

private long transferTime;

Expand Down Expand Up @@ -1583,13 +1584,11 @@ private void finish(int code, PeerNode next, boolean fromOfferedKey) {
if(status == SUCCESS) {
if((!isSSK) && transferTime > 0 && logMINOR) {
long timeTaken = System.currentTimeMillis() - startTime;
synchronized(avgTimeTaken) {
avgTimeTaken.report(timeTaken);
avgTimeTakenTransfer.report(transferTime);
if(logMINOR) Logger.minor(this, "Successful CHK request took "+timeTaken+" average "+avgTimeTaken);
if(logMINOR) Logger.minor(this, "Successful CHK request transfer "+transferTime+" average "+avgTimeTakenTransfer);
if(logMINOR) Logger.minor(this, "Search phase: median "+(avgTimeTaken.currentValue() - avgTimeTakenTransfer.currentValue())+"ms, mean "+(avgTimeTaken.meanValue() - avgTimeTakenTransfer.meanValue())+"ms");
}
avgTimeTaken.report(timeTaken);
avgTimeTakenTransfer.report(transferTime);
Logger.minor(this, "Successful CHK request took "+timeTaken+" average "+avgTimeTaken.currentValue());
Logger.minor(this, "Successful CHK request transfer "+transferTime+" average "+avgTimeTakenTransfer.currentValue());
Logger.minor(this, "Search phase: mean "+(avgTimeTaken.currentValue() - avgTimeTakenTransfer.currentValue())+"ms");
}
if(next != null) {
next.onSuccess(false, isSSK);
Expand Down
Loading