Skip to content

Conversation

@pracucci
Copy link
Contributor

@pracucci pracucci commented Mar 4, 2024

What this PR does:

In Mimir ingesters, 10% of object (and memory) allocations come from gRPC metadata.FromIncomingContext(). metadata.FromIncomingContext() is called in few places, including user.ExtractFromGRPCRequest(). The problem of metadata.FromIncomingContext() is that it creates a copy of all metadata map, when we only want to lookup a single key.

Two years ago, metadata.ValueFromIncomingContext() was introduced in gRPC golang library exactly for this reason. The function is still marked as experimental but it was left untouched since was introduced 2 years ago. I propose to use it. If it will get removed, we can always revert back to metadata.FromIncomingContext().

Benchmark:

goos: darwin
goarch: amd64
pkg: github.com/grafana/dskit/user
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
                          │ before.txt  │             after.txt              │
                          │   sec/op    │   sec/op     vs base               │
ExtractFromGRPCRequest-12   772.2n ± 2%   124.0n ± 7%  -83.94% (p=0.002 n=6)

                          │ before.txt  │             after.txt             │
                          │    B/op     │    B/op     vs base               │
ExtractFromGRPCRequest-12   560.00 ± 0%   80.00 ± 0%  -85.71% (p=0.002 n=6)

                          │ before.txt  │             after.txt             │
                          │  allocs/op  │ allocs/op   vs base               │
ExtractFromGRPCRequest-12   10.000 ± 0%   3.000 ± 0%  -70.00% (p=0.002 n=6)

Which issue(s) this PR fixes:

N/A

Checklist

  • Tests updated
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]

goos: darwin
goarch: amd64
pkg: github.com/grafana/dskit/user
cpu: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
                          │ before.txt  │             after.txt              │
                          │   sec/op    │   sec/op     vs base               │
ExtractFromGRPCRequest-12   772.2n ± 2%   124.0n ± 7%  -83.94% (p=0.002 n=6)

                          │ before.txt  │             after.txt             │
                          │    B/op     │    B/op     vs base               │
ExtractFromGRPCRequest-12   560.00 ± 0%   80.00 ± 0%  -85.71% (p=0.002 n=6)

                          │ before.txt  │             after.txt             │
                          │  allocs/op  │ allocs/op   vs base               │
ExtractFromGRPCRequest-12   10.000 ± 0%   3.000 ± 0%  -70.00% (p=0.002 n=6)

Signed-off-by: Marco Pracucci <[email protected]>
@pracucci pracucci marked this pull request as ready for review March 4, 2024 14:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants