-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Run multi-tenant queries in parallel. #10129
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
func(_ context.Context, idx int) error { | ||
res, err := jobs[idx]() | ||
if res != nil { | ||
results = append(results, res...) |
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 don't think this was thread safe so I've replace the logic.
pkg/querier/multi_tenant_querier.go
Outdated
iters[i] = NewTenantSampleIterator(iter, id) | ||
i++ | ||
id := id | ||
p.Go(func(ctx context.Context) (iter.SampleIterator, error) { |
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.
iter.MapErr
would be a little nicer but it does not work with a context and cancel on error. There's one (sourcegraph/conc#114) in the work.
id := id | ||
p.Go(func(c context.Context) (iter.SampleIterator, error) { | ||
singleContext := user.InjectOrgID(c, id) | ||
iter, err := q.Querier.SelectSamples(singleContext, params) |
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.
This fails with a cancelled context when run a second time. I have a hard time understanding why.
@jeschkies what shall we do with this? |
Closing for now, we can revive it later if we want to. |
What this PR does / why we need it:
Previously the multi-tenant queries would run in sequence which might have slowed them down. That is why we are going to execute them in a small worker pool.
The tests have been update as well, since they were faulty.
Checklist
CONTRIBUTING.md
guide (required)CHANGELOG.md
updatedadd-to-release-notes
labeldocs/sources/setup/upgrade/_index.md
production/helm/loki/Chart.yaml
and updateproduction/helm/loki/CHANGELOG.md
andproduction/helm/loki/README.md
. Example PR