From adf3e528f56ed6da5a6b29b644b5c8c0d82adb81 Mon Sep 17 00:00:00 2001 From: reesporte Date: Thu, 21 Oct 2021 13:09:24 -0500 Subject: [PATCH] Change time estimation to use avg time per message MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In [SUP-75](https://molecula.atlassian.net/browse/SUP-75?atlOrigin=eyJpIjoiYmU5MzdkMmUyZTAyNGQ2Y2IzMDMzYTgzMDU2Y2ZhNmMiLCJwIjoiaiJ9) Allen pointed out that the time estimation is really good for the first couple lines of output, but gets exponentially worse as execution continues. After looking into it, it looks like we’re currently using a heuristic based on the amount of messages processed in the previous second(ish) which is what results in that sort of exponential drop off. To remedy this, I adjusted the time estimation calculation to use the average time per message up to the point of calculating the new estimate to ideally improve estimates over time, with the trade-off of a potentially less accurate estimate to begin with. --- server.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index fdca4dc39..ce6babe25 100644 --- a/server.go +++ b/server.go @@ -722,8 +722,10 @@ func (s *Server) Open() error { if now := time.Now(); now.Sub(prevMsg) > time.Second { progressRatio := float64(i+1) / float64(len(toSend)) - remainingRatio := 1 - progressRatio - timeRemaining := time.Duration(float64(now.Sub(prevMsg)) * (remainingRatio / progressRatio)) + numSentMessages := len(toSend) - (i + 1) + messagesLeft := len(toSend) - numSentMessages + avgTimePerMessage := float64(now.Sub(start)) / float64(numSentMessages) + timeRemaining := time.Duration(avgTimePerMessage * float64(messagesLeft)) s.logger.Printf("synced %d/%d messages (%.2f%% complete; %s remaining)", i+1, len(toSend), 100*progressRatio, timeRemaining) prevMsg = now }