What is the best way to calculate the remaining boot time?

Let's say you want to calculate the remaining download time, and you have all the necessary information, namely: File size, file size, size on the left, time is up, instant speed, etc. ". How would you calculate the remaining time dl?

Of course, a simple way would be either: the size of the left / instant speed dl, or: (time elapsed / dl 'ed size) * the size on the left. It is only that the former will be subject to deviations in instantaneous speed, and the latter will not adapt well to changes in speeds.

There must be some smarter way to do this, right? Take a look at the pirated software and music that you download from uTorrent. It is easy to see that he does more than the simple calculation mentioned earlier. In fact, I notice that sometimes, when the speed dl drops, the remaining time also falls by a couple of moments until it changes.

+14
download
Apr 28 '09 at 16:33
source share
7 answers

Well, as you said, using the absolutely current download speed is not a great method, because it tends to fluctuate. However, something like a general average is also not a good idea, because there can be big fluctuations.

Consider if I start uploading a file at the same time as 9 others. I get only 10% of my usual speed, but halfway through the file, the remaining 9 end. Now I load 10 times the speed with which I started. My initial 10 percent speed should not be a factor in “how much time is left?” calculation more.

Personally, I'll probably take the average of the last 30 seconds or so, and use that. Calculations based on recent speed should do this without any hesitation. 30 seconds, there may not be a suitable amount, some experimentation will be required to get a good amount.

Another option would be to establish a kind of “fluctuation threshold”, in which you will not recalculate until the speed has changed by more than this threshold. For example (a random number, again, will require experimentation), you can set the threshold value at 10%. Then, if you download at a speed of 100 kbit / s, you do not count the remaining time until the download speed changes below 90 kb / s or 110 kbit / s. If one of these changes occurs, the time is recalculated and a new threshold is set.

+12
Apr 28 '09 at 16:36
source share

You can use the averaging algorithm, where old values ​​will decrease linearly. If S_n is the speed at time n, and A_ {n-1} is the average value of time n-1, then determine your average speed as follows.

A_1 = S_1
A_2 = (S_1 + S_2) / 2
A_n = S_n / (n-1) + A_ {n-1} (1-1 / (n-1))

In English, this means that the longer a measurement has taken place in the past, the less it matters because its value has died out.

Compare this with the usual averaging algorithm: A_n = S_n / n + A_ {n-1} (1-1 / n)

You could also have its geometrically decay, which would greatly affect the latest speeds: A_n = S_n / 2 + A_ {n-1} / 2

If the speed is 4.3.5.6, then A_4 = 4.5 (simple average value)
A_4 = 4.75 (linear decay)
A_4 = 5.125 (geometric decay)

PHP example

Beware that $n+1 (not $n ) is the number of current data points due to the fact that PHP arrays did not have a zero index. To match the above example, set n == $n+1 or n-1 == $n

 <?php $s = [4,3,5,6]; // average $a = []; for ($n = 0; $n < count($s); ++$n) { if ($n == 0) $a[$n] = $s[$n]; else { // $n+1 = number of data points so far $weight = 1/($n+1); $a[$n] = $s[$n] * $weight + $a[$n-1] * (1 - $weight); } } var_dump($a); // linear decay $a = []; for ($n = 0; $n < count($s); ++$n) { if ($n == 0) $a[$n] = $s[$n]; elseif ($n == 1) $a[$n] = ($s[$n] + $s[$n-1]) / 2; else { // $n = number of data points so far - 1 $weight = 1/($n); $a[$n] = $s[$n] * $weight + $a[$n-1] * (1 - $weight); } } var_dump($a); // geometric decay $a = []; for ($n = 0; $n < count($s); ++$n) { if ($n == 0) $a[$n] = $s[$n]; else { $weight = 1/2; $a[$n] = $s[$n] * $weight + $a[$n-1] * (1 - $weight); } } var_dump($a); 

Exit

 array (size=4) 0 => int 4 1 => float 3.5 2 => float 4 3 => float 4.5 array (size=4) 0 => int 4 1 => float 3.5 2 => float 4.25 3 => float 4.8333333333333 array (size=4) 0 => int 4 1 => float 3.5 2 => float 4.25 3 => float 5.125 
+10
Apr 28 '09 at 17:37
source share

The obvious way would be something in between, you need a "moving average" download speed.

+7
Apr 28 '09 at 16:37
source share

I think this is just an averaging algorithm. It averages the speed for several seconds.

+2
Apr 28 '09 at 16:36
source share

What you could do is track your average speed and show the results of this.

+1
Apr 28 '09 at 16:35
source share

EDIT: here is what I finally suggest, I tried, and it gives quite satisfactory results:

I have a zero initialized array for each download speed from 0 to 500 kB / s (maybe higher if you expect such speeds) in increments of 1 kB / s. I try on loading speed instantly (every second is a good interval) and increase the argument element of the array by one. Now I know how many seconds I spent downloading a file at each speed. The sum of all these values ​​is the elapsed time (in seconds). The sum of these values, multiplied by the corresponding speed, is the size loaded so far. If I accept the relationship between each value in the array and elapsed time, assuming that the rate change pattern is stabilizing, I can formulate a formula to predict the time that each size will take. This size in this case is the remaining size. This is what I do: I take the sum of each value of the element of the array, multiplied by the corresponding speed (index) and divided by the elapsed time. Then I divide the size remaining by this value and the remaining time.

It takes a few seconds to stabilize and then works well, damn it.

Please note that this is a “complex” average value, so the method of discarding old values ​​(moving average) can further improve it.

0
Apr 28 '09 at 17:13
source share

For anyone interested, I wrote an open source C # library called Progression , which has a “moving average” implementation: ETACalculator.cs .

The Progression library defines an easy-to-use structure for reporting several types of progress. It also easily manages nested progress to get a very smooth progress report.

0
Mar 15 '11 at 23:41
source share



All Articles