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

Speed up Trace Statistics view calculation #1941

Merged

Conversation

maxgaponov
Copy link
Contributor

@maxgaponov maxgaponov commented Nov 3, 2023

Which problem is this PR solving?

Description of the changes

  • Speed up Trace Statistics view calculation. Now we precompute child spans for each span to calculate statistics. Previously we filtered all spans to find children for each span.

How was this change tested?

  • Existing tests. Ran manually on a large trace.

Checklist

Resolves jaegertracing#1925
Now we precompute child spans for each span
to calculate statistics. Previously we filtered
all spans to find children for each span.

Signed-off-by: Maksim Gaponov <gaponovmaxev@gmail.com>
@maxgaponov maxgaponov requested a review from a team as a code owner November 3, 2023 12:02
@maxgaponov maxgaponov requested review from yurishkuro and removed request for a team November 3, 2023 12:02
@@ -97,6 +107,7 @@ function valueFirstDropdown(selectedTagKey: string, trace: Trace) {
let color = '';
let allDiffColumnValues = [];
const allSpans = trace.spans;
parentChildOfMap = null;
Copy link
Member

Choose a reason for hiding this comment

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

why do you keep nulling this out?

span.childSpanIds.includes(each.spanID) &&
each.references[0].spanID === span.spanID &&
each.references[0].refType === 'CHILD_OF'
const cdr = new DRange(span.startTime, span.startTime + span.duration - 1).intersect(
Copy link
Member

Choose a reason for hiding this comment

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

I prefer to keep the original logic parent.subtract(children). Your change does not require modifying that logic since all you need to do is cache children mapping.

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

Copy link

codecov bot commented Nov 17, 2023

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (85303aa) 96.54% compared to head (d2943f3) 96.54%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1941   +/-   ##
=======================================
  Coverage   96.54%   96.54%           
=======================================
  Files         256      256           
  Lines        7604     7613    +9     
  Branches     1978     1978           
=======================================
+ Hits         7341     7350    +9     
  Misses        263      263           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Signed-off-by: Maksim Gaponov <gaponovmaxev@gmail.com>
@maxgaponov
Copy link
Contributor Author

Seems like everything is fixed. Can you please review it again? @yurishkuro

@yurishkuro yurishkuro added the changelog:bugfix-or-minor-feature 🐞 Bug fixes, Minor Improvements label Nov 27, 2023
each.references[0].spanID === span.spanID &&
each.references[0].refType === 'CHILD_OF'
if (!span.hasChildren) return span.duration;
const spanRange = new DRange(span.startTime, span.startTime + span.duration - 1).subtract(
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we can change the logic away from *10. DRange does not work correctly on the raw timestamps (see the comments above).

Side note: we need a test that illustrates that.

Copy link
Member

@yurishkuro yurishkuro Nov 27, 2023

Choose a reason for hiding this comment

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

I don't understand why the calculations need to change - the speed-up is coming from building a map once instead of n^2 looping, so why not change just that part and leave the calculations intact?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In the change we use DRange(begin, end - 1) to represent halp-open intervals. The length of this DRange is (end-1)-begin+1=end-begin because DRange treats all intervals as inclusive.

In the example above (1, 10) will be represented as DRange(1, 9); (4, 8) will be represented as DRange(4, 7). So first.substract(second) will be range([1..3], [8..9]) (length = 3+2=5).

As I understand there is a mistake in the comment in the calculation of Drange.length.

Copy link
Member

Choose a reason for hiding this comment

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

That still doesn't answer my question why calculations need to change, it a PR that is about efficiency of the code.

If you want to dig down to the exact reasons for *10 logic, you can see the comment as well as the discussion on the original PR that introduced it. TLDR is that DRange does not understand open/close intervals, and subtraction works incorrectly for our purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agree. It shouldn't be changed in this PR. Returned to the initial version.

Signed-off-by: Maksim Gaponov <gaponovmaxev@gmail.com>
maxgaponov and others added 4 commits November 29, 2023 09:20
Co-authored-by: Yuri Shkuro <yurishkuro@users.noreply.github.com>
Signed-off-by: Maksim <gaponovmaxev@gmail.com>
Signed-off-by: Maksim Gaponov <gaponovmaxev@gmail.com>
Signed-off-by: Yuri Shkuro <github@ysh.us>
@yurishkuro yurishkuro merged commit 112e880 into jaegertracing:main Nov 29, 2023
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog:bugfix-or-minor-feature 🐞 Bug fixes, Minor Improvements
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature]: Speed up Trace Statistics view calculation
2 participants