From 9c3927c81add7c5a5cda22add171499c8636616a Mon Sep 17 00:00:00 2001 From: Luis Guzman Date: Sat, 15 Aug 2026 16:08:34 -0600 Subject: [PATCH] ADFA-5160: warm up the clone-receive ETA before showing it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-up to the clone progress fix. rsync's first progress samples report a tiny instantaneous speed, so an ETA derived from them read as thousands of hours (e.g. 1665:33:45) for the opening seconds. Hold the ETA for a ~3s warmup (showing "…"), then compute it from the AVERAGE speed (bytes moved / elapsed) rather than the instantaneous figure — steadier, and it smooths the mid-transfer jitter too. The bar and speed keep moving during the warmup. parseSpeedBytesPerSec is no longer used (the ETA no longer parses rsync's speed string), so it and its test are removed. --- .../org/iiab/controller/RsyncManager.java | 25 +++++++++++---- .../controller/sync/domain/RsyncProgress.java | 31 ------------------- .../sync/domain/RsyncProgressTest.java | 10 ------ 3 files changed, 19 insertions(+), 47 deletions(-) diff --git a/controller/app/src/main/java/org/iiab/controller/RsyncManager.java b/controller/app/src/main/java/org/iiab/controller/RsyncManager.java index 9a78e6153..42dddb3a5 100644 --- a/controller/app/src/main/java/org/iiab/controller/RsyncManager.java +++ b/controller/app/src/main/java/org/iiab/controller/RsyncManager.java @@ -139,6 +139,8 @@ public void startClient(Context context, ShareConfig config, String hostIp, int String lastFile = ""; int lastEmittedPct = 0; // ADFA-5160: smoothed percent, never walked back + long firstProgressMs = 0L; // ADFA-5160 follow-up: anchor for the ETA warmup + final long etaWarmupMs = 3000L; // hold the ETA until the speed sample settles while ((line = reader.readLine()) != null) { if (isCancelled) { @@ -162,15 +164,26 @@ public void startClient(Context context, ShareConfig config, String hostIp, int lastEmittedPct = pct; // ADFA-5160: rsync's ETA is computed against its per-file plan, so it jumps - // the same way the old percent did. When we have a whole-set total, derive - // the ETA from the bytes still to go and the current speed instead. - String eta = progress.eta; + // the same way the old percent did — and its first samples report a tiny + // instantaneous speed, so an ETA derived then reads as thousands of hours. + // Hold the ETA for a short warmup, then compute it from the AVERAGE speed + // (bytes moved / elapsed), which is steadier than rsync's instantaneous + // figure and smooths the mid-transfer jitter too. The bar and speed keep + // moving during the warmup; only the ETA waits. + if (firstProgressMs == 0L) firstProgressMs = System.currentTimeMillis(); + long elapsedMs = System.currentTimeMillis() - firstProgressMs; + + String eta; if (expectedTotalBytes > 0) { - double bps = RsyncProgress.parseSpeedBytesPerSec(progress.speed); - if (bps > 0) { + if (elapsedMs >= etaWarmupMs && progress.bytes > 0) { + double avgBps = progress.bytes / (elapsedMs / 1000.0); long remaining = Math.max(0L, expectedTotalBytes - progress.bytes); - eta = RsyncProgress.formatEta((long) (remaining / bps)); + eta = RsyncProgress.formatEta((long) (remaining / avgBps)); + } else { + eta = "…"; // warmup: no bogus figure yet } + } else { + eta = progress.eta; // no whole-set total: rsync's own ETA } String finalFile = lastFile; diff --git a/controller/app/src/main/java/org/iiab/controller/sync/domain/RsyncProgress.java b/controller/app/src/main/java/org/iiab/controller/sync/domain/RsyncProgress.java index 43aac8f81..8246c8539 100644 --- a/controller/app/src/main/java/org/iiab/controller/sync/domain/RsyncProgress.java +++ b/controller/app/src/main/java/org/iiab/controller/sync/domain/RsyncProgress.java @@ -41,12 +41,6 @@ private RsyncProgress(long bytes, int percent, String speed, String eta) { private static final Pattern STATS = Pattern.compile("Total transferred file size:\\s+([\\d,\\.]+)\\s+bytes"); - // ADFA-5160: rsync's speed column, e.g. "12.34MB/s" / "512.00B/s". Used to turn the - // whole-set remaining bytes into a whole-set ETA, instead of rsync's own ETA, which is - // computed against its per-file plan and jumps the same way the old percent did. - private static final Pattern SPEED = - Pattern.compile("([\\d\\.]+)([kMGT]?B)/s"); - /** * Parses one rsync {@code --info=progress2} line. Returns {@code null} if the * line carries no progress token or the percentage is not a number. @@ -79,31 +73,6 @@ public static long parseTransferredBytes(String line, long fallback) { } } - /** - * Parses a rsync speed column ("12.34MB/s") into bytes per second (1024-based units, as - * rsync prints them). Returns {@code -1} when the string does not match. ADFA-5160. - */ - public static double parseSpeedBytesPerSec(String speed) { - if (speed == null) return -1d; - Matcher m = SPEED.matcher(speed); - if (!m.find()) return -1d; - try { - double n = Double.parseDouble(m.group(1)); - double mult; - switch (m.group(2)) { - case "B": mult = 1d; break; - case "kB": mult = 1024d; break; - case "MB": mult = 1024d * 1024d; break; - case "GB": mult = 1024d * 1024d * 1024d; break; - case "TB": mult = 1024d * 1024d * 1024d * 1024d; break; - default: return -1d; - } - return n * mult; - } catch (NumberFormatException e) { - return -1d; - } - } - /** Formats a duration in seconds as rsync's {@code H:MM:SS}. Negatives clamp to zero. */ public static String formatEta(long seconds) { if (seconds < 0) seconds = 0; diff --git a/controller/app/src/test/java/org/iiab/controller/sync/domain/RsyncProgressTest.java b/controller/app/src/test/java/org/iiab/controller/sync/domain/RsyncProgressTest.java index 11f9fe551..c88e2df86 100644 --- a/controller/app/src/test/java/org/iiab/controller/sync/domain/RsyncProgressTest.java +++ b/controller/app/src/test/java/org/iiab/controller/sync/domain/RsyncProgressTest.java @@ -51,16 +51,6 @@ public void returnsFallbackWhenStatsLineAbsent() { assertEquals(0L, RsyncProgress.parseTransferredBytes(null, 0L)); } - // ADFA-5160: speed -> bytes/sec, for deriving a whole-set ETA. - @Test - public void parsesSpeedToBytesPerSecond() { - assertEquals(1024.0 * 1024.0, RsyncProgress.parseSpeedBytesPerSec("1.00MB/s"), 0.001); - assertEquals(1024.0, RsyncProgress.parseSpeedBytesPerSec("1.00kB/s"), 0.001); - assertEquals(512.0, RsyncProgress.parseSpeedBytesPerSec("512.00B/s"), 0.001); - assertEquals(-1.0, RsyncProgress.parseSpeedBytesPerSec("n/a"), 0.001); - assertEquals(-1.0, RsyncProgress.parseSpeedBytesPerSec(null), 0.001); - } - // ADFA-5160: whole-set ETA formatting, rsync's H:MM:SS. @Test public void formatsEtaAsHoursMinutesSeconds() {