(zzz) Add rate reporting to i2psnark

This commit is contained in:
zzz
2006-09-03 09:12:22 +00:00
committed by zzz
parent 4aed23b198
commit 3b01df1d2c
5 changed files with 64 additions and 13 deletions

View File

@ -89,8 +89,6 @@ class PeerCheckerTask extends TimerTask
if (peer.isChoked()) if (peer.isChoked())
choked++; choked++;
// XXX - We should calculate the up/download rate a bit
// more intelligently
long upload = peer.getUploaded(); long upload = peer.getUploaded();
uploaded += upload; uploaded += upload;
long download = peer.getDownloaded(); long download = peer.getDownloaded();
@ -196,6 +194,10 @@ class PeerCheckerTask extends TimerTask
// Put peers back at the end of the list that we removed earlier. // Put peers back at the end of the list that we removed earlier.
coordinator.peers.addAll(removed); coordinator.peers.addAll(removed);
coordinator.peerCount = coordinator.peers.size(); coordinator.peerCount = coordinator.peers.size();
// store the rates
coordinator.setRateHistory(uploaded, downloaded);
} }
if (coordinator.halted()) { if (coordinator.halted()) {
cancel(); cancel();

View File

@ -50,6 +50,9 @@ public class PeerCoordinator implements PeerListener
private long uploaded; private long uploaded;
private long downloaded; private long downloaded;
final static int RATE_DEPTH = 6; // make following arrays RATE_DEPTH long
private long uploaded_old[] = {0,0,0,0,0,0};
private long downloaded_old[] = {0,0,0,0,0,0};
// synchronize on this when changing peers or downloaders // synchronize on this when changing peers or downloaders
final List peers = new ArrayList(); final List peers = new ArrayList();
@ -142,6 +145,43 @@ public class PeerCoordinator implements PeerListener
return downloaded; return downloaded;
} }
/**
* Push the total uploaded/downloaded onto a RATE_DEPTH deep stack
*/
public void setRateHistory(long up, long down)
{
for (int i = RATE_DEPTH-1; i > 0; i--){
uploaded_old[i] = uploaded_old[i-1];
downloaded_old[i] = downloaded_old[i-1];
}
uploaded_old[0] = up;
downloaded_old[0] = down;
}
/**
* Returns the 2-minute-average rate in Bps
*/
public long getDownloadRate()
{
long rate = 0;
for (int i = 0; i < RATE_DEPTH; i++){
rate += downloaded_old[i];
}
return rate / (RATE_DEPTH * CHECK_PERIOD / 1000);
}
/**
* Returns the 2-minute-average rate in Bps
*/
public long getUploadRate()
{
long rate = 0;
for (int i = 0; i < RATE_DEPTH; i++){
rate += uploaded_old[i];
}
return rate / (RATE_DEPTH * CHECK_PERIOD / 1000);
}
public MetaInfo getMetaInfo() public MetaInfo getMetaInfo()
{ {
return metainfo; return metainfo;

View File

@ -292,8 +292,13 @@ public class I2PSnarkServlet extends HttpServlet {
long remaining = (long) snark.storage.needed() * (long) snark.meta.getPieceLength(0); long remaining = (long) snark.storage.needed() * (long) snark.meta.getPieceLength(0);
if (remaining > total) if (remaining > total)
remaining = total; remaining = total;
int totalBps = 4096; // should probably grab this from the snark... long downBps = snark.coordinator.getDownloadRate();
long remainingSeconds = remaining / totalBps; long upBps = snark.coordinator.getUploadRate();
long remainingSeconds;
if (downBps > 0)
remainingSeconds = remaining / downBps;
else
remainingSeconds = -1;
long uploaded = snark.coordinator.getUploaded(); long uploaded = snark.coordinator.getUploaded();
boolean isRunning = !snark.stopped; boolean isRunning = !snark.stopped;
@ -339,17 +344,18 @@ public class I2PSnarkServlet extends HttpServlet {
out.write("<td valign=\"top\" align=\"left\" class=\"snarkTorrentDownloaded " + rowClass + "\">"); out.write("<td valign=\"top\" align=\"left\" class=\"snarkTorrentDownloaded " + rowClass + "\">");
if (remaining > 0) { if (remaining > 0) {
out.write(formatSize(total-remaining) + "/" + formatSize(total)); // 18MB/3GB out.write(formatSize(total-remaining) + "/" + formatSize(total)); // 18MB/3GB
// lets hold off on the ETA until we have rates sorted... if(isRunning && remainingSeconds > 0)
//out.write(" (eta " + DataHelper.formatDuration(remainingSeconds*1000) + ")"); // (eta 6h) out.write(" (ETA " + DataHelper.formatDuration(remainingSeconds*1000) + ")"); // (eta 6h)
} else { } else {
out.write(formatSize(total)); // 3GB out.write(formatSize(total)); // 3GB
} }
out.write("</td>\n\t"); out.write("</td>\n\t");
out.write("<td valign=\"top\" align=\"left\" class=\"snarkTorrentUploaded " + rowClass out.write("<td valign=\"top\" align=\"left\" class=\"snarkTorrentUploaded " + rowClass
+ "\">" + formatSize(uploaded) + "</td>\n\t"); + "\">" + formatSize(uploaded) + "</td>\n\t");
//out.write("<td valign=\"top\" align=\"left\" class=\"snarkTorrentRate\">"); out.write("<td valign=\"top\" align=\"left\" class=\"snarkTorrentRate\">");
//out.write("n/a"); //2KBps/12KBps/4KBps if(isRunning)
//out.write("</td>\n\t"); out.write(formatSize(downBps) + "ps/" + formatSize(upBps) + "ps");
out.write("</td>\n\t");
out.write("<td valign=\"top\" align=\"left\" class=\"snarkTorrentAction " + rowClass + "\">"); out.write("<td valign=\"top\" align=\"left\" class=\"snarkTorrentAction " + rowClass + "\">");
if (isRunning) { if (isRunning) {
out.write("<a href=\"" + uri + "?action=Stop&nonce=" + _nonce out.write("<a href=\"" + uri + "?action=Stop&nonce=" + _nonce
@ -574,7 +580,7 @@ public class I2PSnarkServlet extends HttpServlet {
" <th align=\"left\" valign=\"top\">Torrent</th>\n" + " <th align=\"left\" valign=\"top\">Torrent</th>\n" +
" <th align=\"left\" valign=\"top\">Downloaded</th>\n" + " <th align=\"left\" valign=\"top\">Downloaded</th>\n" +
" <th align=\"left\" valign=\"top\">Uploaded</th>\n" + " <th align=\"left\" valign=\"top\">Uploaded</th>\n" +
//" <th align=\"left\" valign=\"top\">Rate</th>\n" + " <th align=\"left\" valign=\"top\">Rate Down/Up</th>\n" +
" <th>&nbsp;</th></tr>\n" + " <th>&nbsp;</th></tr>\n" +
"</thead>\n"; "</thead>\n";

View File

@ -1,4 +1,7 @@
$Id: history.txt,v 1.506 2006-08-21 00:55:34 complication Exp $ $Id: history.txt,v 1.507 2006-09-03 01:37:46 complication Exp $
2006-09-03 zzz
* Add rate reporting to i2psnark
2006-09-03 Complication 2006-09-03 Complication
* Limit form size in SusiDNS to avoid exceeding a POST size limit on postback * Limit form size in SusiDNS to avoid exceeding a POST size limit on postback

View File

@ -15,9 +15,9 @@ import net.i2p.CoreVersion;
* *
*/ */
public class RouterVersion { public class RouterVersion {
public final static String ID = "$Revision: 1.446 $ $Date: 2006-08-21 00:55:34 $"; public final static String ID = "$Revision: 1.447 $ $Date: 2006-09-03 01:37:47 $";
public final static String VERSION = "0.6.1.24"; public final static String VERSION = "0.6.1.24";
public final static long BUILD = 5; public final static long BUILD = 6;
public static void main(String args[]) { public static void main(String args[]) {
System.out.println("I2P Router version: " + VERSION + "-" + BUILD); System.out.println("I2P Router version: " + VERSION + "-" + BUILD);
System.out.println("Router ID: " + RouterVersion.ID); System.out.println("Router ID: " + RouterVersion.ID);