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] Increase performance of temporal functions #1917

Merged
merged 7 commits into from
Sep 2, 2019

Conversation

arnikola
Copy link
Collaborator

What this PR does / why we need it:
FIxes very slow temporal function application when working with larger ranges

Special notes for your reviewer:
This is a quick and easy solution for the time being, just removing the allocations made in a tight loop.

Does this PR introduce a user-facing and/or backwards incompatible change?:

None

Does this PR require updating code package or user-facing documentation?:

None

rBound time.Time,
init int,
) (int, int, bool) {
if init > len(dp) || init < 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

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

hm should this be init >= len(dp)?

}

if r == -1 {
r = len(dp)
Copy link
Collaborator

@robskillington robskillington Aug 29, 2019

Choose a reason for hiding this comment

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

Is this not r = len(dp)-1? Are the callers going to directly index into the slice?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, good call

Copy link
Collaborator

Choose a reason for hiding this comment

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

Still need to update this or is this different now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah sorry meant to respond on here; it's used as subslice indices, which should work fine. Added a comment noting this

Copy link
Collaborator

Choose a reason for hiding this comment

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

Sounds good.

@@ -349,7 +394,7 @@ func (c *baseNode) processSingleRequest(

aggDuration := c.op.duration
steps := int((aggDuration + bounds.Duration) / bounds.StepSize)
values := make([]ts.Datapoints, 0, steps)
values := make(ts.Datapoints, 0, steps)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Seems like steps doesn't take into account the dep iters? Perhaps we could get the full running count.

e.g. just thinking out loud:

depExpectedDatapoints := 0
for i, blk := range request.deps {
  // ...
  depIters[i] = iter
  depExpectedDatapoints += len(iter.Datapoints())
}

// ...

values := make(ts.Datapoints, 0, depExpectedDatapoints + steps)

Also at this point do we know how big DatapointsAtStep(x) will be? Do we need to multiply steps * expectedDatapointsAtStep or something like that?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also can values be reused between calls to node.processSingleRequest(...)? Or does processor.process(values[l:r], ...) end up taking ownership of the slice?

steps := int((aggDuration + bounds.Duration) / bounds.StepSize)
values := make([]ts.Datapoints, 0, steps)
desiredLength := int(math.Ceil(float64(aggDuration) / float64(bounds.StepSize)))
depIters := make([]block.UnconsolidatedSeriesIter, len(request.deps))
Copy link
Collaborator

Choose a reason for hiding this comment

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

For safety, should we just use make([]foo, 0, length) and append(...) wherever it's possible to? Been running into a lot of these bugs lately (in not just M3 code base, elsewhere too).

@codecov
Copy link

codecov bot commented Sep 1, 2019

Codecov Report

Merging #1917 into master will decrease coverage by <.1%.
The diff coverage is 73.7%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1917     +/-   ##
=========================================
- Coverage    63.4%    63.4%   -0.1%     
=========================================
  Files        1113     1112      -1     
  Lines      104747   104797     +50     
=========================================
+ Hits        66428    66455     +27     
- Misses      34077    34108     +31     
+ Partials     4242     4234      -8
Flag Coverage Δ
#aggregator 79.8% <ø> (ø) ⬆️
#cluster 56.3% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 64.8% <ø> (ø) ⬆️
#m3em 59.6% <ø> (ø) ⬆️
#m3ninx 61.1% <ø> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.5% <ø> (-0.2%) ⬇️
#msg 74.9% <ø> (ø) ⬆️
#query 68.1% <73.7%> (ø) ⬆️
#x 75.6% <ø> (+0.2%) ⬆️

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 0553850...26f4a6c. Read the comment docs.

@codecov
Copy link

codecov bot commented Sep 1, 2019

Codecov Report

Merging #1917 into master will decrease coverage by <.1%.
The diff coverage is 73.7%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master    #1917     +/-   ##
=========================================
- Coverage    63.4%    63.4%   -0.1%     
=========================================
  Files        1113     1112      -1     
  Lines      104747   104797     +50     
=========================================
+ Hits        66428    66455     +27     
- Misses      34077    34108     +31     
+ Partials     4242     4234      -8
Flag Coverage Δ
#aggregator 79.8% <ø> (ø) ⬆️
#cluster 56.3% <ø> (ø) ⬆️
#collector 63.7% <ø> (ø) ⬆️
#dbnode 64.8% <ø> (ø) ⬆️
#m3em 59.6% <ø> (ø) ⬆️
#m3ninx 61.1% <ø> (ø) ⬆️
#m3nsch 51.1% <ø> (ø) ⬆️
#metrics 17.5% <ø> (-0.2%) ⬇️
#msg 74.9% <ø> (ø) ⬆️
#query 68.1% <73.7%> (ø) ⬆️
#x 75.6% <ø> (+0.2%) ⬆️

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 0553850...6441851. Read the comment docs.

Copy link
Collaborator

@robskillington robskillington left a comment

Choose a reason for hiding this comment

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

LGTM

@arnikola arnikola merged commit 3044cf5 into master Sep 2, 2019
@arnikola arnikola deleted the arnikola/temporal-perf branch September 2, 2019 01:03
@arnikola arnikola changed the title [Query] Increase performance of temporal functions [query] Increase performance of temporal functions Oct 16, 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.

2 participants