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 @@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
### Changed

- Organized default metrics
- perf: Histogram rendering builds its export list straight from the store iterator instead of an intermediate array. Faster at high series counts on Node 24 and 26, can be slightly slower on Node 22

### Added

Expand Down
38 changes: 37 additions & 1 deletion benchmarks/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

'use strict';

const { getLabelNames, labelCombinationFactory } = require('./utils/labels');
const {
getLabelNames,
getLabelCombinations,
labelCombinationFactory,
} = require('./utils/labels');

module.exports = setupHistogramSuite;

Expand Down Expand Up @@ -100,6 +104,19 @@ function setupHistogramSuite(suite) {
),
{ teardown, setup: setup(6) },
);

// `method` repeats `delete`, so `1 x 64` stores 63 label sets and `2 x 8` stores 56.
[
{ name: 'no labels', counts: [] },
{ name: '1 x 64', counts: [64] },
{ name: '2 x 8', counts: [8, 8] },
{ name: '6 x 2', counts: [2, 2, 2, 2, 2, 2] },
].forEach(({ name, counts }) => {
suite.add(`get() ${name}`, (client, { histogram }) => histogram.get(), {
teardown,
setup: observed(counts),
});
});
}

function setup(labelCount) {
Expand All @@ -117,6 +134,25 @@ function setup(labelCount) {
};
}

function observed(labelCounts) {
return client => {
const registry = new client.Registry();

const histogram = new client.Histogram({
name: 'histogram',
help: 'histogram',
labelNames: getLabelNames(labelCounts.length),
registers: [registry],
});

getLabelCombinations(labelCounts).forEach(labels =>
histogram.observe({ ...labels }, 1),

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.

Do all of our histogram tests look like this? Putting all the results into one bucket is probably not quite testing the whole flow, though maybe it doesn't matter here.

);

return { registry, histogram };
};
}

function teardown(client, { registry }) {
registry.clear();
}
4 changes: 2 additions & 2 deletions lib/histogram.js
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ class Histogram extends Metric {
const v = this.collect();
if (v instanceof Promise) await v;
}
const data = Array.from(this.store.values());
const values = data
const values = this.store
.values()
.map(extractBucketValuesForExport(this))
.reduce(addSumAndCountForExport(this), []);

Expand Down
Loading