Skip to content
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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

56quarters
Copy link
Contributor

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

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

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
Comment on lines 60 to 66
func collectOptions(opts ...Option) *Options {
final := &Options{}
for _, opt := range opts {
opt(final)
}
return final
}
Copy link
Contributor

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)

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

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

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.

2 participants