Skip to content

Commit

Permalink
Fix bandwidth approximator (#192)
Browse files Browse the repository at this point in the history
If the client downloads a piece that takes more than 1 second, the
approximation will be wrong. We need a bigger SMOOTH_INTERVAL to
correctly measure the bandwidth
  • Loading branch information
Chocobozzz authored Mar 30, 2021
1 parent 80d082b commit e9c73ad
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions p2p-media-loader-core/lib/bandwidth-approximator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* limitations under the License.
*/

const SMOOTH_INTERVAL = 1 * 1000;
const SMOOTH_INTERVAL = 15 * 1000;
const MEASURE_INTERVAL = 60 * 1000;

class NumberWithTime {
Expand All @@ -35,7 +35,8 @@ export class BandwidthApproximator {
this.currentBytesSum -= this.lastBytes.shift()!.value;
}

this.lastBandwidth.push(new NumberWithTime(this.currentBytesSum / SMOOTH_INTERVAL, timeStamp));
const interval = Math.min(SMOOTH_INTERVAL, timeStamp);
this.lastBandwidth.push(new NumberWithTime(this.currentBytesSum / interval, timeStamp));
}

// in bytes per millisecond
Expand Down

0 comments on commit e9c73ad

Please sign in to comment.