elastic / elastic/apm-agent-nodejs
take a look at performance with large transaction/span labels
- Dominant language
- JavaScript
- Stars
- 594
- Forks
- 244
- Avg merge
- 1d 8h
- Merged PRs (30d)
- 16
Description
Using this small play script "play-large-labels-perf.js":
```js
const tracer = require('./').start({
serviceName: 'play-large-labels-perf',
logUncaughtExceptions: true,
captureSpanStackTraces: false,
metricsInterval: '0s',
breakdownMetrics: false,
centralConfig: false,
cloudProvider: 'none',
captureHeaders: false,
filterHttpHeaders: false,
stackTraceLimit: 10
})
const express = require('express')
const app = express()
const port = 3000
const big1e3 = Buffer.alloc(1e3).toString()
const big1e4 = Buffer.alloc(1e4).toString()
const big1e5 = Buffer.alloc(1e5).toString()
const big1e6 = Buffer.alloc(1e6).toString()
app.get('/', (req, res) => {
var s = tracer.startSpan('thing')
// Adding the following large labels has a big impact on CPU.
// No particular reason that I'm adding labels to the transaction rather than the span.
// s.transaction.setLabel('big3', big1e3)
// s.transaction.setLabel('big4', big1e4)
// s.transaction.setLabel('big5', big1e5)
// s.transaction.setLabel('big6', big1e6)
setTimeout(function () {
if (s) s.end()
res.send('pong')
}, 10)
})
app.listen(port, () => {
console.log(`listening at http://localhost:${port}`)
})
// setInterval(() => {
// console.log(tracer._getStats())
// }, 5000).unref()
```
Load it up with `hey -c 50 -q 10 -z 180m http://localhost:3000/` and watch its CPU usage with `htop -F labels` or whatever.
When adding larger "bigN" labels, the CPU usage gets much higher. Why is that exactly? I was hoping that truncation to length limits would put a ceiling on that CPU impact -- i.e. that `big1e6` would not impact any more than `big1e5` because the length limit is much less than that. However that isn't my observation.
Contributor guide
Assessment
This issue has not been assessed yet.