Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

throughput calculation in FetchLoader #3663

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions samples/dash-if-reference-player/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -314,14 +314,14 @@
<label data-toggle="tooltip" data-placement="right"
title="Default fetch throughput calculation for low latency streaming based on downloaded data chunks.">
<input type="radio" id="abrFetchThroughputCalculationDownloadedData" autocomplete="off"
checked="checked" name="abrFetchThroughputCalculation"
name="abrFetchThroughputCalculation"
ng-click="changeFetchThroughputCalculation('abrFetchThroughputCalculationDownloadedData')">
Data chunks
</label>
<label data-toggle="tooltip" data-placement="right"
title="LoL+ fetch throughput calculation for low latency streaming based on moof parsing.">
<input type="radio" id="abrFetchThroughputCalculationMoofParsing" autocomplete="off"
name="abrFetchThroughputCalculation"
checked="checked" name="abrFetchThroughputCalculation"
ng-click="changeFetchThroughputCalculation('abrFetchThroughputCalculationMoofParsing')">
moof parsing
</label>
Expand Down
2 changes: 1 addition & 1 deletion src/core/Settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -870,7 +870,7 @@ function Settings() {
audio: true,
video: true
},
fetchThroughputCalculationMode: Constants.ABR_FETCH_THROUGHPUT_CALCULATION_DOWNLOADED_DATA
fetchThroughputCalculationMode: Constants.ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING
},
cmcd: {
enabled: false,
Expand Down
5 changes: 3 additions & 2 deletions src/streaming/models/MetricsModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,13 @@ function MetricsModel(config) {
}
}

