-
Notifications
You must be signed in to change notification settings - Fork 378
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: improve the memory usage of histogram when not enable `enableEx…
…emplars`
- Loading branch information
Showing
3 changed files
with
54 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,3 +4,4 @@ node_modules | |
*.log | ||
coverage/ | ||
package-lock.json | ||
*.heapsnapshot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
'use strict'; | ||
|
||
const v8 = require('v8'); | ||
const { register, Histogram } = require('..'); | ||
|
||
// Create more metrics | ||
|
||
async function run() { | ||
const labelNames = Array(10).map((_, idx) => `label_${idx}`); | ||
|
||
const getRandomLabels = () => | ||
labelNames.reduce((acc, label) => { | ||
return { ...acc, [label]: `value_${Math.random()}` }; | ||
}, {}); | ||
|
||
for (let i = 0; i < 100000; i++) { | ||
const h = new Histogram({ | ||
name: `test_histogram_${i}`, | ||
help: `Example of a histogram ${i}`, | ||
buckets: [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, 1], | ||
labelNames, | ||
}); | ||
h.observe(getRandomLabels(), Math.random()); | ||
} | ||
|
||
await register.metrics(); | ||
|
||
global.gc(); | ||
|
||
v8.writeHeapSnapshot(); | ||
} | ||
|
||
run(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters