-
Notifications
You must be signed in to change notification settings - Fork 239
perf: AsyncLocalStorageRunContextManager #2786
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
Conversation
Implement a run-context manager using AsyncLocalStorage. Newer versions
of node (>=14.5, >=12.19) should benefit from significant better perf
compared to AsyncHooksRunContextManager, esp. for promise-heavy apps.
See the many async_hooks-related improvements in:
https://nodejs.org/en/blog/release/v14.5.0/
https://nodejs.org/en/blog/release/v12.19.0/
…o allow selecting any of the 3 run context tracking techniques. Values are 'patch', 'asynchooks', and 'asynclocalstorage'.
…nterfere with tests
…ontextManager can inherit from *it* and not from BvasicRunContextManager which has _enter/_leave and _stack handling that the ALS class doesn't need
|
@astorm Some review notes that might help. The initial work for this was to 3 files, but that become 27 files after config, docs, and test changes. Review notesThere are a few parts to this change that can mostly be reviewed separately:
|
astorm
left a comment
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.
Code looks good and an AsyncLocalStorage option is a welcome change (especially with the potential perf. improvements for Kibana). The class hierarchy makes sense and the configuration looks like it will correctly honor the asyncHooks:false for folks upgrading.
I don't have a lot of insight on the changes to the CI and what context managers are/aren't tested -- so if you have anything you're nervous about there you should probably get a second opinion but I don't have any objections to committing those changes.
docs/configuration.asciidoc
Outdated
| agent supports a limited tracking mechanism (named "patch") that monkey-patches | ||
| much of the core Node.js API to attempt to follow asynchronous calls. The | ||
| "patch" mechanism is limited in usage and coverage (for example, it cannot | ||
| track `async/await` usage), is not recommended, and may be deprecated and |
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.
I'd +1 deprecating patch now to give us/users a long run way in it going away forever.
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.
| } else { | ||
| // Select the appropriate run-context manager. | ||
| const confContextManager = this._agent._conf.contextManager | ||
| if (confContextManager === config.CONTEXT_MANAGER_PATCH) { |
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.
👍 Appears to preserve a user's desires when asyncHooks: false is set to false with no other configuration -- so we should be good here from a backwards compatibility point of view) (i.e uses the basic run context manager)
| // A basic manager for run context. It handles a stack of run contexts, but does | ||
| // no automatic tracking (via async_hooks or otherwise). In combination with | ||
| // "patch-async.js" it does an adequate job of context tracking for much of the | ||
| // "patch-async.js" it does a limited job of context tracking for much of the |
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.
🔥 🔥 🔥 🔥
Implement a run-context manager using AsyncLocalStorage. Newer versions
of node (>=14.5, >=12.19) should benefit from significant better perf
compared to AsyncHooksRunContextManager, esp. for promise-heavy apps.
See the many async_hooks-related improvements in:
https://nodejs.org/en/blog/release/v14.5.0/
https://nodejs.org/en/blog/release/v12.19.0/
Refs: #2745