Skip to content

Commit

Permalink
reduce memory usage
Browse files Browse the repository at this point in the history
Signed-off-by: Haojun Zhou <[email protected]>
  • Loading branch information
Haojun Zhou committed Jul 13, 2018
1 parent fabf974 commit df2569c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 33 deletions.
14 changes: 8 additions & 6 deletions src/comm/bench-flow.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ function printTable(value) {
* @return {Array} row of the title
*/
function getResultTitle() {
// TODO: allow configure percentile value
return ['Name', 'Succ', 'Fail', 'Send Rate', 'Max Latency', 'Min Latency', 'Avg Latency', '75%ile Latency', 'Throughput'];
// temporarily remove percentile return ['Name', 'Succ', 'Fail', 'Send Rate', 'Max Latency', 'Min Latency', 'Avg Latency', '75%ile Latency', 'Throughput'];
return ['Name', 'Succ', 'Fail', 'Send Rate', 'Max Latency', 'Min Latency', 'Avg Latency', 'Throughput'];
}

/**
Expand All @@ -105,20 +105,22 @@ function getResultValue(r) {
row.push(r.delay.max.toFixed(2) + ' s');
row.push(r.delay.min.toFixed(2) + ' s');
row.push((r.delay.sum / r.succ).toFixed(2) + ' s');
if(r.delay.detail.length === 0) {
// temporarily remove percentile
/*if(r.delay.detail.length === 0) {
row.push('N/A');
}
else{
r.delay.detail.sort(function(a, b) {
return a-b;
});
row.push(r.delay.detail[Math.floor(r.delay.detail.length * 0.75)].toFixed(2) + ' s');
}
}*/

(r.final.max === r.final.min) ? row.push(r.succ + ' tps') : row.push(((r.succ / (r.final.max - r.create.min)).toFixed(0)) + ' tps');
}
catch (err) {
row = [r.label, 0, 0, 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'];
// temporarily remove percentile row = [r.label, 0, 0, 'N/A', 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'];
row = [r.label, 0, 0, 'N/A', 'N/A', 'N/A', 'N/A', 'N/A'];
}

return row;
Expand Down Expand Up @@ -158,7 +160,7 @@ function processResult(results, label){
resultTable[0] = getResultTitle();
let r;
if(Blockchain.mergeDefaultTxStats(results) === 0) {
r = Blockchain.createNullDefaultTxStats;
r = Blockchain.createNullDefaultTxStats();
r.label = label;
}
else {
Expand Down
87 changes: 60 additions & 27 deletions src/comm/client/local-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ let blockchain;
let results = [];
let txNum = 0;
let txLastNum = 0;
let txUpdateTail = 0;
let resultStats = [];
let txUpdateTime = 1000;
let trimType = 0;
let trim = 0;
let startTime = 0;

/**
* Calculate realtime transaction statistics and send the txUpdated message
Expand All @@ -28,8 +31,9 @@ function txUpdate() {
let newNum = txNum - txLastNum;
txLastNum += newNum;

let newResults = results.slice(txUpdateTail);
txUpdateTail += newResults.length;

let newResults = results.slice(0);
results = [];
if(newResults.length === 0 && newNum === 0) {
return;
}
Expand All @@ -42,6 +46,32 @@ function txUpdate() {
newStats = blockchain.getDefaultTxStats(newResults, false);
}
process.send({type: 'txUpdated', data: {submitted: newNum, committed: newStats}});

if (resultStats.length === 0) {
switch (trimType) {
case 0: // no trim
resultStats[0] = newStats;
break;
case 1: // based on duration
if (trim < (Date.now() - startTime)/1000) {
resultStats[0] = newStats;
}
break;
case 2: // based on number
if (trim < newResults.length) {
newResults = newResults.slice(trim);
newStats = blockchain.getDefaultTxStats(newResults, false);
resultStats[0] = newStats;
trim = 0;
} else {
trim -= newResults.length;
}
break;
}
} else {
resultStats[1] = newStats;
bc.mergeDefaultTxStats(resultStats);
}
}

/**
Expand All @@ -61,12 +91,25 @@ function addResult(result) {

/**
* Call before starting a new test
* @param {JSON} msg start test message
*/
function beforeTest() {
function beforeTest(msg) {
results = [];
txNum = 0;
txUpdateTail = 0;
resultStats = [];
txNum = 0;
txLastNum = 0;

// conditionally trim beginning and end results for this test run
if (msg.trim) {
if (msg.txDuration) {
trimType = 1;
} else {
trimType = 2;
}
trim = msg.trim;
} else {
trimType = 0;
}
}

/**
Expand All @@ -90,15 +133,15 @@ async function runFixedNumber(msg, cb, context) {
rateControl.init(msg);

await cb.init(blockchain, context, msg.args);
const start = Date.now();
startTime = Date.now();

let promises = [];
while(txNum < msg.numb) {
promises.push(cb.run().then((result) => {
addResult(result);
return Promise.resolve();
}));
await rateControl.applyRateControl(start, txNum, results);
await rateControl.applyRateControl(startTime, txNum, results);
}

await Promise.all(promises);
Expand All @@ -120,15 +163,15 @@ async function runDuration(msg, cb, context) {
const duration = msg.txDuration; // duration in seconds

await cb.init(blockchain, context, msg.args);
const start = Date.now();
startTime = Date.now();

let promises = [];
while ((Date.now() - start)/1000 < duration) {
while ((Date.now() - startTime)/1000 < duration) {
promises.push(cb.run().then((result) => {
addResult(result);
return Promise.resolve();
}));
await rateControl.applyRateControl(start, txNum, results);
await rateControl.applyRateControl(startTime, txNum, results);
}

await Promise.all(promises);
Expand All @@ -146,7 +189,7 @@ function doTest(msg) {
let cb = require(path.join(__dirname, '../../..', msg.cb));
blockchain = new bc(path.join(__dirname, '../../..', msg.config));

beforeTest();
beforeTest(msg);
// start an interval to report results repeatedly
let txUpdateInter = setInterval(txUpdate, txUpdateTime);
/**
Expand Down Expand Up @@ -183,22 +226,12 @@ function doTest(msg) {
clearUpdateInter();
return cb.end(results);
}).then(() => {
// conditionally trim beginning and end results for this test run
if (msg.trim) {
let trim;
if (msg.txDuration) {
// Considering time based number of transactions
trim = Math.floor(msg.trim * (results.length / msg.txDuration));
} else {
// Considering set number of transactions
trim = msg.trim;
}
let safeCut = (2 * trim) < results.length ? trim : results.length;
results = results.slice(safeCut, results.length - safeCut);
if (resultStats.length > 0) {
return Promise.resolve(resultStats[0]);
}
else {
return Promise.resolve(bc.createNullDefaultTxStats());
}

let stats = blockchain.getDefaultTxStats(results, true);
return Promise.resolve(stats);
}).catch((err) => {
clearUpdateInter();
log('Client ' + process.pid + ': error ' + (err.stack ? err.stack : err));
Expand Down

0 comments on commit df2569c

Please sign in to comment.