Skip to content
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
- perf: Improve performance of registry defaultLabels during metric processing
- perf: New, more space-efficient storage engine, 20-45% faster stats recording
- perf: Further improvement to key generation cost
- perf: Use faster `process.memoryUsage.rss()` API for resident memory collection (30-40% more ops/sec)
- fix: Browser compatibility for Gauge.startTimer()
- ci: Run benchmarks for pull requests
- ci: switch out deprecated benchmark-regression library for replacement
Expand Down
12 changes: 12 additions & 0 deletions lib/metrics/helpers/safeRss.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
'use strict';

// process.memoryUsage.rss() can throw on some platforms, see #67
function safeRss() {
try {
return process.memoryUsage.rss();
} catch {
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd like to use debug for this in the future but for now we only use it for the benchmarks, so I'm not going to force the issue here, despite the silent return being kind of smelly.

}
}

module.exports = safeRss;
12 changes: 6 additions & 6 deletions lib/metrics/osMemoryHeap.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const Gauge = require('../gauge');
const linuxVariant = require('./osMemoryHeapLinux');
const safeMemoryUsage = require('./helpers/safeMemoryUsage');
const safeRss = require('./helpers/safeRss');

const PROCESS_RESIDENT_MEMORY = 'process_resident_memory_bytes';

Expand All @@ -17,11 +17,11 @@ function notLinuxVariant(registry, config = {}) {
registers: registry ? [registry] : undefined,
labelNames,
collect() {
const memUsage = safeMemoryUsage();

// I don't think the other things returned from `process.memoryUsage()` is relevant to a standard export
if (memUsage) {
this.set(labels, memUsage.rss);
// process.memoryUsage.rss() is faster than process.memoryUsage() as it
// only reads RSS from the OS without collecting all heap statistics
const rss = safeRss();
if (rss !== undefined) {
this.set(labels, rss);
}
Comment thread
jdmarshall marked this conversation as resolved.
},
});
Expand Down
Loading