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

Significantly improve performance of FetchResultToPromResult and helper functions #1003

Merged
merged 7 commits into from
Oct 2, 2018

Conversation

richardartoul
Copy link
Contributor

@richardartoul richardartoul commented Oct 2, 2018

screen shot 2018-10-02 at 9 57 09 am

screen shot 2018-10-02 at 9 57 13 am

Before

BenchmarkFetchResultToPromResult-8   	      30	  34556216 ns/op	25773633 B/op	 1014479 allocs/op

After

BenchmarkFetchResultToPromResult-8   	     100	  10563444 ns/op	25368543 B/op	    4443 allocs/op

benchResult *prompb.QueryResult
)

func BenchmarkFetchResultToPromResult(b *testing.B) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Might be useful to paste the benchmark results in a comment here just for easier comparisons in the future?

// Perform bulk allocation upfront then convert to pointers afterwards
// to reduce total number of allocations. See BenchmarkFetchResultToPromResult
// if modifying.
timeseries := make([]prompb.TimeSeries, 0, len(result.SeriesList))
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice pattern, we can probably make use fo this approach elsewhere too

for i := 0; i < numDatapointsPerSeries; i++ {
values = append(values, ts.Datapoint{
Timestamp: time.Time{},
Value: float64(i),
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: maybe use a random value and time.Now() instead?

@codecov
Copy link

codecov bot commented Oct 2, 2018

Codecov Report

Merging #1003 into master will decrease coverage by 2.39%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1003     +/-   ##
=========================================
- Coverage    77.6%   75.21%   -2.4%     
=========================================
  Files         412      407      -5     
  Lines       34653    34474    -179     
=========================================
- Hits        26892    25929    -963     
- Misses       5887     6641    +754     
- Partials     1874     1904     +30
Flag Coverage Δ
#dbnode 78.29% <ø> (-3.16%) ⬇️
#m3ninx 75.33% <ø> (+0.07%) ⬆️
#query 62.93% <0%> (-0.26%) ⬇️
#x 84.72% <ø> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6b4fe4f...e278bde. Read the comment docs.

func SeriesToPromTS(series *ts.Series) prompb.TimeSeries {
labels := TagsToPromLabels(series.Tags)
samples := SeriesToPromSamples(series)
return prompb.TimeSeries{Labels: labels, Samples: samples}
}

// TagsToPromLabels converts tags to prometheus labels
// TagsToPromLabels converts tags to prometheus labels.TagsToPromLabels.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like a find+replace issue?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

}
var (
seriesLen = series.Len()
values = series.Values()
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: we only use these in one place so probably prefer to drop the var for it and just use the accessor?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nah because then it gets called on every iteration of the loop. Moving these out into vars actually made a significant impact (20%ish percent improvement or so)

})
}

samplesPointers := make([]*prompb.Sample, 0, len(samples))
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit; alternatively can use seriesLen here too

Copy link
Contributor Author

Choose a reason for hiding this comment

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

just seemed safer to use the length of the thing I'm actually iterating through

@richardartoul richardartoul merged commit 11c7e29 into master Oct 2, 2018
@robskillington robskillington deleted the ra/http_allpoc branch October 2, 2018 18:19
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