Hello,
I wonder, why the bandwidth limit is implemented the way it is.
I put up a node for that I can spend 2 GB traffic a month. So I set the
bandwidth limit in .freenetrc to 800 byte/second and then realized, how
slow my node became.
My solution was to save the currently unused bandwidth for a later time.
This should not be a problem, unless you are doing any realtime stuff
over the network.
If you find my patch useful, you can apply it (against 0.3.9.1) with:
cd Freenet
patch -p1 < thismail
Bye
Thomas
diff -Naur Freenet/support/io/Bandwidth.java Freenet-tl/support/io/Bandwidth.java
--- Freenet/support/io/Bandwidth.java Thu Mar 29 08:02:29 2001
+++ Freenet-tl/support/io/Bandwidth.java Tue Jun 19 20:27:08 2001
@@ -1,7 +1,6 @@
package Freenet.support.io;
import Freenet.support.Logger;
import Freenet.Core;
-import java.io.*;
public class Bandwidth {
@@ -24,14 +23,13 @@
public Bandwidth(int bandwidth) {
bandwidthPerTick = bandwidth / ticksPerSecond;
+ moreBandwidthTime = System.currentTimeMillis();
+ available = 0;
}
- synchronized protected void chargeBandwidth(int used) {
+ protected void chargeBandwidth(int used) {
do {
- waitForBandwidth();
- int result = Math.min(used, available);
- available -= result;
- used -= result;
+ used -= getBandwidth(used);
} while(used > 0);
}
@@ -46,21 +44,26 @@
// Too bad "void" is such a short word. (-:
synchronized protected void waitForBandwidth() {
- for (;;) {
- long now = System.currentTimeMillis();
- refillAvailableBandwidth(now);
- if (available != 0)
- break;
- try {
- Thread.currentThread().sleep(moreBandwidthTime - now);
- } catch (InterruptedException e) {}
- }
- }
-
+ for (;;) {
+ long now = System.currentTimeMillis();
+ refillAvailableBandwidth(now);
+ if (0 != available) {
+ break;
+ }
+ try {
+ Thread.currentThread().sleep
+ (moreBandwidthTime - System.currentTimeMillis());
+ } catch (InterruptedException e) {}
+ }
+ }
+
synchronized protected void refillAvailableBandwidth(long now) {
- if (now >= moreBandwidthTime) {
- available = bandwidthPerTick;
- moreBandwidthTime = now + millisPerTick;
- }
- }
+ while (moreBandwidthTime <= now) {
+ moreBandwidthTime += millisPerTick;
+ available += bandwidthPerTick;
+ }
+ if (available < 0) { //integer overflow occurred
+ available = Integer.MAX_VALUE;
+ }
+ }
}
_______________________________________________
Devl mailing list
[EMAIL PROTECTED]
http://lists.freenetproject.org/mailman/listinfo/devl