feat(p2p): pre-allocate static labels used to produce metrics#2851
feat(p2p): pre-allocate static labels used to produce metrics#2851
Conversation
| } else if !p.hasChannel(chID) { | ||
| return false | ||
| } | ||
| metricLabelValue := p.mlc.ValueToMetricLabel(msg) |
There was a problem hiding this comment.
I wonder whether there was a reason for calling this here, as msg can be changed in line 276...
There was a problem hiding this comment.
Indeed, it breaks everything. Restored.
| @@ -43,6 +43,19 @@ type Metrics struct { | |||
| type metricsLabelCache struct { | |||
| mtx *sync.RWMutex | |||
| messageLabelNames map[reflect.Type]string | |||
There was a problem hiding this comment.
We could probably also pre-allocate this guy, which would allow us for getting rid of the lock.
andynog
left a comment
There was a problem hiding this comment.
added a comment around metric allocation, I don't understand the metric package well but just looking at the dependency I think there might still some problems with allocations.
| } | ||
| p.metrics.PeerReceiveBytesTotal.With(labels...).Add(float64(len(msgBytes))) | ||
| p.metrics.MessageReceiveBytesTotal.With("message_type", p.mlc.ValueToMetricLabel(msg)).Add(float64(len(msgBytes))) | ||
| p.metrics.PeerReceiveBytesTotal. |
There was a problem hiding this comment.
in the go-kit/metrics dependency, using the With factory I believe might allocate a Counter (at least a pointer) for every combination of peer ID and channel ID on a received message ? If so maybe the logic to cache should be not on labels but on the Counter (pair or peer ID and chID) and then you just call the Add in the receive msg routine ?
https://github.com/go-kit/kit/blob/78fbbceece7bbcf073bee814a7772f4397ea756c/metrics/prometheus/prometheus.go#L36
There was a problem hiding this comment.
This is my understanding of the bottleneck here as well. (That Allocations come from the With call, and thats what we want to cache)
There was a problem hiding this comment.
We would need to cache the metrics.Counter instances. The problem is the cardinality.
We have 22 message types, if I am not wrong, and 10 channels. With standard configuration, we can have from 10 to 50 peers. Ok, at the end is not that impossible.
The problem is that this is very hard to evaluate without running a bunch of nodes... |
|
Can help with getting more mainnet profiles! |
|
Maybe we can merge this, while it is pretty clear that it does not solve the problem... |
|
That sgtm! These sprintf calls were avoiding do show up in cpu profiles so absolutely helpful to get this eliminated! |
|
Not sure about backporting this code though. |
Addresses #2840. The same approach taken for the `send()` method is also adopted for the `onReceive()` method. --- #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec (cherry picked from commit 7673d74)
#2851) (#2877) Addresses #2840. The same approach taken for the `send()` method is also adopted for the `onReceive()` method. --- #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments - [x] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request #2851 done by [Mergify](https://mergify.com). Co-authored-by: Daniel <daniel.cason@informal.systems> Co-authored-by: Anton Kaliaev <anton.kalyaev@gmail.com>
…ng (#2984) In the metric `MessageReceiveBytesTotal`, the only value produced in the `message_type` label is `v1_Message`. This is because we are reading the `msg` variable before the message is unwrapped. This bug was recently introduced in #2851. --- #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments - [ ] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec
…ng (#2984) In the metric `MessageReceiveBytesTotal`, the only value produced in the `message_type` label is `v1_Message`. This is because we are reading the `msg` variable before the message is unwrapped. This bug was recently introduced in #2851. --- #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments - [ ] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec (cherry picked from commit 33729e6)
…ng (backport #2984) (#2985) In the metric `MessageReceiveBytesTotal`, the only value produced in the `message_type` label is `v1_Message`. This is because we are reading the `msg` variable before the message is unwrapped. This bug was recently introduced in #2851. --- #### PR checklist - [ ] Tests written/updated - [ ] Changelog entry added in `.changelog` (we use [unclog](https://github.com/informalsystems/unclog) to manage our changelog) - [ ] Updated relevant documentation (`docs/` or `spec/`) and code comments - [ ] Title follows the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) spec <hr>This is an automatic backport of pull request #2984 done by [Mergify](https://mergify.com). Co-authored-by: Hernán Vanzetto <15466498+hvanz@users.noreply.github.com>



Addresses #2840.
The same approach taken for the
send()method is also adopted for theonReceive()method.PR checklist
.changelog(we use unclog to manage our changelog)docs/orspec/) and code comments