Skip to content

Commit

Permalink
optimize perf.
Browse files Browse the repository at this point in the history
  • Loading branch information
icebob committed Apr 12, 2017
1 parent 2b3ee83 commit 6f255a2
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
4 changes: 2 additions & 2 deletions benchmark/perf-runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ let Serializer = require("../src/serializers/json");
function createBrokers(Transporter, opts) {
let b1 = new ServiceBroker({
transporter: new Transporter(opts),
requestTimeout: 0,
//requestTimeout: 0,
//logger: console,
//logLevel: "debug",
serializer: new Serializer(),
Expand Down Expand Up @@ -43,7 +43,7 @@ let [b1, b2] = createBrokers(Transporters.Fake);
let count = 0;
function doRequest() {
count++;
return b1.call("echo.reply", { a: count }).then(res => {
return b2.call("echo.reply", { a: count }).then(res => {
if (count % 10000) {
// Fast cycle
doRequest();
Expand Down
2 changes: 1 addition & 1 deletion src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Context {
this.nodeID = opts.nodeID;
this.parentID = opts.parent ? opts.parent.id : null;

this.metrics = opts.metrics || false;
this.metrics = !!opts.metrics;
this.level = opts.level || (opts.parent && opts.parent.level ? opts.parent.level + 1 : 1);

this.setParams(opts.params);
Expand Down
14 changes: 8 additions & 6 deletions src/service-broker.js
Original file line number Diff line number Diff line change
Expand Up @@ -654,19 +654,21 @@ class ServiceBroker {
ctx.nodeID = nodeID;
} else {
// New root context
ctx = new this.ContextFactory({
const ctxOpts = {
broker: this,
action,
params,
nodeID,
requestID: opts.requestID,
metrics: this.shouldMetric(),
metrics: this.shouldMetric(),
parent: opts.parentCtx,
meta: opts.meta,
meta: opts.meta
// bad performance above 8 props
};

timeout: opts.timeout,
retryCount: opts.retryCount
});
ctx = new this.ContextFactory(ctxOpts);
ctx.timeout = opts.timeout;
ctx.retryCount = opts.retryCount;
}

// Add metrics start
Expand Down

0 comments on commit 6f255a2

Please sign in to comment.