Commit fd3bcd7f authored by Alexandra Rogova's avatar Alexandra Rogova

added timed index export bench

parent 9338d893
const puppeteer = require('puppeteer');
const Server = require('ws').Server;
const args = require("yargs")
.usage("Usage : export_index.js -file file_path")
.demandOption(['file'])
.alias("f", "file")
.describe("file", "file containing content, data must follow JSON standard")
.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_index.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_index.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_index.csv");
stream.write("items,zip,json\n");
var to_run = [{scriptPath : './export_index.js', args : ['-f' ,"./test_files/INDEX/index100000.json"], amount : 100000},
{scriptPath : './export_index.js', args : ['-f' ,"./test_files/INDEX/index50000.json"], amount : 50000},
{scriptPath : './export_index.js', args : ['-f' ,"./test_files/INDEX/index10000.json"], amount : 10000},
{scriptPath : './export_index.js', args : ['-f' ,"./test_files/INDEX/index5000.json"], amount : 5000},
{scriptPath : './export_index.js', args : ['-f' ,"./test_files/INDEX/index1000.json"], amount : 1000},
{scriptPath : './export_index.js', args : ['-f' ,"./test_files/INDEX/index100.json"], amount : 100}];
runScriptSync(to_run, function (err) {if (err) throw err;});
items,zip,json
100,0,0
1000,0,0.026
5000,0,0.041
10000,0,0.05
50000,0,0.12
100000,0,1.092
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