influxdata / influxdata/influxdb

Avoid reading blocks in sort step of ReadGroup

Open
#18,039 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

team/query
Dominant language
Rust
Stars
31.7k
Forks
3.7k
Avg merge
13h 37m
Merged PRs (30d)
8

Description

This code implements ReadGroup on the storage side:
https://github.com/influxdata/influxdb/blob/master/storage/reads/group_resultset.go#L233
That’s the code that sorts all the series so we can group them. At first I thought maybe it’s just sorting the series keys, but I noticed that It calls a method seriesHasPoints
https://github.com/influxdata/influxdb/blob/master/storage/reads/group_resultset.go#L121
The purpose of this code is to avoid sorting the (potentially large number of) series keys that don't have any points in the request's time range. That looks to be actually doing I/O and reading the first block of data into memory for each series for which the predicate evaluates to true. This is a significant performance hit.

The problem here is that we are loading the first block of each series into memory before we even start reading the data, including those series that have no points in the request's time range.

Instead of doing this, we could just sort those series keys for series that have no points for the given range, and omit them from the result later. A potential problem with this approach is that we'll be constructing a larger number of sort keys, which would increase memory/gc pressure.

We should benchmark this work to ensure that it performs better. It would be good to hit the case where there are a large number of series, but tag values change rapidly across time, such that there are a large number of empty series for a sufficiently narrow range.


An alternative and more optimal way of addressing this problem would be to determine if a given series has no points in the request's time range without doing I/O.

We already filter out series based on predicates against tag keys (i.e., predicates from Flux filters that have been pushed down), so it seems feasible that we could evaluate the range here too. But I don't yet understand this code well enough to know if that's feasible.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with storage/reads/group_resultset.go, especially ReadGroup around line 233 and seriesHasPoints around line 121. Trace how series are sorted and how the first block is loaded, then compare the proposed sorting/filtering approaches. Add a benchmark covering many rapidly changing series and a narrow time range, and use it to verify reduced I/O and acceptable memory use.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
databases, performance
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.