Skip to content

Conversation

@findingrish
Copy link
Contributor

@findingrish findingrish commented Jan 11, 2021

Currently we run, all the view-generators in individual services.
Although we do have a possibility of running view generator together in a single service using MultiViewGeneratorLauncher,
though that won't be very optimal due to repeated operations amongst the view-generators.

This pr tries to optimise that by caching shared state in a threadlocal, thus ensuring that for a given Trace, those operations are performed once.

Note: this changes should not affect in the case when view-generators have to be individually deployed

@findingrish findingrish requested a review from a team January 11, 2021 17:49
@codecov
Copy link

codecov bot commented Jan 11, 2021

Codecov Report

Merging #108 (b4eb664) into main (06dd320) will increase coverage by 0.76%.
The diff coverage is 80.00%.

Impacted file tree graph

@@             Coverage Diff              @@
##               main     #108      +/-   ##
============================================
+ Coverage     68.61%   69.38%   +0.76%     
- Complexity      821      830       +9     
============================================
  Files            84       85       +1     
  Lines          3486     3505      +19     
  Branches        367      369       +2     
============================================
+ Hits           2392     2432      +40     
+ Misses          950      927      -23     
- Partials        144      146       +2     
Flag Coverage Δ Complexity Δ
unit 69.38% <80.00%> (+0.76%) 0.00 <9.00> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ Complexity Δ
...ce/viewgenerator/generators/BaseViewGenerator.java 10.00% <0.00%> (+4.33%) 2.00 <0.00> (ø)
...wgenerator/generators/RawServiceViewGenerator.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...generator/generators/ServiceCallViewGenerator.java 0.00% <0.00%> (ø) 0.00 <0.00> (ø)
...e/viewgenerator/generators/ViewGeneratorState.java 93.02% <93.02%> (ø) 9.00 <9.00> (?)

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 06dd320...b4eb664. Read the comment docs.

@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@tim-mwangi
Copy link
Contributor

Unit tests?

@github-actions

This comment has been minimized.


// Construct ApiTraceGraph and look at all the head spans within each ApiNode
ApiTraceGraph apiTraceGraph = new ApiTraceGraph(structuredTrace);
ApiTraceGraph apiTraceGraph = ViewGeneratorState.getApiTraceGraph(structuredTrace);
Copy link
Contributor

@skjindal93 skjindal93 Jan 12, 2021

Choose a reason for hiding this comment

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

I think it will be easy not to make functions static, and use ViewGeneratorState as a singleton class. It would really simplify writing the unit tests for the class, because then you can easily mock ViewGeneratorState class

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will give it a try, and if it works will make the changes in a subsequent pr.

Copy link
Contributor

Choose a reason for hiding this comment

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

If it is made a singleton, remember that it should be stateless :)

return traceStateThreadLocal.get();
}

private static boolean isDifferentTrace(StructuredTrace cached, StructuredTrace trace) {
Copy link
Contributor

Choose a reason for hiding this comment

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

When will this happen in view generators?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

When the same trace is getting processed by multiple view-generators, this would return false, and we save on some repeated operations.
When a new trace starts getting processed, this would return false, leading to rebuilding of TraceState and ApiTraceGraph

Copy link
Contributor

Choose a reason for hiding this comment

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

I was mainly concerned/curious about the customer id check, but I guess that's just done for safety? Because, a trace being different means, a different trace id

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, just an additional check

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think checking for traceId is also not required, since the input trace doesn't get modified in this service. So all we need is to check for same object.

skjindal93
skjindal93 previously approved these changes Jan 12, 2021
@kotharironak
Copy link
Contributor

Tagging the corresponding issue - #102

assertNotNull(traceState);
assertEquals(trace, traceState.getTrace());

StructuredTrace modifiedTrace = getTestTrace(customerId, traceId1);
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's not modifiedTrace, its a new one, right?

Copy link
Contributor

Choose a reason for hiding this comment

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

I got it, it's the same one.

kotharironak
kotharironak previously approved these changes Jan 12, 2021
Copy link
Contributor

@kotharironak kotharironak left a comment

Choose a reason for hiding this comment

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

lgtm

@findingrish findingrish dismissed stale reviews from kotharironak and skjindal93 via 6907695 January 12, 2021 15:56
@github-actions

This comment has been minimized.

@github-actions

This comment has been minimized.

@findingrish findingrish merged commit 897c97b into main Jan 12, 2021
@findingrish findingrish deleted the optimise-all-view-gen-job branch January 12, 2021 17:11
@github-actions
Copy link

Unit Test Results

  48 files  +1    48 suites  +1   54s ⏱️ -7s
244 tests +3  244 ✔️ +3  0 💤 ±0  0 ❌ ±0 

Results for commit 897c97b. ± Comparison against base commit 06dd320.

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.

6 participants