function appendHttpTrace(httpRequest, s, d, b) {
function appendHttpTrace(httpRequest, s, d, b, t) {
let vo = new HTTPRequestTrace();

vo.s = s;
vo.d = d;
vo.b = b;
vo.t = t;

httpRequest.trace.push(vo);

Expand Down Expand Up @@ -185,7 +186,7 @@ function MetricsModel(config) {

if (traces) {
traces.forEach(trace => {
appendHttpTrace(vo, trace.s, trace.d, trace.b);
appendHttpTrace(vo, trace.s, trace.d, trace.b, trace.t);
});
} else {
// The interval and trace shall be absent for redirect and failure records.
Expand Down
93 changes: 54 additions & 39 deletions src/streaming/net/FetchLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,17 @@ function FetchLoader(cfg) {
// If there is pending data, call progress so network metrics
// are correctly generated
// Same structure as https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequestEventTarget/
let calculatedThroughput = null;
if (calculationMode === Constants.ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING) {
calculatedThroughput = calculateThroughputByChunkData(startTimeData, endTimeData);
}

httpRequest.progress({
loaded: bytesReceived,
total: isNaN(totalBytes) ? bytesReceived : totalBytes,
lengthComputable: true,
time: calculateDownloadedTime(calculationMode, startTimeData, endTimeData, downloadedData, bytesReceived),
time: calculateDownloadedTime(downloadedData, bytesReceived),
throughput: calculatedThroughput,
stream: true
});

Expand Down Expand Up @@ -195,7 +201,7 @@ function FetchLoader(cfg) {
const end = boxesInfo.lastCompletedOffset + boxesInfo.size;

// Store the end time of each chunk download with its size in array EndTimeData
if (calculationMode === Constants.ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING) {
if (calculationMode === Constants.ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING && !lastChunkWasFinished) {
lastChunkWasFinished = true;
endTimeData.push({
ts: performance.now(), /* jshint ignore:line */
Expand Down Expand Up @@ -285,43 +291,7 @@ function FetchLoader(cfg) {
}
}

// Compute the download time of a segment
function calculateDownloadedTime(calculationMode, startTimeData, endTimeData, downloadedData, bytesReceived) {
switch (calculationMode) {
case Constants.ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING:
return _calculateDownloadedTimeByMoofParsing(startTimeData, endTimeData);
case Constants.ABR_FETCH_THROUGHPUT_CALCULATION_DOWNLOADED_DATA:
return _calculateDownloadedTimeByBytesReceived(downloadedData, bytesReceived);
default:
return _calculateDownloadedTimeByBytesReceived(downloadedData, bytesReceived);
}
}

function _calculateDownloadedTimeByMoofParsing(startTimeData, endTimeData) {
try {
let datum, datumE;
// Filter the first and last chunks in a segment in both arrays [StartTimeData and EndTimeData]
datum = startTimeData.filter((data, i) => i > 0 && i < startTimeData.length - 1);
datumE = endTimeData.filter((dataE, i) => i > 0 && i < endTimeData.length - 1);
// Compute the download time of a segment based on the filtered data [last chunk end time - first chunk beginning time]
let segDownloadTime = 0;
if (datum.length > 1) {
for (let i = 0; i < datum.length; i++) {
if (datum[i] && datumE[i]) {
let chunkDownladTime = datumE[i].ts - datum[i].ts;
segDownloadTime += chunkDownladTime;
}
}

return segDownloadTime;
}
return null;
} catch (e) {
return null;
}
}

function _calculateDownloadedTimeByBytesReceived(downloadedData, bytesReceived) {
function calculateDownloadedTime(downloadedData, bytesReceived) {
try {
downloadedData = downloadedData.filter(data => data.bytes > ((bytesReceived / 4) / downloadedData.length));
if (downloadedData.length > 1) {
Expand All @@ -343,6 +313,51 @@ function FetchLoader(cfg) {
}
}

function calculateThroughputByChunkData(startTimeData, endTimeData) {
try {
let datum, datumE;
// Filter the last chunks in a segment in both arrays [StartTimeData and EndTimeData]
datum = startTimeData.filter((data, i) => i < startTimeData.length - 1);
datumE = endTimeData.filter((dataE, i) => i < endTimeData.length - 1);
let chunkThroughputs = [];
// Compute the average throughput of the filtered chunk data
if (datum.length > 1) {
let shortDurationBytesReceived = 0;
let shortDurationStartTime = 0;
for (let i = 0; i < datum.length; i++) {
if (datum[i] && datumE[i]) {
let chunkDownloadTime = datumE[i].ts - datum[i].ts;
if (chunkDownloadTime > 1) {
chunkThroughputs.push((8 * datumE[i].bytes) / chunkDownloadTime);
} else {
if (shortDurationStartTime === 0) {
shortDurationStartTime = datum[i].ts;
}
let cumulatedChunkDownloadTime = datumE[i].ts - shortDurationStartTime;
if (cumulatedChunkDownloadTime > 1) {
chunkThroughputs.push((8 * shortDurationBytesReceived) / cumulatedChunkDownloadTime);
shortDurationBytesReceived = 0;
shortDurationStartTime = 0;
} else {
// continue cumulating short duration data
shortDurationBytesReceived += datumE[i].bytes;
}
}
}
}

if (chunkThroughputs.length > 0) {
const sumOfChunkThroughputs = chunkThroughputs.reduce((a, b) => a + b, 0);
return sumOfChunkThroughputs / chunkThroughputs.length;
}
}

return null;
} catch (e) {
return null;
}
}

instance = {
load: load,
abort: abort,
Expand Down
3 changes: 2 additions & 1 deletion src/streaming/net/HTTPLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,8 @@ function HTTPLoader(cfg) {
traces.push({
s: lastTraceTime,
d: event.time ? event.time : currentTime.getTime() - lastTraceTime.getTime(),
b: [event.loaded ? event.loaded - lastTraceReceivedCount : 0]
b: [event.loaded ? event.loaded - lastTraceReceivedCount : 0],
t: event.throughput
});

lastTraceTime = currentTime;
Expand Down
30 changes: 23 additions & 7 deletions src/streaming/rules/ThroughputHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,11 @@ function ThroughputHistory(config) {

function setup() {
ewmaHalfLife = {
throughputHalfLife: { fast: EWMA_THROUGHPUT_FAST_HALF_LIFE_SECONDS, slow: EWMA_THROUGHPUT_SLOW_HALF_LIFE_SECONDS },
latencyHalfLife: { fast: EWMA_LATENCY_FAST_HALF_LIFE_COUNT, slow: EWMA_LATENCY_SLOW_HALF_LIFE_COUNT }
throughputHalfLife: {
fast: EWMA_THROUGHPUT_FAST_HALF_LIFE_SECONDS,
slow: EWMA_THROUGHPUT_SLOW_HALF_LIFE_SECONDS
},
latencyHalfLife: { fast: EWMA_LATENCY_FAST_HALF_LIFE_COUNT, slow: EWMA_LATENCY_SLOW_HALF_LIFE_COUNT }
};

reset();
Expand All @@ -86,14 +89,23 @@ function ThroughputHistory(config) {
const downloadTimeInMilliseconds = (httpRequest._tfinish.getTime() - httpRequest.tresponse.getTime()) || 1; //Make sure never 0 we divide by this value. Avoid infinity!
const downloadBytes = httpRequest.trace.reduce((a, b) => a + b.b[0], 0);

let throughputMeasureTime;
let throughputMeasureTime = 0, throughput = 0;
if (settings.get().streaming.lowLatencyEnabled) {
throughputMeasureTime = httpRequest.trace.reduce((a, b) => a + b.d, 0);
const calculationMode = settings.get().streaming.abr.fetchThroughputCalculationMode;
if (calculationMode === Constants.ABR_FETCH_THROUGHPUT_CALCULATION_MOOF_PARSING) {
const sumOfThroughputValues = httpRequest.trace.reduce((a, b) => a + b.t, 0);
throughput = Math.round(sumOfThroughputValues / httpRequest.trace.length);
}
if (throughput === 0) {
throughputMeasureTime = httpRequest.trace.reduce((a, b) => a + b.d, 0);
}
} else {
throughputMeasureTime = useDeadTimeLatency ? downloadTimeInMilliseconds : latencyTimeInMilliseconds + downloadTimeInMilliseconds;
}

const throughput = Math.round((8 * downloadBytes) / throughputMeasureTime); // bits/ms = kbits/s
if (throughputMeasureTime !== 0) {
throughput = Math.round((8 * downloadBytes) / throughputMeasureTime); // bits/ms = kbits/s
}

checkSettingsForMediaType(mediaType);

Expand Down Expand Up @@ -225,8 +237,12 @@ function ThroughputHistory(config) {
function checkSettingsForMediaType(mediaType) {
throughputDict[mediaType] = throughputDict[mediaType] || [];
latencyDict[mediaType] = latencyDict[mediaType] || [];
ewmaThroughputDict[mediaType] = ewmaThroughputDict[mediaType] || {fastEstimate: 0, slowEstimate: 0, totalWeight: 0};
ewmaLatencyDict[mediaType] = ewmaLatencyDict[mediaType] || {fastEstimate: 0, slowEstimate: 0, totalWeight: 0};
ewmaThroughputDict[mediaType] = ewmaThroughputDict[mediaType] || {
fastEstimate: 0,
slowEstimate: 0,
totalWeight: 0
};
ewmaLatencyDict[mediaType] = ewmaLatencyDict[mediaType] || { fastEstimate: 0, slowEstimate: 0, totalWeight: 0 };
}

function clearSettingsForMediaType(mediaType) {
Expand Down
5 changes: 5 additions & 0 deletions src/streaming/vo/metrics/HTTPRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,11 @@ class HTTPRequestTrace {
* @public
*/
this.b = [];
/**
* Measurement throughput in kbits/s
* @public
*/
this.t = null;
}
}

Expand Down
6 changes: 2 additions & 4 deletions test/unit/streaming.net.FetchLoader.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.