Skip to content

Commit

Permalink
Eliminate config path transfers between processes
Browse files Browse the repository at this point in the history
Signed-off-by: Attila Klenik <a.klenik@gmail.com>
  • Loading branch information
aklenik committed Nov 6, 2019
1 parent c9e4317 commit dd1d9d6
Show file tree
Hide file tree
Showing 19 changed files with 56 additions and 127 deletions.
17 changes: 2 additions & 15 deletions packages/caliper-burrow/lib/burrowClientFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,15 @@ const path = require('path');
*/
class BurrowClientFactory {

/**
* Require paths to configuration data used when calling new on fabric.js
* @param {String} absNetworkFile absolute workerPath
* @param {Sting} workspace_root root location
*/
constructor(absNetworkFile, workspace_root){
this.absNetworkFile = absNetworkFile;
this.workspaceRoot = workspace_root;
}


/**
* Spawn the worker and perform required init
* @returns {Object} the child process
*/
async spawnWorker() {
const child = childProcess.fork(path.join(__dirname, './burrowClientWorker.js'), process.argv.slice(1), { env: process.env});
const child = childProcess.fork(path.join(__dirname, './burrowClientWorker.js'), process.argv.slice(2), { env: process.env});

const msg = {
type: 'init',
absNetworkFile: this.absNetworkFile,
networkRoot: this.workspaceRoot
type: 'init'
};
child.send(msg);

Expand Down
7 changes: 5 additions & 2 deletions packages/caliper-burrow/lib/burrowClientWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const { CaliperLocalClient, CaliperUtils } = require('@hyperledger/caliper-core');
const { CaliperLocalClient, CaliperUtils, ConfigUtil } = require('@hyperledger/caliper-core');
const BurrowClient = require('./burrow');

let caliperClient;
Expand All @@ -31,7 +31,10 @@ process.on('message', async (message) => {
try {
switch (message.type) {
case 'init': {
const blockchain = new BurrowClient(message.absNetworkFile, message.networkRoot);
const networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig);
const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace);

const blockchain = new BurrowClient(networkConfigPath, workspacePath);
caliperClient = new CaliperLocalClient(blockchain);
process.send({ type: 'ready', data: { pid: process.pid, complete: true } });
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/caliper-cli/lib/benchmark/lib/runBenchmark.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class RunBenchmark {

const {AdminClient, ClientFactory} = require(`@hyperledger/caliper-${blockchainType}`);
const blockchainAdapter = new AdminClient(networkConfigPath, workspacePath);
const workerFactory = new ClientFactory(networkConfigPath, workspacePath);
const workerFactory = new ClientFactory();

const engine = new CaliperEngine(benchmarkConfig, networkConfig, blockchainAdapter, workerFactory);
const response = await engine.run();
Expand Down
17 changes: 2 additions & 15 deletions packages/caliper-composer/lib/composerClientFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,15 @@ const path = require('path');
*/
class ComposerClientFactory {

/**
* Require paths to configuration data used when calling new on fabric.js
* @param {String} absNetworkFile absolute workerPath
* @param {Sting} workspace_root root location
*/
constructor(absNetworkFile, workspace_root){
this.absNetworkFile = absNetworkFile;
this.workspaceRoot = workspace_root;
}


/**
* Spawn the worker and perform required init
* @returns {Object} the child process
*/
spawnWorker() {
const child = childProcess.fork(path.join(__dirname, './composerClientWorker.js'), process.argv.slice(1), { env: process.env});
const child = childProcess.fork(path.join(__dirname, './composerClientWorker.js'), process.argv.slice(2), { env: process.env});

const msg = {
type: 'init',
absNetworkFile: this.absNetworkFile,
networkRoot: this.workspaceRoot
type: 'init'
};
child.send(msg);

Expand Down
7 changes: 5 additions & 2 deletions packages/caliper-composer/lib/composerClientWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const {CaliperLocalClient, CaliperUtils} = require('@hyperledger/caliper-core');
const {CaliperLocalClient, CaliperUtils, ConfigUtil} = require('@hyperledger/caliper-core');
const ComposerClient = require('./composer');

let caliperClient;
Expand All @@ -31,7 +31,10 @@ process.on('message', async (message) => {
try {
switch (message.type) {
case 'init': {
const blockchain = new ComposerClient(message.absNetworkFile, message.networkRoot);
const networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig);
const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace);

const blockchain = new ComposerClient(networkConfigPath, workspacePath);
caliperClient = new CaliperLocalClient(blockchain);
process.send({type: 'ready', data: {pid: process.pid, complete: true}});
break;
Expand Down
2 changes: 1 addition & 1 deletion packages/caliper-core/lib/common/utils/logging-util.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ function _messageFormat() {
output = output.replace(labelRegex, info.label || '');
output = output.replace(moduleRegex, info.module || '');
output = output.replace(messageRegex, info.message || '');
return output.replace(metadataRegex, info.meta || '');
return output.replace(metadataRegex, info.metadata || '');
});
}

Expand Down
5 changes: 3 additions & 2 deletions packages/caliper-core/lib/master/caliper-engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,11 @@ class CaliperEngine {
constructor(benchmarkConfig, networkConfig, blockchainAdapter, workerFactory) {
this.benchmarkConfig = benchmarkConfig;
this.networkConfig = networkConfig;
this.blockchainAdapter = blockchainAdapter;
this.workerFactory = workerFactory;
this.workspace = ConfigUtils.get(ConfigUtils.keys.workspace);
this.returnCode = -1;

this.blockchainAdapter = blockchainAdapter;
this.workerFactory = workerFactory;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ const MonitorOrchestrator = require('../monitor/monitor-orchestrator');
const Report = require('../report/report');
const TestObserver = require('../test-observers/test-observer');
const CaliperUtils = require('../../common/utils/caliper-utils');
const ConfigUtils = require('../../common/config/config-util');
const logger = CaliperUtils.getLogger('round-orchestrator');

/**
Expand All @@ -39,8 +38,6 @@ class RoundOrchestrator {
this.networkConfig = networkConfig;
this.benchmarkConfig = benchmarkConfig;

this.workspace = ConfigUtils.get(ConfigUtils.keys.Workspace); // TODO: remove this

this.clientOrchestrator = new ClientOrchestrator(this.benchmarkConfig, workerFactory, workerArguments);
this.monitorOrchestrator = new MonitorOrchestrator(this.benchmarkConfig);
this.report = new Report(this.monitorOrchestrator, this.benchmarkConfig, this.networkConfig);
Expand Down Expand Up @@ -151,8 +148,6 @@ class RoundOrchestrator {
trim: round.trim || 0,
args: round.arguments,
cb: round.callback,
config: 'TODO', // TODO: remove this
root: this.workspace, // TODO: remove this
testRound: index,
pushUrl: this.monitorOrchestrator.hasMonitor('prometheus') ? this.monitorOrchestrator.getMonitor('prometheus').getPushGatewayURL() : null
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ class CaliperLocalClient {
*/
async doTest(test) {
Logger.debug('doTest() with:', test);
let cb = require(CaliperUtils.resolvePath(test.cb, test.root));
let cb = require(CaliperUtils.resolvePath(test.cb));

this.beforeTest(test);

Expand Down
17 changes: 2 additions & 15 deletions packages/caliper-ethereum/lib/ethereumClientFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,15 @@ const path = require('path');
*/
class EthereumClientFactory {

/**
* Require paths to configuration data used when calling new on fabric.js
* @param {String} absNetworkFile absolute workerPath
* @param {Sting} workspace_root root location
*/
constructor(absNetworkFile, workspace_root){
this.absNetworkFile = absNetworkFile;
this.workspaceRoot = workspace_root;
}


/**
* Spawn the worker and perform required init
* @returns {Object} the child process
*/
spawnWorker() {
const child = childProcess.fork(path.join(__dirname, './ethereumClientWorker.js'), process.argv.slice(1), { env: process.env});
const child = childProcess.fork(path.join(__dirname, './ethereumClientWorker.js'), process.argv.slice(2), { env: process.env});

const msg = {
type: 'init',
absNetworkFile: this.absNetworkFile,
networkRoot: this.workspaceRoot
type: 'init'
};
child.send(msg);

Expand Down
7 changes: 5 additions & 2 deletions packages/caliper-ethereum/lib/ethereumClientWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const {CaliperLocalClient, CaliperUtils} = require('@hyperledger/caliper-core');
const {CaliperLocalClient, CaliperUtils, ConfigUtil} = require('@hyperledger/caliper-core');
const EthereumClient = require('./ethereum');

let caliperClient;
Expand All @@ -31,7 +31,10 @@ process.on('message', async (message) => {
try {
switch (message.type) {
case 'init': {
const blockchain = new EthereumClient(message.absNetworkFile, message.networkRoot);
const networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig);
const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace);

const blockchain = new EthereumClient(networkConfigPath, workspacePath);
caliperClient = new CaliperLocalClient(blockchain);
process.send({type: 'ready', data: {pid: process.pid, complete: true}});
break;
Expand Down
17 changes: 2 additions & 15 deletions packages/caliper-fabric/lib/fabricClientFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,15 @@ const path = require('path');
*/
class FabricClientFactory {

/**
* Require paths to configuration data used when calling new on fabric.js
* @param {String} absNetworkFile absolute workerPath
* @param {Sting} workspace_root root location
*/
constructor(absNetworkFile, workspace_root){
this.absNetworkFile = absNetworkFile;
this.workspaceRoot = workspace_root;
}


/**
* Spawn the worker and perform required init
* @returns {Object} the child process
*/
spawnWorker() {
const child = childProcess.fork(path.join(__dirname, './fabricClientWorker.js'), process.argv.slice(1), { env: process.env});
const child = childProcess.fork(path.join(__dirname, './fabricClientWorker.js'), process.argv.slice(2), { env: process.env});

const msg = {
type: 'init',
absNetworkFile: this.absNetworkFile,
networkRoot: this.workspaceRoot
type: 'init'
};
child.send(msg);

Expand Down
7 changes: 5 additions & 2 deletions packages/caliper-fabric/lib/fabricClientWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const {CaliperLocalClient, CaliperUtils} = require('@hyperledger/caliper-core');
const {CaliperLocalClient, CaliperUtils, ConfigUtil } = require('@hyperledger/caliper-core');
const FabricClient = require('./fabric');

const logger = CaliperUtils.getLogger('fabric/fabricClientWorker');
Expand All @@ -32,7 +32,10 @@ process.on('message', async (message) => {
try {
switch (message.type) {
case 'init': {
const blockchain = new FabricClient(message.absNetworkFile, message.networkRoot);
const networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig);
const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace);

const blockchain = new FabricClient(networkConfigPath, workspacePath);
// reload the profiles silently
await blockchain._initializeRegistrars(false);
await blockchain._initializeAdmins(false);
Expand Down
15 changes: 2 additions & 13 deletions packages/caliper-fisco-bcos/lib/fiscoBcosClientFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,16 @@ const path = require('path');
* Class used to spawn FISCO BCOS client workers
*/
class FiscoBcosClientFactory {
/**
* Require paths to configuration data used when calling new on fiscoBcos.js
* @param {String} absNetworkFile absolute workerPath
* @param {Sting} workspace_root root location
*/
constructor(absNetworkFile, workspace_root) {
this.absNetworkFile = absNetworkFile;
this.workspaceRoot = workspace_root;
}

/**
* Spawn the worker and perform required init
* @returns {Object} the child process
*/
spawnWorker() {
const child = childProcess.fork(path.join(__dirname, './fiscoBcosClientWorker.js'), process.argv.slice(1), { env: process.env });
const child = childProcess.fork(path.join(__dirname, './fiscoBcosClientWorker.js'), process.argv.slice(2), { env: process.env });

const msg = {
type: 'init',
absNetworkFile: this.absNetworkFile,
networkRoot: this.workspaceRoot
type: 'init'
};
child.send(msg);

Expand Down
8 changes: 6 additions & 2 deletions packages/caliper-fisco-bcos/lib/fiscoBcosClientWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

const {
CaliperLocalClient,
CaliperUtils
CaliperUtils,
ConfigUtil
} = require('@hyperledger/caliper-core');
const fiscoBcosClient = require('./fiscoBcos');

Expand All @@ -37,7 +38,10 @@ process.on('message', async (message) => {
try {
switch (message.type) {
case 'init': {
const blockchain = new fiscoBcosClient(message.absNetworkFile, message.networkRoot);
const networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig);
const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace);

const blockchain = new fiscoBcosClient(networkConfigPath, workspacePath);
caliperClient = new CaliperLocalClient(blockchain);
process.send({
type: 'ready',
Expand Down
17 changes: 2 additions & 15 deletions packages/caliper-iroha/lib/irohaClientFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,28 +22,15 @@ const path = require('path');
*/
class IrohaClientFactory {

/**
* Require paths to configuration data used when calling new on fabric.js
* @param {String} absNetworkFile absolute workerPath
* @param {Sting} workspace_root root location
*/
constructor(absNetworkFile, workspace_root){
this.absNetworkFile = absNetworkFile;
this.workspaceRoot = workspace_root;
}


/**
* Spawn the worker and perform required init
* @returns {Object} the child process
*/
spawnWorker() {
const child = childProcess.fork(path.join(__dirname, './irohaClientWorker.js'), process.argv.slice(1), { env: process.env});
const child = childProcess.fork(path.join(__dirname, './irohaClientWorker.js'), process.argv.slice(2), { env: process.env});

const msg = {
type: 'init',
absNetworkFile: this.absNetworkFile,
networkRoot: this.workspaceRoot
type: 'init'
};
child.send(msg);

Expand Down
7 changes: 5 additions & 2 deletions packages/caliper-iroha/lib/irohaClientWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

'use strict';

const {CaliperLocalClient, CaliperUtils} = require('@hyperledger/caliper-core');
const {CaliperLocalClient, CaliperUtils, ConfigUtil} = require('@hyperledger/caliper-core');
const IrohaClient = require('./iroha');

let caliperClient;
Expand All @@ -31,7 +31,10 @@ process.on('message', async (message) => {
try {
switch (message.type) {
case 'init': {
const blockchain = new IrohaClient(message.absNetworkFile, message.networkRoot);
const networkConfigPath = ConfigUtil.get(ConfigUtil.keys.NetworkConfig);
const workspacePath = ConfigUtil.get(ConfigUtil.keys.Workspace);

const blockchain = new IrohaClient(networkConfigPath, workspacePath);
caliperClient = new CaliperLocalClient(blockchain);
process.send({type: 'ready', data: {pid: process.pid, complete: true}});
break;
Expand Down
Loading

0 comments on commit dd1d9d6

Please sign in to comment.