-
Notifications
You must be signed in to change notification settings - Fork 805
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
AsyncLocalStorage based ContextManager #1210
AsyncLocalStorage based ContextManager #1210
Conversation
Codecov Report
@@ Coverage Diff @@
## master #1210 +/- ##
==========================================
+ Coverage 93.23% 93.29% +0.06%
==========================================
Files 122 124 +2
Lines 3550 3567 +17
Branches 714 715 +1
==========================================
+ Hits 3310 3328 +18
+ Misses 240 239 -1
|
Think @OlivierAlbertini should weigh in on this, but in general I am not against including a more performant context manager. As far as feature detection goes, I'm not sure how I feel about having the default behavior change based on which version of node you use, but I am open to being convinced otherwise. |
7ebbadb
to
b3f41f6
Compare
As a datapoint from our mildly complex express app on node
|
@dyladan Think you meant to tag me since Olivier didn't work on this part ^^
We didn't yet test it in OT, someone already brought the suggestion here however my main complain with it was simply that the API is still experimental (way more than
This is mandatory for me since we support node 8, 10 and versions that doesn't have this API. Also it allows users to opt-in.
It may in the future but i would be against for now for reasons cited above. I totally agree that this is the way forward (for both performance and correctness reasons) but i would prefer to wait to have real world usage feedback.
Correct me if i'm wrong but AsyncLocalStorage does track promise too (see this) with the PromiseHook API ? To sum everything i said, i'm totally fine having a PS: On the benchmark i believe it would be better to make micro-benchark (see #1123) because other code (that get JIT'ed by V8) might influence the result. |
AsyncLocalStorage is as stable as async_hooks at this point, if not more so due to the reduced surface area. It uses async_hooks internally, so everything async_hooks can handle it can handle too. Through async_hooks it uses promise hooks, however I made some changes to skip the additional garbage collection tracking to emit destroy events for promises if there is no destroy hook present. AsyncLocalStorage only uses the init hook and the executionAsyncResource function, so it has much simpler needs than the full async_hooks capabilities. It can function without much of the usual overhead of async_hooks. Both async_hooks and AsyncLocalStorage have also had issues with thenables. I have a fix that has already landed in V8 and is just in the process of landing in Node.js now. Beyond that, AsyncLocalStorage should be stable enough for regular use. I’m still working on some more changes to async_hooks, but those are largely internal-facing other than some performance improvements. |
b3f41f6
to
7f2e429
Compare
@vmarchaud introduced |
7f2e429
to
f3ecab4
Compare
packages/opentelemetry-context-async-hooks/test/AsyncHooksContextManager.test.ts
Outdated
Show resolved
Hide resolved
@johanneswuerbach Looks great overall ! I will take a closer look tomorrow. I'm wondering whats the best approach to maintain both implementation, should we make two different package ? The switch between |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very large diff makes it difficult to see if the tests have been modified beyond just running them with both context managers. Did you end up adding/removing/changing any tests?
packages/opentelemetry-context-async-hooks/src/BaseContextManager.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-context-async-hooks/src/BaseContextManager.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-context-async-hooks/src/BaseContextManager.ts
Outdated
Show resolved
Hide resolved
packages/opentelemetry-context-async-hooks/src/BaseContextManager.ts
Outdated
Show resolved
Hide resolved
Use AsyncLocalStorage in ContentManager to improve performance
f3ecab4
to
4f9e8f2
Compare
@dyladan I didn't remove any tests, hiding whitespaces https://github.com/open-telemetry/opentelemetry-js/pull/1210/files?diff=split&w=1 should make this more easy to compare. I tried to touch as least code as possible, should I maybe split this up into two commits: a) adding the new base context manager ? |
@johanneswuerbach Wow i didnt know that you could remove the whitespace diff from github, thanks ! Should be the default ahah |
Cool. Please try to avoid changing history and force pushing during the review process. It breaks the github emails and links, and breaks the link between conversations and code. |
packages/opentelemetry-context-async-hooks/src/AbstractAsyncHooksContextManager.ts
Show resolved
Hide resolved
packages/opentelemetry-context-async-hooks/src/AsyncLocalStorageContextManager.ts
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm, i will report with some production feedback when this will get merged. I've had weird trace with the current impl and was wondering if it's linked to it or something downstream in the collectors that i run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry I’m not sure about the process, should i squash my commits now? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mentioned you did some performance tests, I wonder if you could create some performance test here (we have benchmark folder). It might be useful to somehow compare it in future whoever will decide to refactor this again and then check if it was improved or not. This doesn't need to be in this PR so can be a separate issue - not a blocker here., thx
don't merge, please wait for maintainer |
Commits are squashed during the merge process anyway so it isn't that important unless you want the message to say something specific.
he doesn't even have permission to merge. Only approvers/maintainers do. |
Which problem is this PR solving?
Performance impact of using the current nodejs default context manager.
Short description of the changes
async_hooks
especially with promise executing tracking enabled are known to have a significant performance impact nodejs/benchmarking#181Luckily there is a new API in node AsyncLocalStorage (available since v13.10.0+ and v12.17.0+), which is supposed to be scoped more towards the ContextManager use-case and is more performant.
AsyncLocalStorage
recently received additional perf improvements nodejs/node#32891 and has more planned nodejs/diagnostics#376As this is a fairly recent API, I'm sure this can't be accepted as is and should be seen more as a conversation starter.
Open question:
AsyncLocalStorage
already tested and discarded (all test pass, but I might miss something)AsyncLocalStorage
and use this as default?