-
Notifications
You must be signed in to change notification settings - Fork 68
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
ring: add GetWithOptions method to adjust per call behavior #620
base: main
Are you sure you want to change the base?
Conversation
This change adds a new method that accepts 0 or more `Option` instances that modify the behavior of the call. These options can (currently) be used to adjust the replication factor for a particular key or use buffers to avoid excessive allocation. Part of grafana/mimir#9944
ring/ring.go
Outdated
func collectOptions(opts ...Option) *Options { | ||
final := &Options{} | ||
for _, opt := range opts { | ||
opt(final) | ||
} | ||
return final | ||
} |
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.
we had some benchmarks about not allocating on Get
. The plan is not to use this GetWithOptions on the hot path, right? (but also maybe just returning an Options
might do away with the 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.
I tried returning Options
but it still (presumably) escaped to the heap. I refactored this a bit locally to avoid the allocation for Get()
but it's less clean than this.
The way GetWithOptions
is called in Mimir - it's called to filter blocks in the store-gateway sharding strategy: done in the background, called by queriers to find a store-gateway replication set: not sure if this is a "hot path". It's called once per block that's part of a query.
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.
aha, i guess it's on the hot path, but it's called much less often than "once per sample" on the write path. We can probably pay the cost without noticing it
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'll see if I can improve this since it'd be nice to clean it up:
ring/ring.go:46:18: leaking param: bufDescs
ring/ring.go:46:43: leaking param: bufHosts
ring/ring.go:46:53: leaking param: bufZones
ring/ring.go:47:14: opts does not escape
ring/ring.go:47:9: func literal escapes to heap
ring/ring.go:55:14: opts does not escape
ring/ring.go:55:9: func literal escapes to heap
ring/ring.go:60:21: opts does not escape
ring/ring.go:61:11: &Options{} escapes to heap
What this PR does:
This change adds a new method that accepts 0 or more
Option
instances that modify the behavior of the call. These options can (currently) be used to adjust the replication factor for a particular key or use buffers to avoid excessive allocation.Which issue(s) this PR fixes:
Part of grafana/mimir#9944
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]