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

Fix round index handling in rate controllers #747

Merged
merged 1 commit into from
Feb 28, 2020
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
11 changes: 5 additions & 6 deletions packages/caliper-core/lib/worker/rate-control/compositeRate.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,20 @@ class CompositeRateController extends RateInterface{

this.controllers = [];
this.activeControllerIndex = 0;
this.clientIdx = -1;
this.clientIdx = clientIdx + 1;
this.roundIndex = roundIdx;
this.controllerSwitch = null;
this.logControllerChange = (this.options.logChange &&
typeof(this.options.logChange) === 'boolean' && this.options.logChange) || false;

this.__prepareControllers(clientIdx, roundIdx);
this.__prepareControllers();
}

/**
* Internal method for preparing the controllers for further use.
* @param {number} clientIdx The 0-based index of the client who instantiates the controller.
* @param {number} roundIdx The 1-based index of the round the controller is instantiated in.
* @private
*/
__prepareControllers(clientIdx, roundIdx) {
__prepareControllers() {
let weights = this.options.weights;
let rateControllers = this.options.rateControllers;

Expand Down Expand Up @@ -136,7 +135,7 @@ class CompositeRateController extends RateInterface{
continue;
}

let info = new ControllerData(weights[i], rateControllers[i], new RateControl(rateControllers[i], clientIdx, roundIdx));
let info = new ControllerData(weights[i], rateControllers[i], new RateControl(rateControllers[i], this.clientIdx, this.roundIndex));
this.controllers.push(info);
}

Expand Down
5 changes: 2 additions & 3 deletions packages/caliper-core/lib/worker/rate-control/recordRate.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class RecordRateController extends RateInterface{
*/
constructor(opts, clientIdx, roundIdx) {
super(opts);
this.roundIdx = roundIdx;
this.clientIdx = clientIdx + 1;
this.records = [];

if (typeof opts.pathTemplate === 'undefined') {
Expand Down Expand Up @@ -137,9 +139,6 @@ class RecordRateController extends RateInterface{
* @async
*/
async init(msg) {
this.roundIdx = msg.roundIdx;
this.clientIdx = msg.clientIdx + 1;

// if we know the number of transactions beforehand, pre-allocate the array
if (msg.numb) {
this.records = new Array(msg.numb);
Expand Down
9 changes: 5 additions & 4 deletions packages/caliper-core/lib/worker/rate-control/replayRate.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,13 @@ class ReplayRateController extends RateInterface{
* Creates a new instance of the {ReplayRateController} class.
* @constructor
* @param {object} opts Options for the rate controller.
* @param {number} clientIdx The 0-based index of the client who instantiates the controller.
* @param {number} roundIdx The 1-based index of the round the controller is instantiated in.
*/
constructor(opts) {
constructor(opts, clientIdx, roundIdx) {
super(opts);
this.roundIdx = roundIdx;
this.clientIdx = clientIdx + 1;
this.records = [];

if (typeof opts.pathTemplate === 'undefined') {
Expand Down Expand Up @@ -123,9 +127,6 @@ class ReplayRateController extends RateInterface{
* @async
*/
async init(msg) {
this.roundIdx = msg.roundIdx;
this.clientIdx = msg.clientIdx + 1;

// resolve template path placeholders
this.pathTemplate = this.pathTemplate.replace(/<R>/gi, this.roundIdx.toString());
this.pathTemplate = this.pathTemplate.replace(/<C>/gi, this.clientIdx.toString());
Expand Down