Skip to content

Commit

Permalink
hard code
Browse files Browse the repository at this point in the history
Signed-off-by: SamYuan1990 <yy19902439@126.com>
  • Loading branch information
SamYuan1990 committed Oct 23, 2020
1 parent be200d9 commit 40c216d
Show file tree
Hide file tree
Showing 7 changed files with 117 additions and 39 deletions.
3 changes: 2 additions & 1 deletion .gitignore
@@ -1 +1,2 @@
node_modules
node_modules
vars
10 changes: 5 additions & 5 deletions config.yaml
@@ -1,15 +1,15 @@
# Definition of nodes
peer1: &peer1
addr: peer1.org0.example.com:7051
tls_ca_cert: /config/minifabric/vars/keyfiles/peerOrganizations/org0.example.com/msp/tlscacerts/tlsca1.org0.example.com-cert.pem
tls_ca_cert: /config/vars/keyfiles/peerOrganizations/org0.example.com/msp/tlscacerts/tlsca1.org0.example.com-cert.pem

peer2: &peer2
addr: peer1.org1.example.com:7051
tls_ca_cert: /config/minifabric/vars/keyfiles/peerOrganizations/org1.example.com/msp/tlscacerts/tlsca1.org1.example.com-cert.pem
tls_ca_cert: /config/vars/keyfiles/peerOrganizations/org1.example.com/msp/tlscacerts/tlsca1.org1.example.com-cert.pem

orderer1: &orderer1
addr: orderer1.example.com:7050
tls_ca_cert: /config/minifabric/vars/keyfiles/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem
tls_ca_cert: /config/vars/keyfiles/ordererOrganizations/example.com/msp/tlscacerts/tlsca.example.com-cert.pem

# Nodes to interact with
endorsers:
Expand All @@ -29,8 +29,8 @@ args:
- a
mspid: org0-example-com

private_key: /config/minifabric/vars/keyfiles/peerOrganizations/org0.example.com/users/Admin@org0.example.com/msp/keystore/priv_sk
sign_cert: /config/minifabric/vars/keyfiles/peerOrganizations/org0.example.com/users/Admin@org0.example.com/msp/signcerts/Admin@org0.example.com-cert.pem
private_key: /config/vars/keyfiles/peerOrganizations/org0.example.com/users/Admin@org0.example.com/msp/keystore/priv_sk
sign_cert: /config/vars/keyfiles/peerOrganizations/org0.example.com/users/Admin@org0.example.com/msp/signcerts/Admin@org0.example.com-cert.pem
num_of_conn: 10
client_per_conn: 10

76 changes: 63 additions & 13 deletions lib/libs.js
@@ -1,7 +1,6 @@
const fs = require('fs');
const path = require('path');
const parse = require('csv-parse/lib/sync');
const sleep = require('system-sleep');
const process = require('child_process');

exports.BatchTimeout = 'BatchTimeout'
Expand Down Expand Up @@ -64,8 +63,8 @@ tapeCount
*/
exports.run = function run(CmdInfo,BatchTimeout,MaxMessageCount,AbsoluteMaxBytes,PreferredMaxBytes){
var tapeCmd = 'docker';
var startup;
var teardown;
var startup = '/minifab';
var teardown = '/minifab';
BatchTimeout.forEach(BatchTimeoutElement =>{
MaxMessageCount.forEach(MaxMessageCountElement => {
AbsoluteMaxBytes.forEach(AbsoluteMaxBytesElement => {
Expand All @@ -77,24 +76,71 @@ exports.run = function run(CmdInfo,BatchTimeout,MaxMessageCount,AbsoluteMaxBytes
AbsoluteMaxBytes:AbsoluteMaxBytesElement,
PreferredMaxBytes:PreferredMaxBytesElement,
}
startup(startup,TurnInfo);
tapeTPS = tapeTPS(CmdInfo,tapeCmd);
TPS = convertTPS(tapeTPS);
teardown(teardown);
this.startup(startup,TurnInfo);
TPS = this.tapeTPS(CmdInfo,tapeCmd);
this.teardown(teardown);
//'sample,0.75,10,2,256, 180.038278,'
appendRS(TurnInfo.Chaincode+','+
this.appendRS(TurnInfo.Chaincode+','+
TurnInfo.BatchTimeout+','+
TurnInfo.MaxMessageCountElement+','+
TurnInfo.AbsoluteMaxBytesElement+','+
TurnInfo.PreferredMaxBytesElement+','+
TurnInfo.MaxMessageCount+','+
TurnInfo.AbsoluteMaxBytes+','+
TurnInfo.PreferredMaxBytes+','+
TPS+',');
sleep(CmdInfo.Sleep*1000);
console.log('start cold down');
this.sleep();
console.log('end of cold down');
})
})
})
});
}

exports.sleep = function sleep(){
rs = process.spawnSync('sleep',['10']);
console.log(rs.status);
if (rs.status !=0) {
console.log(rs);
console.log(rs.stderr.toString('utf-8'));
}
return rs.status;
}

exports.startup = function startup(startup,TurnInfo){
//./prepareConfig.sh $BatchTimeout $MaxMessageCount $AbsoluteMaxBytes $PreferredMaxBytes -n $chaincode
rs = process.spawnSync(path.resolve('./minifabric')+'/prepareConfig.sh',[
TurnInfo.BatchTimeout,
TurnInfo.MaxMessageCount,
TurnInfo.AbsoluteMaxBytes,
TurnInfo.PreferredMaxBytes,
'-n',
TurnInfo.Chaincode,
]);
console.log(rs.status);

rs = process.spawnSync('mv',[
'-f',
path.resolve('./')+'/spec.yaml',
path.resolve('./minifabric/')+'/spec.yaml'
]);
console.log(rs.status);
rs = process.spawnSync(path.resolve('./minifabric/')+startup,['up']);
if (rs.status !=0) {
console.log(rs.stderr.toString());
}
console.log(rs.status);
return rs.status;
}

