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

async_hooks,process: remove internalNextTick #19147

Closed

Conversation

apapirovski
Copy link
Member

Instead of having mostly duplicate code in form of internalNextTick, instead use the existing defaultAsyncTriggerIdScope with a slight modification which allows undefined triggerAsyncId to be passed in, which then just triggers the callback with the provided arguments.

(The ability to pass in undefined removes the need for a bunch of conditional checks for whether the asyncId is set on a given resource.)

Refs: #19104

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

async_hooks, http, dgram, net, process, test

@apapirovski apapirovski added process Issues and PRs related to the process subsystem. async_hooks Issues and PRs related to the async hooks subsystem. labels Mar 5, 2018
@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs related to general changes in the lib or src directory. label Mar 5, 2018
@@ -342,10 +341,7 @@ Agent.prototype.destroy = function destroy() {
function handleSocketCreation(request, informRequest) {
return function handleSocketCreation_Inner(err, socket) {
if (err) {
const asyncId = (socket && socket._handle && socket._handle.getAsyncId) ?
Copy link
Member Author

@apapirovski apapirovski Mar 5, 2018

Choose a reason for hiding this comment

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

After checking all the call sites, it's not possible to receive a socket here if err is truthy. (I've also double-checked this by adding an assert during debugging.)

if (socketAsyncId === undefined) socketAsyncId = null;

nextTick(socketAsyncId, callback);
defaultTriggerAsyncIdScope(conn[async_id_symbol],
Copy link
Member

Choose a reason for hiding this comment

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

Is conn[async_id_symbol] === this.socket[async_id_symbol]? Also, this changes the socketAsyncId so if this is correct the comment should be updated too.

Copy link
Member Author

Choose a reason for hiding this comment

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

conn === this.socket so it's equivalent. Not quite clear on the second part of the feedback — the comment above it still applies.

@AndreasMadsen
Copy link
Member

AndreasMadsen commented Mar 5, 2018

I think we should benchmark the http throughput before landing this.

edit: also, it is kinda an implementation detail that undefined works as expected. The function actually "asserts" that it isn't undefined. https://github.com/nodejs/node/blob/master/lib/internal/async_hooks.js#L284

@apapirovski
Copy link
Member Author

apapirovski commented Mar 5, 2018

Benchmark CI: https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/129/ (only http/simple and will go from there, don't want to tie up the CI for 40 hours)

@apapirovski
Copy link
Member Author

edit: also, it is kinda an implementation detail that undefined works as expected. The function actually "asserts" that it isn't undefined. https://github.com/nodejs/node/blob/master/lib/internal/async_hooks.js#L284

I've adjusted the function to special handle undefined. It would be incorrect to use it with the current version.

@apapirovski
Copy link
Member Author

Nothing meaningful from the benchmark. I think these changes are very unlikely to make a difference.

                                                                                       confidence improvement accuracy (*)   (**)   (***)
 http/simple.js chunkedEnc=0 c=500 chunks=1 len=102400 type='buffer' benchmarker='wrk'                -1.20 %       ±6.91% ±9.19% ±11.96%
 http/simple.js chunkedEnc=0 c=500 chunks=1 len=102400 type='bytes' benchmarker='wrk'                  1.41 %       ±4.84% ±6.45%  ±8.41%
 http/simple.js chunkedEnc=0 c=500 chunks=1 len=1024 type='buffer' benchmarker='wrk'                   2.26 %       ±3.52% ±4.69%  ±6.10%
 http/simple.js chunkedEnc=0 c=500 chunks=1 len=1024 type='bytes' benchmarker='wrk'                    0.89 %       ±4.21% ±5.61%  ±7.33%
 http/simple.js chunkedEnc=0 c=500 chunks=1 len=4 type='buffer' benchmarker='wrk'                     -2.00 %       ±3.70% ±4.92%  ±6.41%
 http/simple.js chunkedEnc=0 c=500 chunks=1 len=4 type='bytes' benchmarker='wrk'               **     -5.23 %       ±3.53% ±4.70%  ±6.11%
 http/simple.js chunkedEnc=0 c=500 chunks=4 len=102400 type='buffer' benchmarker='wrk'                -1.02 %       ±5.79% ±7.70% ±10.02%
 http/simple.js chunkedEnc=0 c=500 chunks=4 len=102400 type='bytes' benchmarker='wrk'                  0.21 %       ±3.06% ±4.08%  ±5.31%
 http/simple.js chunkedEnc=0 c=500 chunks=4 len=1024 type='buffer' benchmarker='wrk'                   2.30 %       ±3.86% ±5.13%  ±6.68%
 http/simple.js chunkedEnc=0 c=500 chunks=4 len=1024 type='bytes' benchmarker='wrk'                    0.78 %       ±3.72% ±4.95%  ±6.46%
 http/simple.js chunkedEnc=0 c=500 chunks=4 len=4 type='buffer' benchmarker='wrk'                     -0.21 %       ±3.52% ±4.68%  ±6.09%
 http/simple.js chunkedEnc=0 c=500 chunks=4 len=4 type='bytes' benchmarker='wrk'                       1.51 %       ±3.27% ±4.36%  ±5.68%
 http/simple.js chunkedEnc=0 c=50 chunks=1 len=102400 type='buffer' benchmarker='wrk'                 -0.59 %       ±5.48% ±7.29%  ±9.49%
 http/simple.js chunkedEnc=0 c=50 chunks=1 len=102400 type='bytes' benchmarker='wrk'                   2.26 %       ±3.39% ±4.52%  ±5.89%
 http/simple.js chunkedEnc=0 c=50 chunks=1 len=1024 type='buffer' benchmarker='wrk'                    2.56 %       ±2.76% ±3.67%  ±4.78%
 http/simple.js chunkedEnc=0 c=50 chunks=1 len=1024 type='bytes' benchmarker='wrk'                    -1.84 %       ±3.73% ±4.96%  ±6.45%
 http/simple.js chunkedEnc=0 c=50 chunks=1 len=4 type='buffer' benchmarker='wrk'               **      3.48 %       ±2.50% ±3.34%  ±4.35%
 http/simple.js chunkedEnc=0 c=50 chunks=1 len=4 type='bytes' benchmarker='wrk'                       -1.75 %       ±3.37% ±4.48%  ±5.83%
 http/simple.js chunkedEnc=0 c=50 chunks=4 len=102400 type='buffer' benchmarker='wrk'                 -0.66 %       ±5.72% ±7.61%  ±9.90%
 http/simple.js chunkedEnc=0 c=50 chunks=4 len=102400 type='bytes' benchmarker='wrk'                  -0.44 %       ±2.71% ±3.61%  ±4.69%
 http/simple.js chunkedEnc=0 c=50 chunks=4 len=1024 type='buffer' benchmarker='wrk'                   -0.31 %       ±3.58% ±4.77%  ±6.21%
 http/simple.js chunkedEnc=0 c=50 chunks=4 len=1024 type='bytes' benchmarker='wrk'                     0.35 %       ±3.26% ±4.34%  ±5.66%
 http/simple.js chunkedEnc=0 c=50 chunks=4 len=4 type='buffer' benchmarker='wrk'                       2.11 %       ±3.29% ±4.38%  ±5.71%
 http/simple.js chunkedEnc=0 c=50 chunks=4 len=4 type='bytes' benchmarker='wrk'                        1.13 %       ±3.31% ±4.41%  ±5.74%
 http/simple.js chunkedEnc=1 c=500 chunks=1 len=102400 type='buffer' benchmarker='wrk'                 0.54 %       ±6.20% ±8.25% ±10.74%
 http/simple.js chunkedEnc=1 c=500 chunks=1 len=102400 type='bytes' benchmarker='wrk'                  1.06 %       ±3.15% ±4.19%  ±5.45%
 http/simple.js chunkedEnc=1 c=500 chunks=1 len=1024 type='buffer' benchmarker='wrk'                   1.66 %       ±4.81% ±6.40%  ±8.33%
 http/simple.js chunkedEnc=1 c=500 chunks=1 len=1024 type='bytes' benchmarker='wrk'                    1.11 %       ±4.78% ±6.37%  ±8.32%
 http/simple.js chunkedEnc=1 c=500 chunks=1 len=4 type='buffer' benchmarker='wrk'                      3.30 %       ±3.86% ±5.14%  ±6.71%
 http/simple.js chunkedEnc=1 c=500 chunks=1 len=4 type='bytes' benchmarker='wrk'                       2.30 %       ±4.43% ±5.89%  ±7.67%
 http/simple.js chunkedEnc=1 c=500 chunks=4 len=102400 type='buffer' benchmarker='wrk'                 3.67 %       ±5.22% ±6.95%  ±9.05%
 http/simple.js chunkedEnc=1 c=500 chunks=4 len=102400 type='bytes' benchmarker='wrk'                 -0.62 %       ±2.63% ±3.50%  ±4.56%
 http/simple.js chunkedEnc=1 c=500 chunks=4 len=1024 type='buffer' benchmarker='wrk'                  -0.85 %       ±4.55% ±6.06%  ±7.88%
 http/simple.js chunkedEnc=1 c=500 chunks=4 len=1024 type='bytes' benchmarker='wrk'                   -3.76 %       ±4.87% ±6.48%  ±8.45%
 http/simple.js chunkedEnc=1 c=500 chunks=4 len=4 type='buffer' benchmarker='wrk'                      1.97 %       ±5.12% ±6.82%  ±8.87%
 http/simple.js chunkedEnc=1 c=500 chunks=4 len=4 type='bytes' benchmarker='wrk'                       2.05 %       ±4.80% ±6.39%  ±8.31%
 http/simple.js chunkedEnc=1 c=50 chunks=1 len=102400 type='buffer' benchmarker='wrk'                  1.59 %       ±6.32% ±8.42% ±10.96%
 http/simple.js chunkedEnc=1 c=50 chunks=1 len=102400 type='bytes' benchmarker='wrk'                   1.36 %       ±3.22% ±4.28%  ±5.57%
 http/simple.js chunkedEnc=1 c=50 chunks=1 len=1024 type='buffer' benchmarker='wrk'                   -1.28 %       ±3.73% ±4.96%  ±6.46%
 http/simple.js chunkedEnc=1 c=50 chunks=1 len=1024 type='bytes' benchmarker='wrk'                    -1.58 %       ±2.66% ±3.54%  ±4.61%
 http/simple.js chunkedEnc=1 c=50 chunks=1 len=4 type='buffer' benchmarker='wrk'                      -0.04 %       ±3.53% ±4.70%  ±6.12%
 http/simple.js chunkedEnc=1 c=50 chunks=1 len=4 type='bytes' benchmarker='wrk'                       -0.27 %       ±3.74% ±4.98%  ±6.48%
 http/simple.js chunkedEnc=1 c=50 chunks=4 len=102400 type='buffer' benchmarker='wrk'                  0.35 %       ±5.72% ±7.61%  ±9.91%
 http/simple.js chunkedEnc=1 c=50 chunks=4 len=102400 type='bytes' benchmarker='wrk'                   0.06 %       ±2.60% ±3.47%  ±4.51%
 http/simple.js chunkedEnc=1 c=50 chunks=4 len=1024 type='buffer' benchmarker='wrk'                   -1.18 %       ±2.71% ±3.60%  ±4.69%
 http/simple.js chunkedEnc=1 c=50 chunks=4 len=1024 type='bytes' benchmarker='wrk'                     2.16 %       ±2.54% ±3.38%  ±4.41%
 http/simple.js chunkedEnc=1 c=50 chunks=4 len=4 type='buffer' benchmarker='wrk'                      -2.10 %       ±2.41% ±3.21%  ±4.18%
 http/simple.js chunkedEnc=1 c=50 chunks=4 len=4 type='bytes' benchmarker='wrk'                       -2.06 %       ±2.74% ±3.64%  ±4.74%

Copy link
Member

@AndreasMadsen AndreasMadsen left a comment

Choose a reason for hiding this comment

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

LGTM

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 6, 2018
Instead of having mostly duplicate code in form of internalNextTick,
instead use the existing defaultAsyncTriggerIdScope with a slight
modification which allows undefined triggerAsyncId to be passed in,
which then just triggers the callback with the provided arguments.
@apapirovski apapirovski force-pushed the patch-remove-internal-nexttick branch from 7958cea to 37f6ef0 Compare March 8, 2018 12:08
@apapirovski
Copy link
Member Author

Lite CI (after rebase): https://ci.nodejs.org/job/node-test-pull-request-lite/237/

@apapirovski
Copy link
Member Author

Landed in 4d07434

@apapirovski apapirovski closed this Mar 8, 2018
@apapirovski apapirovski deleted the patch-remove-internal-nexttick branch March 8, 2018 12:24
apapirovski added a commit that referenced this pull request Mar 8, 2018
Instead of having mostly duplicate code in form of internalNextTick,
instead use the existing defaultAsyncTriggerIdScope with a slight
modification which allows undefined triggerAsyncId to be passed in,
which then just triggers the callback with the provided arguments.

PR-URL: #19147
Refs: #19104
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@targos targos removed the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 17, 2018
@targos
Copy link
Member

targos commented Mar 17, 2018

Should this be backported to v9.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

@AndreasMadsen
Copy link
Member

Yes, APM providers will appreciate if this were backported.

MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
Instead of having mostly duplicate code in form of internalNextTick,
instead use the existing defaultAsyncTriggerIdScope with a slight
modification which allows undefined triggerAsyncId to be passed in,
which then just triggers the callback with the provided arguments.

PR-URL: nodejs#19147
Refs: nodejs#19104
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Andreas Madsen <amwebdk@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
@jasnell
Copy link
Member

jasnell commented Aug 17, 2018

Should this be backported to 8.x? If so, we need a separate backport PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
async_hooks Issues and PRs related to the async hooks subsystem. lib / src Issues and PRs related to general changes in the lib or src directory. process Issues and PRs related to the process subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants