-
Notifications
You must be signed in to change notification settings - Fork 48
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Improve speed and reduce allocations when adding fields #402
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before we land this, I suggest we actually try this in hound via an override and make sure it has the allocations benefit we expect
When testing, a panic happened if |
Unfortunately, this appears to contend the RWMutex inside the LRU cache, making this operation much slower than just doing the RAM allocation :( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Under load, lock contention updating the cache was worse than the memory allocations for a concatenated string. We need to reconsider this implementation.
Another approach could be to only add the prefix if it doesn't already exist, and then go through various places in shepherd and update the keys we pass in to include |
Ah, the lock contention being an issue for high volume make sense. I agree with @cartermp - likely the best solution is to check if the key already has the |
Also, I found that we already had benchmarks for AddField so I've added the following benchmarks:
Added results to PR description. |
I did some experimentation here. |
After further experimentation, it does not seem to be reasonable to have a shared cache that does not have a significant performance bottleneck when trying to limit the size of the cache. (It's probably possible, but not without a lot of tricky code.) And not limiting the cache size might cause a major memory hit in the case of a customer who accidentally uses a high-cardinality value for a column name. I no longer think this approach is worthwhile; a small number of short-duration allocations seems preferable to the locking problems from a shared cache. I'd suggest that we close this issue. |
Introducing a cache is showing to have too much lock contention, closing this in favour of #406. |
Which problem is this PR solving?
The cost of adding the
app.
prefix to all field names is expensive and can account for a significant amount of allocations as observed by perf tools. This is down to always doing a string manipulation for every field that's being added to a span or trace.Short description of the changes
getPrefixedFieldName
func that checks does the following:New benchmarks:
Previous benchmarks (equivalent to consistent key above):