Skip to content
This repository has been archived by the owner on Aug 25, 2021. It is now read-only.

Commit

Permalink
Merge pull request #281 from midwayjs/fix_client_oom
Browse files Browse the repository at this point in the history
fix: fix client oom by repeat create metric object
  • Loading branch information
guangwong authored Dec 11, 2018
2 parents b0ac916 + 1aa4166 commit 8f535fb
Showing 1 changed file with 25 additions and 10 deletions.
35 changes: 25 additions & 10 deletions packages/metrics/src/MetricsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,32 +154,47 @@ export class MetricsClient extends AbstractIndicator {
}

getCounter(group: string, name: MetricName | string) {
const counter = new Counter();
this.register(group, name, counter);
let counter = this.allMetricsRegistry.getMetric(this.buildName(name));
if (!counter) {
counter = new Counter();
this.register(group, name, counter);
}
return counter;
}

getTimer(group: string, name: MetricName | string) {
const timer = new Timer();
this.register(group, name, timer);
let timer = this.allMetricsRegistry.getMetric(this.buildName(name));
if (!timer) {
timer = new Timer();
this.register(group, name, timer);
}
return timer;
}

getMeter(group: string, name: MetricName | string) {
const meter = new Meter();
this.register(group, name, meter);
let meter = this.allMetricsRegistry.getMetric(this.buildName(name));
if (!meter) {
meter = new Meter();
this.register(group, name, meter);
}
return meter;
}

getHistogram(group: string, name: MetricName | string) {
const histogram = new Histogram();
this.register(group, name, histogram);
let histogram = this.allMetricsRegistry.getMetric(this.buildName(name));
if (!histogram) {
histogram = new Histogram();
this.register(group, name, histogram);
}
return histogram;
}

getFastCompass(group: string, name: MetricName | string) {
const fastCompass = new FastCompass();
this.register(group, name, fastCompass);
let fastCompass = this.allMetricsRegistry.getMetric(this.buildName(name));
if (!fastCompass) {
fastCompass = new FastCompass();
this.register(group, name, fastCompass);
}
return fastCompass;
}

Expand Down

0 comments on commit 8f535fb

Please sign in to comment.