Commit adb78155 authored by Alexandra Rogova's avatar Alexandra Rogova

added timed content export bench

parent fd3bcd7f
const puppeteer = require('puppeteer');
const Server = require('ws').Server;
const args = require("yargs")
.usage("Usage : export_content.js -file file_path")
.demandOption(['file'])
.alias("f", "file")
.describe("file", "file containing content, data must be ZIP")
.nargs("file", 1)
.argv;
var browser,
start,
zip,
plain_start,
plain;
function init_server (){
var port = 9030;
var ws = new Server({port: port});
ws.on('connection', function(w){
w.on('message', function(msg){
if (msg === "Start"){
start = Date.now();
} else if (msg === "Zip"){
zip = Date.now() - start;
plain_start = Date.now();
} else if (msg === "JSON"){
plain = Date.now() - plain_start;
process.send(zip/1000 + "," +plain/1000);
ws.close();
browser.close();
} else {
console.log("Error : " + msg);
browser.close();
}
});
w.on('close', function() {
ws.close();
});
});
}
(async () => {
init_server();
browser = await puppeteer.launch();
var page = await browser.newPage();
await page.goto('https://softinst115787.host.vifib.net/public/unit_tests/export_content.html');
const [fileChooser] = await Promise.all([
page.waitForFileChooser(),
page.click('input#load')
]);
await fileChooser.accept([args.file]);
})();
var childProcess = require('child_process');
const fs = require('fs');
var stream = fs.createWriteStream("./results/export_content.csv", {flags:'a'});
function writeResult(items, info){
stream.write(items + "," + info + "\n");
}
function runScriptSync(list, callback) {
if (list.length === 0) return;
var invoked = false,
to_run = list.pop();
process = childProcess.fork(to_run.scriptPath, to_run.args);
process.on('message', function (mes){
console.log(to_run.amount + " : " + mes)
writeResult(to_run.amount, mes);
runScriptSync(list, callback);
});
process.on('error', function (err) {
if (invoked) return;
invoked = true;
callback(err);
});
process.on('exit', function (code) {
if (invoked) return;
invoked = true;
var err = code === 0 ? null : new Error('exit code ' + code);
callback(err);
});
}
fs.truncateSync("./results/export_content.csv");
stream.write("items,zip,json\n");
var to_run = [{scriptPath : './export_content.js', args : ['-f' ,"./test_files/CONTENT/content100000.zip"], amount : 100000},
{scriptPath : './export_content.js', args : ['-f' ,"./test_files/CONTENT/content10000.zip"], amount : 10000},
{scriptPath : './export_content.js', args : ['-f' ,"./test_files/CONTENT/content1000.zip"], amount : 1000},
{scriptPath : './export_content.js', args : ['-f' ,"./test_files/CONTENT/content100.zip"], amount : 100}];
runScriptSync(to_run, function (err) {if (err) throw err;});
items,zip,json
100,0.016,0.01
1000,0.063,0.028
10000,0.699,0.029
100000,9.51,0.023
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment