fix(buffers): Optimize buffer usage metric tracking#24911
fix(buffers): Optimize buffer usage metric tracking#24911
Conversation
7e9a011 to
4a15afc
Compare
The buffer usage metrics, in particular the value of the current utilization levels, were tracked using an atomic `u64` which was updated using a `fetch_update` mechanism in order to protect against underflowing. This same mechanism was extended to all of the atomics as well for consistency. The problem with that is that `fetch_udpate` internally uses a loop around a `compare-and-exchange` operation which is very expensive, particularly when contended. In comparison, the base `fetch_add` is typically a single locked instruction which completes in many fewer cycles. This change returns these atomics to only ever use `fetch_add` and then calculate the current level by subtracting the count of increments from the count of decrements.
4a15afc to
3936121
Compare
| @@ -0,0 +1,3 @@ | |||
| Fixed regression in performance of buffer usage metric tracking. | |||
There was a problem hiding this comment.
Did we validate if this PR fixes the regression?
Ref #24911 (comment)
|
Thanks for the effort, @bruceg! |
Hi @pznamensky I kicked off a custom build: https://github.com/vectordotdev/vector/actions/runs/23146056109 You can use those builds once they are published. Looking forward to hearing back from after you test this 🤞 |
|
@pront, thank you for preparing the images. |

Summary
The buffer usage metrics, in particular the value of the current utilization levels, were tracked using an atomic
u64which was updated using afetch_updatemechanism in order to protect against underflowing. This same mechanism was extended to all of the atomics as well for consistency. The problem with that is thatfetch_udpateinternally uses a loop around acompare-and-exchangeoperation which is very expensive, particularly when contended. In comparison, the basefetch_addis typically a single locked instruction which completes in many fewer cycles.This change returns these atomics to only ever use
fetch_addand then calculate the current level by subtracting the count of increments from the count of decrements.Vector configuration
N/A
How did you test this PR?
Unit tests
Change Type
Is this a breaking change?
Does this PR include user facing changes?
no-changeloglabel to this PR.References
#24058
Notes
@vectordotdev/vectorto reach out to us regarding this PR.pre-pushhook, please see this template.make fmtmake check-clippy(if there are failures it's possible some of them can be fixed withmake clippy-fix)make testgit merge origin masterandgit push.Cargo.lock), pleaserun
make build-licensesto regenerate the license inventory and commit the changes (if any). More details here.