Skip to content

Commit

Permalink
Merge pull request #747 from aklenik/fix-rate-index
Browse files Browse the repository at this point in the history
Fix round index handling in rate controllers
  • Loading branch information
aklenik authored Feb 28, 2020
2 parents fc3e458 + edacbdc commit f19275a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 13 deletions.
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

0 comments on commit f19275a

Please sign in to comment.