exports.teardown = function teardown(teardown){
rs = process.spawnSync(path.resolve('./minifabric/')+teardown,['cleanup']);
console.log(rs.status);
if (rs.status !=0) {
console.log(rs);
console.log(rs.stderr.toString('utf-8'));
}
return rs.status;
}

// docker run --name tape -e TAPE_LOGLEVEL=debug --network minifab -v $PWD:/config tape tape /config/config.yaml 500
exports.tapeTPS = function tapeTPS(CmdInfo,tapeCmd){
rs = process.spawnSync(tapeCmd,[
Expand All @@ -110,11 +156,15 @@ exports.tapeTPS = function tapeTPS(CmdInfo,tapeCmd){
'tape',
'tape',
'/config/config.yaml',
500//CmdInfo.tapeConfig,CmdInfo.tapeCount
5000//CmdInfo.tapeConfig,CmdInfo.tapeCount
]);
if (rs.status != 0) {
console.log(rs.stderr.toString());
}
str=rs.output.toString('utf-8',0);
str = str.substring(str.indexOf('tps:'));
str = str.substring(0,str.indexOf('\n'));
str = str.substring(4);
console.log(str);
return str;
}
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -5,7 +5,7 @@
"main": "app.js",
"scripts": {
"start": "node ./bin/www",
"test": "export NODE_ENV=test PORT=3300 && mocha 'test/**/*.test.js' --exit"
"test": "export NODE_ENV=test PORT=3300 && mocha 'test/**/*.test.js' --timeout 1200000 --exit"
},
"repository": {
"type": "git",
Expand Down
28 changes: 11 additions & 17 deletions routes/api.js
Expand Up @@ -28,24 +28,18 @@ router.get('/getTPS', function(req, res, next) {
});

router.get('/run', function(req, res, next) {
var d = new Date();
libs.init();
libs.appendRS('sample,0.75,10,2,256, 180.038278,');
libs.appendRS('sample,0.75,40,2,256, 291.310916,');
libs.appendRS('sample,0.75,80,2,256, 333.041573,');
libs.appendRS('sample,0.75,120,2,256, 351.752320,');
libs.appendRS('sample,1,10,2,256, 172.872861,');
libs.appendRS('sample,1,40,2,256, 291.617799,');
libs.appendRS('sample,1,80,2,256, 337.826232,');
libs.appendRS('sample,1,120,2,256, 319.039588,');
libs.appendRS('sample,2,10,2,256, 182.105577,');
libs.appendRS('sample,2,40,2,256, 260.276446,');
libs.appendRS('sample,2,80,2,256, 323.542760,');
libs.appendRS('sample,2,120,2,256, 323.526945,');
libs.appendRS('sample,1.5,10,2,256, 172.745382,');
libs.appendRS('sample,1.5,40,2,256, 268.041591,');
libs.appendRS('sample,1.5,80,2,256, 348.150198,');
libs.appendRS('sample,1.5,120,2,256, 310.915616,');
res.send('success');
CmdInfo = {
Chaincode:'sample',
}
BatchTimeout = [2,4];
MaxMessageCount = [20];
AbsoluteMaxBytes= [10];
PreferredMaxBytes= [10];
libs.run(CmdInfo,BatchTimeout,MaxMessageCount,AbsoluteMaxBytes,PreferredMaxBytes);
//console.log(new Date().toString());
res.send(d.toString()+' success at '+new Date().toString());
});

module.exports = router;
4 changes: 2 additions & 2 deletions test/app.test.js
Expand Up @@ -12,11 +12,11 @@ describe('# test app.js', function () {
.get('/api')
.expect(200, done)
});
it('GET /api/run', function (done) {
/*it('GET /api/run', function (done) {
request
.get('/api/run')
.expect(200, done)
});
});*/
it('GET /api/getBatchTimeout', function (done) {
request
.get('/api/getBatchTimeout')
Expand Down
33 changes: 33 additions & 0 deletions test/lib.test.js
Expand Up @@ -2,6 +2,32 @@ const libs = require('../lib/libs');
var expect = require('chai').expect;

describe('# libs', function () {
/*it('run', function(done){
CmdInfo = {
Chaincode:'sample',
}
BatchTimeout = [2];
MaxMessageCount = [20];
AbsoluteMaxBytes= [10];
PreferredMaxBytes= [10];
libs.run(CmdInfo,BatchTimeout,MaxMessageCount,AbsoluteMaxBytes,PreferredMaxBytes);
done();
})
*/
/*
it('start', function(done){
var TurnInfo = {
Chaincode:'sample',
BatchTimeout:2,
MaxMessageCount:200,
AbsoluteMaxBytes:2,
PreferredMaxBytes:2,
}
var startup = '/minifab';
rs = libs.startup(startup,TurnInfo);
expect(true).to.deep.equal(parseFloat(rs) === 0);
done();
});
it('tapeTPS', function(done){
var CmdInfo = {
Expand All @@ -14,6 +40,13 @@ describe('# libs', function () {
done();
})
it('tear down', function(done){
var teardown = '/minifab';
rs = libs.teardown(teardown);
expect(true).to.deep.equal(parseFloat(rs) === 0);
done();
});
*/
it('appendRS', function(done){
libs.init();
libs.appendRS('sample,0.75,10,2,256, 180.038278,');
Expand Down

0 comments on commit 40c216d

Please sign in to comment.