-
Notifications
You must be signed in to change notification settings - Fork 3.7k
fix(ingest-limits): Use stripe locking for metadata #17150
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
Conversation
7222994
to
c6b8c9c
Compare
c6b8c9c
to
805f573
Compare
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.
In general looks good! I would love to see a better abstraction around the stripes and the lock acquisition though. I think if you do this you'll find the code easier to reason about and also easier to write tests. You could consider using https://pkg.go.dev/iter for some of the operations.
6cb1f32
to
8a03e24
Compare
266b8c1
to
4bf6f5d
Compare
pkg/limits/stream_metadata.go
Outdated
|
||
// AllFunc is a function that is called for each stream in the metadata. | ||
// It is used to count per tenant active streams. | ||
// Note: The collect function should not modify the stream metadata. |
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.
Is modification possible as we pass a copy of Stream
? I suppose you could change the values in RateBuckets
?
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.
You are right, this is more of a note on how to use the interface not an enforced rule as of now.
require.ElementsMatch(t, expected, actual) | ||
} | ||
|
||
func TestStreamMetadata_Usage_Concurrent(t *testing.T) { |
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.
Do we need to run these with -race
?
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.
Just FYI, we don't run our tests with -race
:
Run gotestsum -- -covermode=atomic -coverprofile=coverage.txt -p=4 ./pkg/limits/...
What this PR does / why we need it:
This pull request implements a stripe-lock approach to read/write the internal ingest-limits stream metadata structure. The stripes are distributed over the total amount of partitions (e.g. default is 64). This allows updating and reading the structure with less lock contention.
Which issue(s) this PR fixes:
Fixes #
Special notes for your reviewer:
Checklist
CONTRIBUTING.md
guide (required)feat
PRs are unlikely to be accepted unless a case can be made for the feature actually being a bug fix to existing behavior.docs/sources/setup/upgrade/_index.md
deprecated-config.yaml
anddeleted-config.yaml
files respectively in thetools/deprecated-config-checker
directory. Example PR