Skip to content

Commit 01dfb4d

Browse files
author
Petr Pchelko
authored
Remove GC stats feature (#240)
The feature emits metrics about garbage collection. To my knowledge these metrics have never benefitted anyone in 5 years of their existance. Now gc-stats package used to collect the metric has issues, so let's just remove the feature entirely.
1 parent 6583eeb commit 01dfb4d

File tree

3 files changed

+1
-66
lines changed

3 files changed

+1
-66
lines changed

lib/heapwatch.js

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,6 @@
22

33
const cluster = require('cluster');
44

5-
const ZERO_CUMULATIVE_GC_INTERVAL = {
6-
minor: 0,
7-
major: 0,
8-
incremental: 0,
9-
weak: 0
10-
};
11-
const GC_REPORT_INTERVAL = 1000;
12-
135
class HeapWatch {
146
constructor(conf, logger, metrics) {
157
this.conf = conf = conf || {};
@@ -19,55 +11,6 @@ class HeapWatch {
1911
this.checkInterval = 60000; // Once per minute
2012
this.failCount = 0;
2113
this.timeoutHandle = undefined;
22-
this.gcReportInterval = undefined;
23-
this.cumulativeGCTimes = Object.assign({}, ZERO_CUMULATIVE_GC_INTERVAL);
24-
this.reportStatsHandler = (stats) => {
25-
// Report GC timings to statsd (in nanoseconds).
26-
const type = this._gcTypeName(stats.gctype);
27-
if (type !== 'unknown') {
28-
this.cumulativeGCTimes[this._gcTypeName(stats.gctype)] += stats.pause;
29-
}
30-
};
31-
this._gcStats = null;
32-
}
33-
34-
_gcTypeName(typeID) {
35-
switch (typeID) {
36-
case 1: return 'minor';
37-
case 2: return 'major';
38-
case 4: return 'incremental';
39-
case 8: return 'weak';
40-
case 15: return 'all';
41-
default: return 'unknown';
42-
}
43-
}
44-
45-
setGCMonitor() {
46-
try {
47-
this._gcStats = require('gc-stats')();
48-
this._gcStats.on('stats', this.reportStatsHandler);
49-
this.gcReportInterval = setInterval(() => {
50-
Object.keys(this.cumulativeGCTimes).forEach((gcType) => {
51-
const totalGCTime = this.cumulativeGCTimes[gcType];
52-
if (totalGCTime > 0) {
53-
this.metrics.makeMetric({
54-
type: 'Histogram',
55-
name: `gc.${gcType}`,
56-
prometheus: {
57-
name: `nodejs_gc_${gcType}_duration_seconds`,
58-
help: 'garbage collection pause duration seconds',
59-
staticLabels: this.metrics.getServiceLabel(),
60-
buckets: [5e-4, 1e-3, 5e-3, 10e-3, 15e-3, 30e-3, 50e-3]
61-
}
62-
}).observe(totalGCTime * 1e-9); // nanoseconds to seconds
63-
}
64-
});
65-
this.cumulativeGCTimes = Object.assign({}, ZERO_CUMULATIVE_GC_INTERVAL);
66-
}, GC_REPORT_INTERVAL);
67-
} catch (e) {
68-
// gc-stats is a binary dependency, so if it's not installed
69-
// ignore reporting GC metrics
70-
}
7114
}
7215

7316
watch() {
@@ -134,17 +77,10 @@ class HeapWatch {
13477
}
13578

13679
close() {
137-
if (this._gcStats) {
138-
this._gcStats.removeListener('stats', this.reportStatsHandler);
139-
}
14080
if (this.timeoutHandle) {
14181
clearTimeout(this.timeoutHandle);
14282
this.timeoutHandle = undefined;
14383
}
144-
if (this.gcReportInterval) {
145-
clearInterval(this.gcReportInterval);
146-
this.gcReportInterval = undefined;
147-
}
14884
}
14985
}
15086

lib/worker.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,6 @@ class Worker extends BaseService {
149149
const limitMB = parseInt(this.config.worker_heap_limit_mb, 10) || 1500;
150150
this._heapwatchHandle = new HeapWatch({ limitMB }, this._logger, this._metrics);
151151
this._heapwatchHandle.watch();
152-
this._heapwatchHandle.setGCMonitor();
153152

154153
if (cluster.isWorker) {
155154
this._setupWorkerHeartBeat();

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "service-runner",
3-
"version": "2.8.4",
3+
"version": "2.9.0",
44
"description": "Generic nodejs service supervisor / cluster runner",
55
"main": "service-runner.js",
66
"bin": {

0 commit comments

Comments
 (0)