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

Further approach for measurement and estimation of throughput calculation in LL CTE streaming #3660

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
100 changes: 100 additions & 0 deletions build/helpers/LLsegment.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
const fs = require("fs");
const path = require("path");

const segmentData = fs.readFileSync(path.join(__dirname, 'data', 'chunk', 'chunk-stream_0-00001.m4s'));
const segmentInfo = fs.readFileSync(path.join(__dirname, 'data', 'chunk', 'chunk-stream_0-00001.json')).toString();

function sendChunks(res, segmentInfoData, param, interval, previousTs, chunkDistances) {
let chunksInBurst = 0;
if (param.chunksAvailableAtReqTime) {
chunksInBurst = param.chunksAvailableAtReqTime;
param.chunksAvailableAtReqTime = 0;
} else {
chunksInBurst = param.chunkCount;
}

for (let index = 0; index < chunksInBurst; index++) {
let mdatFound = false;
let chunkSize = 0;
while (!mdatFound && segmentInfoData.length) {
let box = segmentInfoData.shift();
mdatFound = box.name === 'mdat';
chunkSize += box.size;
}
if (chunkSize) {
res.write(segmentData.slice(param.pos, param.pos + chunkSize));
param.pos = param.pos + chunkSize;
}
}
if (!segmentInfoData.length) {
if (chunkDistances && chunkDistances.length) {
// console.log('all sent with average chunk (burst) distance', chunkDistances.reduce((prev, curr) => prev + curr, 0) / chunkDistances.length)
}
return res.end();
}

let processingDuration = 0;
const chunkDistance = Date.now() - previousTs;
// console.log('ms since last call', chunkDistance)

if (chunkDistance > interval) {
chunkDistances.push(chunkDistance)
processingDuration = chunkDistance - interval;
}
if (interval - processingDuration > 0) {
setTimeout((previousTs) => {
sendChunks(res, segmentInfoData, param, interval, previousTs, chunkDistances);
}, interval - processingDuration, Date.now()); // minus processing duration on producer side
}
}

function streamWithPattern(res, interval, chunkCount, chunksAvailableAtReqTime) {
const segmentInfoData = JSON.parse(segmentInfo);

res.statusCode = 200;

const param = {
chunkCount,
pos: 0,
chunksAvailableAtReqTime
}

sendChunks(res, segmentInfoData, param, interval, Date.now(), []);
}


module.exports = function (req, res) {
switch (req.url) {
case '/ll/pattern0':
streamWithPattern(res, 0, 0, 60);
break;
case '/ll/pattern1':
streamWithPattern(res, 33, 1, 0);
break;
case '/ll/pattern2':
streamWithPattern(res, 133, 4, 0);
break;
case '/ll/pattern3':
streamWithPattern(res, 333, 10, 0);
break;
case '/ll/pattern4':
streamWithPattern(res, 1000, 30, 0);
break;
case '/ll/pattern5':
streamWithPattern(res, 33, 1, 30);
break;
case '/ll/pattern6':
streamWithPattern(res, 133, 4, 30);
break;
case '/ll/pattern7':
streamWithPattern(res, 333, 10, 30);
break;
case '/ll/pattern8':
streamWithPattern(res, 1000, 30, 30);
break;
default:
console.log('unknown', req.url);
res.statusCode = 404;
return res.end();
}
};
Loading