-
Notifications
You must be signed in to change notification settings - Fork 69
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
chore: Improve performance of TenantID #541
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.
I can see there's a performance regression of about 10% CPU time for the multi-tenant case versus main.
My suggestion is to refactor the string parsing in TenantIDs
into a function tenantIDsFromString
, that is also called from TenantID
so you don't have to call user.ExtractOrgID
twice in the multi-tenant case. When I try this, the perf regression goes away.
✗ benchstat perf.txt perf-arve.txt
goos: linux
goarch: amd64
pkg: github.com/grafana/dskit/tenant
cpu: AMD Ryzen 9 3950X 16-Core Processor
│ perf.txt │ perf-arve.txt │
│ sec/op │ sec/op vs base │
TenantID/single-32 19.96n ± 9% 20.46n ± 4% ~ (p=0.589 n=6)
TenantID/multi-32 320.5n ± 3% 290.6n ± 2% -9.34% (p=0.002 n=6)
geomean 79.98n 77.10n -3.60%
│ perf.txt │ perf-arve.txt │
│ B/op │ B/op vs base │
TenantID/single-32 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=6) ¹
TenantID/multi-32 48.00 ± 0% 48.00 ± 0% ~ (p=1.000 n=6) ¹
geomean ² +0.00% ²
¹ all samples are equal
² summaries must be >0 to compute geomean
│ perf.txt │ perf-arve.txt │
│ allocs/op │ allocs/op vs base │
TenantID/single-32 0.000 ± 0% 0.000 ± 0% ~ (p=1.000 n=6) ¹
TenantID/multi-32 1.000 ± 0% 1.000 ± 0% ~ (p=1.000 n=6) ¹
geomean ² +0.00% ²
¹ all samples are equal
² summaries must be >0 to compute geomean
good call
|
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.
LGTM, thanks!
CI is failing consistently in |
Seems like a flake |
What this PR does:
This improves performance in case there's is only 1 tenant which is apparently 99% of the time. The multi tenant case is kept unchanged.
Basically saves us 2 allocs per push/query requests.
Which issue(s) this PR fixes:
Fixes #
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
Don't think I need a changelog entry for that.