summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2024-05-22 15:10:37 +0200
committerSimon Rettberg2024-05-22 15:10:37 +0200
commit97742fd485183b6ce57bacc99e7c3c2d6fbfce88 (patch)
treeddd5af2e7a3cf25d771de105c397b4cf28e76dd1
parent[server] Remove upload state in JSON; handled by client now (diff)
downloadtutor-module-97742fd485183b6ce57bacc99e7c3c2d6fbfce88.tar.gz
tutor-module-97742fd485183b6ce57bacc99e7c3c2d6fbfce88.tar.xz
tutor-module-97742fd485183b6ce57bacc99e7c3c2d6fbfce88.zip
[server] CoW: Fix calculating copy speed, don't return delay=0
Returning a calculated delay of 0 tells the caller that we wrote the modified block, which isn't true, so in effect a corrupted final image is created where certain modified blocks are missing.
-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) {