summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSession.java19
1 files changed, 11 insertions, 8 deletions
diff --git a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSession.java b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSession.java
index a2814d15..c24f4acb 100644
--- a/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSession.java
+++ b/dozentenmodulserver/src/main/java/org/openslx/bwlp/sat/fileserv/cow/CowSession.java
@@ -50,7 +50,7 @@ public class CowSession {
private final CowSessionData data;
- private int estimatedSpeedKbs = 0;
+ private long estimatedSpeedKbs = 0;
/**
* Use for operations on destinationFile.
@@ -336,6 +336,9 @@ public class CowSession {
if (estimatedSpeedKbs > 0) {
delay = (int) ((missing / 1000) / estimatedSpeedKbs);
}
+ if (delay < 1) {
+ delay = 1;
+ }
LOGGER.info("Throttling client - Missing: " + Util.formatBytes(missing) + ", Speed: "
+ Util.formatBytes(estimatedSpeedKbs * 1000) + "/s, Wait: " + delay);
return delay;
@@ -361,7 +364,7 @@ public class CowSession {
public void run() {
long lastTime = Util.tickCount();
long byteCount = 0;
- int[] history = new int[10];
+ long[] history = new long[10];
int historySlot = 0;
try {
byte[] chunk = new byte[COPY_BLOCK_SIZE];
@@ -386,7 +389,7 @@ public class CowSession {
long now = Util.tickCount();
long delta = now - lastTime;
if (delta > 1000) {
- history[historySlot++ % history.length] = (int) (byteCount / delta);
+ history[historySlot++ % history.length] = byteCount / delta;
byteCount = 0;
lastTime = now;
updateSpeedEstimate(history);
@@ -410,16 +413,16 @@ public class CowSession {
}
}
- private void updateSpeedEstimate(int[] values) {
- int sum = 0;
- for (int i = 0; i < values.length; ++i) {
+ private void updateSpeedEstimate(long[] history) {
+ long sum = 0;
+ for (int i = 0; i < history.length; ++i) {
// Some slots might still be 0 in the beginning, so for the first 10+ seconds
// we underestimate. But that shouldn't matter since background upload on the
// client only starts 60 seconds in.
- sum += values[i];
+ sum += history[i];
}
// This is effectively KB/s, as we divided by milliseconds, not seconds
- estimatedSpeedKbs = sum;
+ estimatedSpeedKbs = sum / history.length;
}
};
synchronized (varLock) {