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

Chunk iterator performance improvement #1203

Merged
merged 7 commits into from
Oct 28, 2019

Conversation

joe-elliott
Copy link
Member

@joe-elliott joe-elliott commented Oct 26, 2019

What this PR does / why we need it:
Improves the headblock iterator performance by storing an index instead of a current item.

Before:

go test -bench=BenchmarkHead. -benchmem
goos: linux
goarch: amd64
pkg: github.com/grafana/loki/pkg/chunkenc
BenchmarkHeadBlockIterator/Size_100000-8         	     501	   2384544 ns/op	 2400311 B/op	       2 allocs/op
BenchmarkHeadBlockIterator/Size_50000-8          	     916	   1155438 ns/op	 1204272 B/op	       2 allocs/op
BenchmarkHeadBlockIterator/Size_15000-8          	    3272	    331680 ns/op	  360496 B/op	       2 allocs/op
BenchmarkHeadBlockIterator/Size_10000-8          	    5660	    232224 ns/op	  245808 B/op	       2 allocs/op
PASS
ok  	github.com/grafana/loki/pkg/chunkenc	8.534s

After

go test -bench=BenchmarkHead. -benchmem
goos: linux
goarch: amd64
pkg: github.com/grafana/loki/pkg/chunkenc
BenchmarkHeadBlockIterator/Size_100000-8         	     486	   2430331 ns/op	 2400288 B/op	       2 allocs/op
BenchmarkHeadBlockIterator/Size_50000-8          	    1070	   1126875 ns/op	 1204256 B/op	       2 allocs/op
BenchmarkHeadBlockIterator/Size_15000-8          	    4156	    279365 ns/op	  360480 B/op	       2 allocs/op
BenchmarkHeadBlockIterator/Size_10000-8          	    6690	    177187 ns/op	  245792 B/op	       2 allocs/op
PASS
ok  	github.com/grafana/loki/pkg/chunkenc	8.675s

Special notes for your reviewer:
Please review and discuss the guard code at the top of Entry() would we prefer a panic to returning dummy data here?

	if li.cur < 0 || li.cur >= len(li.entries) {
		return logproto.Entry{}
	}

Checklist

  • Documentation added
  • Tests updated

Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
Signed-off-by: Joe Elliott <number101010@gmail.com>
@cyriltovena
Copy link
Contributor

Why did you close that one ? It was looking good.

@joe-elliott joe-elliott reopened this Oct 28, 2019
@joe-elliott
Copy link
Member Author

joe-elliott commented Oct 28, 2019

Updated the benchmarks to be more comprehensive:

100k -     - 243 / 238 = 1.02
50k  - p99 - 112 / 114 = .98
15k  - avg -  27 /  31 = .81
10k  - p50 -  17 /  23 = .73

@cyriltovena I just should have waited til Monday. I was unsure of the validity of the benchmarks and wanted to feel more comfortable before someone merged.

Signed-off-by: Joe Elliott <number101010@gmail.com>
@owen-d
Copy link
Member

owen-d commented Oct 28, 2019

Unsure regarding panic vs returning the zero-value struct, but I believe your approach is good. I know that in cortex, for instance, we assume that entries will not be checked when Next() is false. Doing so would cause a panic, so perhaps your code should mimic that behavior. However, I like your approach of avoiding panicking where possible and leaving it up to the consumer to use it correctly.

:lgtm:

Signed-off-by: Joe Elliott <number101010@gmail.com>
@joe-elliott
Copy link
Member Author

@owen-d
Right. I think the "correct" approach is to not have the guard code, but given how important the stability of the ingesters are I decided to add it as a discussion point.

Copy link
Contributor

@cyriltovena cyriltovena left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@cyriltovena cyriltovena merged commit 9f8eb8f into grafana:master Oct 28, 2019
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.

3 participants