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

Fix Series API slowness #2123

Merged
merged 1 commit into from
Jun 3, 2020
Merged

Conversation

adityacs
Copy link
Contributor

@adityacs adityacs commented May 25, 2020

What this PR does / why we need it:
Fix Series API slowness

Which issue(s) this PR fixes:
Fixes #2121

Checklist

  • Tests updated

@adityacs
Copy link
Contributor Author

adityacs commented May 25, 2020

This is just an attempt to fix the API slowness. I may be wrong

@codecov-commenter
Copy link

codecov-commenter commented May 25, 2020

Codecov Report

Merging #2123 into master will increase coverage by 0.28%.
The diff coverage is 88.33%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2123      +/-   ##
==========================================
+ Coverage   61.50%   61.79%   +0.28%     
==========================================
  Files         149      149              
  Lines       11935    12084     +149     
==========================================
+ Hits         7341     7467     +126     
- Misses       4012     4029      +17     
- Partials      582      588       +6     
Impacted Files Coverage Δ
pkg/querier/queryrange/roundtrip.go 69.61% <79.16%> (+2.50%) ⬆️
pkg/querier/queryrange/codec.go 91.54% <89.90%> (-3.03%) ⬇️
pkg/querier/queryrange/split_by_interval.go 87.59% <90.90%> (+0.80%) ⬆️
pkg/promtail/targets/tailer.go 76.13% <0.00%> (-2.28%) ⬇️
pkg/querier/queryrange/downstreamer.go 97.93% <0.00%> (+2.06%) ⬆️

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.

I think we want to solve it this way #2106 instead.

The problem with the current approach is that you may load a lot of chunks in memory that can cause the querier to OOM. Currently it's limited by s.cfg.MaxChunkBatchSize which is 50 at the time.

I'll defer to Owen, but I think we want instead to split queries by time.

@cyriltovena cyriltovena requested a review from owen-d May 25, 2020 13:40
@adityacs
Copy link
Contributor Author

The problem with the current approach is that you may load a lot of chunks in memory that can cause the querier to OOM. Currently it's limited by s.cfg.MaxChunkBatchSize which is 50 at the time.

Got your point. I didn't realize this

@owen-d
Copy link
Member

owen-d commented May 26, 2020

Oh yes, I'd much rather we solve this via parallelization in the frontend the same way we do for other queries. Would you like to pick up that approach instead?

@adityacs adityacs marked this pull request as draft May 29, 2020 05:25
@adityacs adityacs force-pushed the 2121_series_api_fix branch 7 times, most recently from da64194 to 7a1e827 Compare May 29, 2020 15:55
@adityacs adityacs marked this pull request as ready for review May 29, 2020 15:59
Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

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

This is looking good. I left a couple of comments to address and I'd also appreciate some tests in
codec_test.go covering encoding/decoding as well as split_by_interval_test.go specifically in the Test_splitByInterval_Do and Test_splitQuery table tests.

pkg/querier/queryrange/roundtrip.go Outdated Show resolved Hide resolved
pkg/querier/queryrange/codec.go Outdated Show resolved Hide resolved
pkg/querier/queryrange/codec.go Outdated Show resolved Hide resolved
pkg/querier/queryrange/codec.go Outdated Show resolved Hide resolved
pkg/querier/queryrange/codec.go Outdated Show resolved Hide resolved
pkg/querier/queryrange/roundtrip.go Outdated Show resolved Hide resolved
pkg/querier/queryrange/split_by_interval.go Show resolved Hide resolved
pkg/querier/queryrange/split_by_interval.go Outdated Show resolved Hide resolved
@adityacs adityacs force-pushed the 2121_series_api_fix branch 4 times, most recently from 5357012 to f7187ec Compare June 2, 2020 12:11
end := start.Add(interval)
if end.After(r.EndTs) {
end = r.EndTs
for start := req.GetStart(); start < req.GetEnd(); start = start + interval.Milliseconds() {
Copy link
Contributor Author

@adityacs adityacs Jun 2, 2020

Choose a reason for hiding this comment

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

This change limits us to use only millisecond. Since, GetStart and GetEnd methods converts the time to milliseconds we won't able to measure anything below millisecond

Time with value 1575892860000000001 will be 1575892860000 upon calling GetStart or GetEnd

Copy link
Member

Choose a reason for hiding this comment

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

Great point, I didn't think of that.

I think your original approach is better :)

@adityacs adityacs requested a review from owen-d June 2, 2020 12:25
@adityacs
Copy link
Contributor Author

adityacs commented Jun 2, 2020

@owen-d Have made the changes based on your comments. Kindly review.

@@ -168,6 +184,35 @@ func Test_codec_EncodeRequest(t *testing.T) {
require.Equal(t, "/loki/api/v1/query_range", req.(*LokiRequest).Path)
}

func Test_codec_sereis_EncodeRequest(t *testing.T) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
func Test_codec_sereis_EncodeRequest(t *testing.T) {
func Test_codec_series_EncodeRequest(t *testing.T) {

@owen-d
Copy link
Member

owen-d commented Jun 2, 2020

Thanks for addressing my comments; it looks great. Just a bit of cleanup then we can get this merged

@adityacs adityacs requested a review from owen-d June 3, 2020 03:03
Copy link
Member

@owen-d owen-d left a comment

Choose a reason for hiding this comment

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

Great thanks!

@owen-d owen-d merged commit 5b8d9b4 into grafana:master Jun 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Loki API /series can be too slow
4 participants