-
Notifications
You must be signed in to change notification settings - Fork 2.2k
query: cache engines in remoteEndpoints to reuse computed MinT / MaxT / LabelSets values across Engines() calls
#8598
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
base: main
Are you sure you want to change the base?
Conversation
1bfe2cf to
a530364
Compare
…axT / LabelSets between .Engines() calls Signed-off-by: Aleksandr Krivoshchekov <SuperPaintmanDeveloper@gmail.com>
a530364 to
dcc729e
Compare
remoteEndpoints to reuse computed MinT / MaxT / LabelSets values across Engines() callsremoteEndpoints to reuse computed MinT / MaxT / LabelSets values across Engines() calls
|
I think this looks reasonable to me; optimizers will have a consistent view of the Engines() then. Currently its used by Passhtrough and Distributed Optimizers. |
Signed-off-by: Aleksandr Krivoshchekov <SuperPaintmanDeveloper@gmail.com>
|
|
||
| // endpoints.Engines() should return exactly the same slice. | ||
| testutil.Equals(t, len(engines1), len(engines2)) | ||
| testutil.Equals(t, cap(engines1), cap(engines2)) |
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 can verify that the underlying slice data is exactly the same:
testutil.Equals(t, unsafe.Pointer(unsafe.SliceData(engines1)), unsafe.Pointer(unsafe.SliceData(engines2)))But I think, that's an overkill.
This would also be affected if the internal representation changes, e.g.:
-return r.engines
+return slices.Clone(r.engines)Signed-off-by: Aleksandr Krivoshchekov <SuperPaintmanDeveloper@gmail.com>
Signed-off-by: Aleksandr Krivoshchekov <SuperPaintmanDeveloper@gmail.com>
Signed-off-by: Aleksandr Krivoshchekov <SuperPaintmanDeveloper@gmail.com>
remoteEndpoints to reuse computed MinT / MaxT / LabelSets values across Engines() callsremoteEndpoints to reuse computed MinT / MaxT / LabelSets values across Engines() calls
| clients := r.getClients() | ||
| engines := make([]api.RemoteEngine, len(clients)) | ||
| for i := range clients { | ||
| engines[i] = NewRemoteEngine(r.logger, clients[i], r.opts) |
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.
Why not make this even simpler and do this once in the constructor instead of wrapping everything into sync.Once? In Thanos case, it just creates a slice with a read lock so it should be very fast, no?
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 think this change can look odd outside of the broader context and other changes.
In Thanos case, it just creates a slice with a read lock so it should be very fast, no?
I'm changing that in another PR. Engines() will do more work than just creating a new slice.
And it also needs more info than high-level API endpoints have (e.g. here).
So now I think it makes more sense to have this cache in the promql-engine: thanos-io/promql-engine#680
| return engines | ||
| func (r *remoteEndpoints) Engines() []api.RemoteEngine { | ||
| r.enginesOnce.Do(func() { | ||
| clients := r.getClients() |
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.
Won't this introduce a bug with dns endpoints? How would new endpoints ever get added to the slice?
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 create new remoteEndpoints for each query, and then Engines() is almost immediately called in query optimizers (e.g. here).
So this cache lives only for and during one query, and it doesn't affect adding / updating endpoints.
|
Moved it into |
Changes
Cache
RemoteEndpoints.Engines()results, so repeated calls return the same slice of engine.This improves two things:
Engines()(used in PassthroughOptimizer and DistributedExecutionOptimizer).MinT/MaxT/LabelSets) multiple times in optimizers. In the current implementation,.Engines()recreates allremoteEngine's, and effectively resets their cached state.Verification
Issue: #8597
CC: @MichaHoffmann