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

define common TxStatus Class #122

Merged
merged 5 commits into from
Jul 16, 2018
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
21 changes: 6 additions & 15 deletions benchmark/composer/composer-micro/query-asset.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'use strict';

const Util = require('../../../src/comm/util');
const TxStatus = require('../../../src/comm/transaction');

module.exports.info = 'Query Asset Performance Test';

Expand Down Expand Up @@ -80,29 +81,19 @@ module.exports.init = async function(blockchain, context, args) {
};

module.exports.run = function() {
let invoke_status = {
id : qryRef++,
status : 'created',
time_create : Date.now(),
time_final : 0,
time_endorse : 0,
time_order : 0,
result : null
};
let invoke_status = new TxStatus(qryRef++);

// use the pre-compiled query named 'selectAllCarsByColour' that is within the business
// network queries file
return busNetConnection.query('selectAllCarsByColour', { colour: matchColor})
.then((result) => {
invoke_status.status = 'success';
invoke_status.time_final = Date.now();
invoke_status.result = result;
invoke_status.SetStatusSuccess();
invoke_status.SetResult(result);
return Promise.resolve(invoke_status);
})
.catch((err) => {
invoke_status.time_final = Date.now();
invoke_status.status = 'failed';
invoke_status.result = [];
invoke_status.SetStatusFail();
invoke_status.SetResult([]);
return Promise.resolve(invoke_status);
});
};
Expand Down
2 changes: 1 addition & 1 deletion benchmark/drm/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ module.exports.run = function() {
module.exports.end = function(results) {
for (let i in results){
let stat = results[i];
if(stat.status === 'success') {
if(stat.IsCommitted()) {
ids.push(stat.result.toString());
}
}
Expand Down
4 changes: 2 additions & 2 deletions benchmark/simple/fabric-node.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"org1": {
"name": "peerOrg1",
"mspid": "Org1MSP",
"domain": "example.com",
"domain": "org1.example.com",
"user": {
"key": "network/fabric/simplenetwork/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/0d2b2fc385b10fa59003217e1bb5af2d24a3d762266e287867a1bc290eb44657_sk",
"cert": "network/fabric/simplenetwork/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]"
Expand All @@ -41,7 +41,7 @@
"org2": {
"name": "peerOrg2",
"mspid": "Org2MSP",
"domain": "example.com",
"domain": "org2.example.com",
"ca": {
"url": "https://localhost:8054",
"name": "ca-org2"
Expand Down
4 changes: 2 additions & 2 deletions benchmark/simple/fabric-remote.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"org1": {
"name": "peerOrg1",
"mspid": "Org1MSP",
"domain": "example.com",
"domain": "org1.example.com",
"msp": "network/fabric/simplenetwork/crypto-config/peerOrganizations/org1.example.com/msp/",
"ca": {
"url": "https://10.229.42.159:7054",
Expand All @@ -35,7 +35,7 @@
"org2": {
"name": "peerOrg2",
"mspid": "Org2MSP",
"domain": "example.com",
"domain": "org2.example.com",
"msp": "network/fabric/simplenetwork/crypto-config/peerOrganizations/org2.example.com/msp/",
"ca": {
"url": "https://10.229.42.159:8054",
Expand Down
4 changes: 2 additions & 2 deletions benchmark/simple/fabric.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"org1": {
"name": "peerOrg1",
"mspid": "Org1MSP",
"domain": "example.com",
"domain": "org1.example.com",
"user": {
"key": "network/fabric/simplenetwork/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/keystore/0d2b2fc385b10fa59003217e1bb5af2d24a3d762266e287867a1bc290eb44657_sk",
"cert": "network/fabric/simplenetwork/crypto-config/peerOrganizations/org1.example.com/users/[email protected]/msp/signcerts/[email protected]"
Expand All @@ -41,7 +41,7 @@
"org2": {
"name": "peerOrg2",
"mspid": "Org2MSP",
"domain": "example.com",
"domain": "org2.example.com",
"ca": {
"url": "https://localhost:8054",
"name": "ca-org2"
Expand Down
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
16 changes: 3 additions & 13 deletions src/comm/blockchain.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,16 +98,6 @@ class Blockchain {

/**
* Invoke smart contract/submit transactions and return corresponding transactions' status
* txStatus = {
* 'id': transaction's id
* 'status': status of the transaction, should be:
* - 'created': successfully created, but not validated or committed yet
* - 'success': successfully validated and committed in the ledger
* 'time_create': time(ms) that the transaction was created
* 'time_final': time(ms) that the transaction was known to be final and committed in ledger
* 'result': response payloads of the transaction request
* ...... : other adapter specific properties
* }
* @param {Object} context context object
* @param {String} contractID identiy of the contract
* @param {String} contractVer version of the contract
Expand Down Expand Up @@ -162,7 +152,7 @@ class Blockchain {
let delays = [];
for(let i = 0 ; i < results.length ; i++) {
let stat = results[i];
let create = stat.time_create;
let create = stat.GetTimeCreate();

if(typeof minCreate === 'undefined') {
minCreate = create;
Expand All @@ -177,9 +167,9 @@ class Blockchain {
}
}

if(stat.status === 'success') {
if(stat.IsCommitted()) {
succ++;
let final = stat.time_final;
let final = stat.GetTimeFinal();
let d = (final - create) / 1000;
if(typeof minFinal === 'undefined') {
minFinal = final;
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
Loading