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

Query frontend #3

Merged
merged 13 commits into from
Jan 6, 2020
Merged

Conversation

owen-d
Copy link

@owen-d owen-d commented Dec 31, 2019

This includes two changes.

Codec performance improvements for merging responses.

We now take advantage of the fact that split responses are already ordered and don't overlap. This includes

  • Introduces an escape hatch when limit >= entries that avoid some unnecessary comparisons
  • Ordering per-stream entry groups in O(n*log(n)) instead of O(m*log(m)) where n = num_intervals, m = num_entries
  • Extracting limit results from a collection of streams in O(n*log(k)) where n = limit, k = num_streams by using a new priority queue impl.

The splitByInterval middleware has been changed significantly.

Previously it split time ranges twice, the first for serial execution and the second for parallel execution within the first.

Now we split one time and use a channel to determine parallelism. This avoids queries in a later interval being convoyed behind a slow (retrying, etc) earlier query. It simplifies the execution model while making it less prone to blocking.

If requested, we can also add a backpressure parameter to the splitByInterval middleware which would prevent scheduling later queries if we're still waiting on an earlier query from backpressure previous intervals.

$ go test -bench . | prettybench
goos: darwin
goarch: amd64
pkg: github.com/grafana/loki/pkg/querier/queryrange
PASS
benchmark                                                              iter     time/iter
---------                                                              ----     ---------
BenchmarkResponseMerge/mergeStreams_unlimited-8                          25   45.81 ms/op
BenchmarkResponseMerge/mergeOrderedNonOverlappingStreams_unlimited-8   1029    1.16 ms/op
BenchmarkResponseMerge/mergeStreams_limited-8                            24   47.88 ms/op
BenchmarkResponseMerge/mergeOrderedNonOverlappingStreams_limited-8       56   22.16 ms/op
ok      github.com/grafana/loki/pkg/querier/queryrange  5.983s

@cyriltovena cyriltovena merged this pull request into cyriltovena:frontend-cleaned Jan 6, 2020
cyriltovena pushed a commit that referenced this pull request Jan 6, 2020
* frontend codec merging optimizations

* codec benchmarks

* removes unused bounds code in queryrange ordering

* [wip] splitby uses channels instead of sub batching intervals

* splitBy channel limit test

* single allocation for merging entries from a single stream

* skip merging loki responses when limit is already hit

* removes checks for unlimited queries in queryrange

* removes splitByInterval{,.interval} spans

* removes interval_batch_size from jsonnet lib

* moves benchmark utils to own file

* renames markers -> entries

* priority queue comments
cyriltovena added a commit that referenced this pull request Jan 7, 2020
* Adds frontend to Loki.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Improves tests.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Fixes sneaky bug in entries sorting.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Fixes the split by interval.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Tweak jsonnet deployments and add a way to lint/fmt.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* lint.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* fix timezone issue.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Improve tests and rollback change in loghttp package.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Fixes a flaky test that might run one more goroutine.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Fixes windows build.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Improve tracing in the split by interval.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Add test stream to proto conversion.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Fixes flappy retry test.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Remove err shadowing in stopQueryFrontend as it was confusing.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Refactor grpc message size in the libsonnet config file.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Don't check auth header for GRPC  TransferChunks.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Query frontend (#3)

* frontend codec merging optimizations

* codec benchmarks

* removes unused bounds code in queryrange ordering

* [wip] splitby uses channels instead of sub batching intervals

* splitBy channel limit test

* single allocation for merging entries from a single stream

* skip merging loki responses when limit is already hit

* removes checks for unlimited queries in queryrange

* removes splitByInterval{,.interval} spans

* removes interval_batch_size from jsonnet lib

* moves benchmark utils to own file

* renames markers -> entries

* priority queue comments

* Removes unused logRequest.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Sets the cache interval to the same split interval.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Missing import libsonnet for the frontend.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

* Frontend should not be a cluster IP.

Signed-off-by: Cyril Tovena <cyril.tovena@gmail.com>

Co-authored-by: Owen Diehl <ow.diehl@gmail.com>
jeschkies referenced this pull request in jeschkies/loki Dec 21, 2021
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