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

dgram: use uv_udp_try_send() #29832

Closed
wants to merge 2 commits into from
Closed

Conversation

addaleax
Copy link
Member

@addaleax addaleax commented Oct 3, 2019

This improves dgram performance by avoiding unnecessary async
operations.

One issue with this commit is that it seems hard to actually create
conditions under which the fallback path to the async case is
actually taken, for all supported OS, so an internal CLI option
is used for testing that path.

Another caveat is that the lack of an async operation means
that there are slight timing differences (essentially nextTick()
rather than setImmediate() for the send callback).

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

This improves dgram performance by avoiding unnecessary async
operations.

One issue with this commit is that it seems hard to actually create
conditions under which the fallback path to the async case is
actually taken, for all supported OS, so an internal CLI option
is used for testing that path.

Another caveat is that the lack of an async operation means
that there are slight timing differences (essentially `nextTick()`
rather than `setImmediate()` for the send callback).
@addaleax addaleax added the dgram Issues and PRs related to the dgram subsystem / UDP. label Oct 3, 2019
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. labels Oct 3, 2019
@nodejs-github-bot
Copy link
Collaborator

@addaleax
Copy link
Member Author

addaleax commented Oct 3, 2019

@addaleax addaleax added performance Issues and PRs related to the performance of Node.js. and removed lib / src Issues and PRs related to general changes in the lib or src directory. labels Oct 3, 2019
@addaleax
Copy link
Member Author

addaleax commented Oct 4, 2019

Benchmark results
                                                                        confidence improvement accuracy (*)    (**)   (***)
 dgram/array-vs-concat.js dur=5 type='concat' chunks=1 num=100 len=1024        ***     15.76 %       ±3.18%  ±4.21%  ±5.46%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=1 num=100 len=256         ***     27.61 %       ±8.81% ±11.70% ±15.18%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=1 num=100 len=512         ***     29.55 %       ±8.83% ±11.72% ±15.18%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=1 num=100 len=64          ***     11.52 %       ±4.18%  ±5.53%  ±7.13%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=2 num=100 len=1024        ***     15.41 %       ±3.90%  ±5.17%  ±6.68%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=2 num=100 len=256         ***     31.09 %       ±9.10% ±12.08% ±15.66%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=2 num=100 len=512         ***     24.64 %       ±8.69% ±11.53% ±14.93%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=2 num=100 len=64          ***     14.61 %       ±5.33%  ±7.05%  ±9.10%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=4 num=100 len=1024        ***     14.19 %       ±3.59%  ±4.75%  ±6.14%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=4 num=100 len=256         ***     26.91 %       ±8.15% ±10.81% ±14.03%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=4 num=100 len=512         ***     14.44 %       ±6.92%  ±9.18% ±11.87%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=4 num=100 len=64          ***      7.61 %       ±3.51%  ±4.64%  ±5.99%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=8 num=100 len=1024        ***     18.07 %       ±3.87%  ±5.13%  ±6.64%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=8 num=100 len=256         ***     27.15 %       ±8.17% ±10.84% ±14.05%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=8 num=100 len=512         ***     16.23 %       ±7.36%  ±9.75% ±12.61%
 dgram/array-vs-concat.js dur=5 type='concat' chunks=8 num=100 len=64          ***     10.39 %       ±4.38%  ±5.80%  ±7.48%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=1 num=100 len=1024         ***     20.23 %       ±6.54%  ±8.68% ±11.26%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=1 num=100 len=256          ***     27.09 %       ±7.00%  ±9.30% ±12.05%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=1 num=100 len=512          ***     25.06 %       ±7.64% ±10.14% ±13.15%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=1 num=100 len=64           ***     11.35 %       ±3.00%  ±3.96%  ±5.12%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=2 num=100 len=1024         ***     16.78 %       ±5.66%  ±7.49%  ±9.67%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=2 num=100 len=256          ***     16.37 %       ±5.50%  ±7.28%  ±9.41%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=2 num=100 len=512          ***     20.55 %       ±5.21%  ±6.90%  ±8.94%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=2 num=100 len=64           ***      6.06 %       ±3.34%  ±4.41%  ±5.69%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=4 num=100 len=1024         ***     15.41 %       ±6.13%  ±8.11% ±10.47%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=4 num=100 len=256          ***     19.48 %       ±5.79%  ±7.66%  ±9.89%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=4 num=100 len=512          ***     18.07 %       ±5.84%  ±7.74%  ±9.99%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=4 num=100 len=64           ***     13.45 %       ±4.27%  ±5.66%  ±7.31%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=8 num=100 len=1024         ***     29.61 %       ±9.00% ±11.93% ±15.43%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=8 num=100 len=256          ***     20.40 %       ±6.59%  ±8.74% ±11.31%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=8 num=100 len=512          ***     19.48 %       ±7.26%  ±9.63% ±12.47%
 dgram/array-vs-concat.js dur=5 type='multi' chunks=8 num=100 len=64           ***     12.97 %       ±4.16%  ±5.50%  ±7.10%
 dgram/bind-params.js address='false' port='false' n=10000                             -0.24 %       ±3.94%  ±5.20%  ±6.71%
 dgram/bind-params.js address='false' port='true' n=10000                               2.32 %       ±4.12%  ±5.45%  ±7.03%
 dgram/bind-params.js address='true' port='true' n=10000                                2.39 %       ±4.01%  ±5.30%  ±6.84%
 dgram/multi-buffer.js dur=5 type='recv' chunks=1 num=100 len=1024             ***     10.21 %       ±4.94%  ±6.54%  ±8.47%
 dgram/multi-buffer.js dur=5 type='recv' chunks=1 num=100 len=256              ***     14.01 %       ±5.05%  ±6.69%  ±8.65%
 dgram/multi-buffer.js dur=5 type='recv' chunks=1 num=100 len=64               ***     10.44 %       ±3.64%  ±4.82%  ±6.21%
 dgram/multi-buffer.js dur=5 type='recv' chunks=2 num=100 len=1024             ***     15.47 %       ±5.12%  ±6.78%  ±8.76%
 dgram/multi-buffer.js dur=5 type='recv' chunks=2 num=100 len=256              ***     15.83 %       ±4.93%  ±6.53%  ±8.44%
 dgram/multi-buffer.js dur=5 type='recv' chunks=2 num=100 len=64               ***      6.91 %       ±2.66%  ±3.52%  ±4.54%
 dgram/multi-buffer.js dur=5 type='recv' chunks=4 num=100 len=1024             ***      9.19 %       ±4.76%  ±6.30%  ±8.13%
 dgram/multi-buffer.js dur=5 type='recv' chunks=4 num=100 len=256              ***     20.84 %       ±6.68%  ±8.85% ±11.44%
 dgram/multi-buffer.js dur=5 type='recv' chunks=4 num=100 len=64                **      4.46 %       ±3.09%  ±4.08%  ±5.26%
 dgram/multi-buffer.js dur=5 type='recv' chunks=8 num=100 len=1024             ***     17.39 %       ±6.88%  ±9.12% ±11.81%
 dgram/multi-buffer.js dur=5 type='recv' chunks=8 num=100 len=256              ***     19.47 %       ±7.13%  ±9.45% ±12.23%
 dgram/multi-buffer.js dur=5 type='recv' chunks=8 num=100 len=64               ***     17.37 %       ±4.66%  ±6.17%  ±7.97%
 dgram/multi-buffer.js dur=5 type='send' chunks=1 num=100 len=1024             ***     21.15 %       ±6.67%  ±8.86% ±11.50%
 dgram/multi-buffer.js dur=5 type='send' chunks=1 num=100 len=256              ***     15.04 %       ±5.16%  ±6.85%  ±8.87%
 dgram/multi-buffer.js dur=5 type='send' chunks=1 num=100 len=64               ***     12.65 %       ±3.13%  ±4.14%  ±5.36%
 dgram/multi-buffer.js dur=5 type='send' chunks=2 num=100 len=1024             ***     16.03 %       ±6.39%  ±8.46% ±10.94%
 dgram/multi-buffer.js dur=5 type='send' chunks=2 num=100 len=256              ***     15.56 %       ±5.54%  ±7.33%  ±9.46%
 dgram/multi-buffer.js dur=5 type='send' chunks=2 num=100 len=64               ***      9.41 %       ±3.58%  ±4.73%  ±6.10%
 dgram/multi-buffer.js dur=5 type='send' chunks=4 num=100 len=1024             ***     13.31 %       ±5.92%  ±7.83% ±10.11%
 dgram/multi-buffer.js dur=5 type='send' chunks=4 num=100 len=256              ***     12.62 %       ±5.50%  ±7.28%  ±9.40%
 dgram/multi-buffer.js dur=5 type='send' chunks=4 num=100 len=64               ***      5.86 %       ±3.19%  ±4.22%  ±5.44%
 dgram/multi-buffer.js dur=5 type='send' chunks=8 num=100 len=1024             ***     20.88 %       ±7.38%  ±9.77% ±12.64%
 dgram/multi-buffer.js dur=5 type='send' chunks=8 num=100 len=256              ***     29.32 %       ±7.99% ±10.59% ±13.72%
 dgram/multi-buffer.js dur=5 type='send' chunks=8 num=100 len=64               ***     12.77 %       ±4.44%  ±5.88%  ±7.58%
 dgram/offset-length.js dur=5 type='recv' num=100 len=1                         **      5.68 %       ±3.59%  ±4.75%  ±6.13%
 dgram/offset-length.js dur=5 type='recv' num=100 len=1024                     ***     14.28 %       ±4.55%  ±6.03%  ±7.77%
 dgram/offset-length.js dur=5 type='recv' num=100 len=256                        *      6.38 %       ±5.12%  ±6.77%  ±8.73%
 dgram/offset-length.js dur=5 type='recv' num=100 len=64                       ***      7.20 %       ±3.61%  ±4.77%  ±6.15%
 dgram/offset-length.js dur=5 type='send' num=100 len=1                        ***      7.99 %       ±3.69%  ±4.87%  ±6.28%
 dgram/offset-length.js dur=5 type='send' num=100 len=1024                     ***     16.19 %       ±4.67%  ±6.18%  ±7.97%
 dgram/offset-length.js dur=5 type='send' num=100 len=256                      ***     10.41 %       ±3.80%  ±5.02%  ±6.48%
 dgram/offset-length.js dur=5 type='send' num=100 len=64                       ***      8.24 %       ±3.69%  ±4.88%  ±6.29%
 dgram/single-buffer.js dur=5 type='recv' num=100 len=1                        ***     13.37 %       ±4.19%  ±5.55%  ±7.16%
 dgram/single-buffer.js dur=5 type='recv' num=100 len=1024                     ***     19.70 %       ±7.01%  ±9.31% ±12.08%
 dgram/single-buffer.js dur=5 type='recv' num=100 len=256                      ***     14.51 %       ±4.99%  ±6.62%  ±8.58%
 dgram/single-buffer.js dur=5 type='recv' num=100 len=64                       ***     12.94 %       ±3.87%  ±5.12%  ±6.61%
 dgram/single-buffer.js dur=5 type='send' num=100 len=1                        ***     14.86 %       ±3.78%  ±5.01%  ±6.47%
 dgram/single-buffer.js dur=5 type='send' num=100 len=1024                     ***     20.56 %       ±6.77%  ±8.99% ±11.66%
 dgram/single-buffer.js dur=5 type='send' num=100 len=256                      ***     13.47 %       ±5.30%  ±7.03%  ±9.10%
 dgram/single-buffer.js dur=5 type='send' num=100 len=64                       ***     10.76 %       ±3.55%  ±4.70%  ±6.06%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case there are 75 comparisons, you can thus
expect the following amount of false-positive results:
  3.75 false positives, when considering a   5% risk acceptance (*, **, ***),
  0.75 false positives, when considering a   1% risk acceptance (**, ***),
  0.07 false positives, when considering a 0.1% risk acceptance (***)

src/udp_wrap.cc Outdated Show resolved Hide resolved
lib/dgram.js Show resolved Hide resolved
@addaleax addaleax added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Oct 4, 2019
@nodejs-github-bot
Copy link
Collaborator

Trott pushed a commit that referenced this pull request Oct 6, 2019
This improves dgram performance by avoiding unnecessary async
operations.

One issue with this commit is that it seems hard to actually create
conditions under which the fallback path to the async case is
actually taken, for all supported OS, so an internal CLI option
is used for testing that path.

Another caveat is that the lack of an async operation means
that there are slight timing differences (essentially `nextTick()`
rather than `setImmediate()` for the send callback).

PR-URL: #29832
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
@Trott
Copy link
Member

Trott commented Oct 6, 2019

Landed in afdc3d0

(Also, confirmed before landing that test/benchmark/test-benchmark-dgram.js still passes!)

@Trott Trott closed this Oct 6, 2019
BridgeAR pushed a commit that referenced this pull request Oct 9, 2019
This improves dgram performance by avoiding unnecessary async
operations.

One issue with this commit is that it seems hard to actually create
conditions under which the fallback path to the async case is
actually taken, for all supported OS, so an internal CLI option
is used for testing that path.

Another caveat is that the lack of an async operation means
that there are slight timing differences (essentially `nextTick()`
rather than `setImmediate()` for the send callback).

PR-URL: #29832
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
addaleax added a commit to nodejs/quic that referenced this pull request Oct 9, 2019
This improves dgram performance by avoiding unnecessary async
operations.

One issue with this commit is that it seems hard to actually create
conditions under which the fallback path to the async case is
actually taken, for all supported OS, so an internal CLI option
is used for testing that path.

Another caveat is that the lack of an async operation means
that there are slight timing differences (essentially `nextTick()`
rather than `setImmediate()` for the send callback).

PR-URL: nodejs/node#29832
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
@BridgeAR BridgeAR mentioned this pull request Oct 10, 2019
addaleax added a commit to nodejs/quic that referenced this pull request Oct 11, 2019
This improves dgram performance by avoiding unnecessary async
operations.

One issue with this commit is that it seems hard to actually create
conditions under which the fallback path to the async case is
actually taken, for all supported OS, so an internal CLI option
is used for testing that path.

Another caveat is that the lack of an async operation means
that there are slight timing differences (essentially `nextTick()`
rather than `setImmediate()` for the send callback).

PR-URL: nodejs/node#29832
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
addaleax added a commit to nodejs/quic that referenced this pull request Oct 16, 2019
This improves dgram performance by avoiding unnecessary async
operations.

One issue with this commit is that it seems hard to actually create
conditions under which the fallback path to the async case is
actually taken, for all supported OS, so an internal CLI option
is used for testing that path.

Another caveat is that the lack of an async operation means
that there are slight timing differences (essentially `nextTick()`
rather than `setImmediate()` for the send callback).

PR-URL: nodejs/node#29832
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
addaleax added a commit to nodejs/quic that referenced this pull request Oct 16, 2019
This improves dgram performance by avoiding unnecessary async
operations.

One issue with this commit is that it seems hard to actually create
conditions under which the fallback path to the async case is
actually taken, for all supported OS, so an internal CLI option
is used for testing that path.

Another caveat is that the lack of an async operation means
that there are slight timing differences (essentially `nextTick()`
rather than `setImmediate()` for the send callback).

PR-URL: nodejs/node#29832
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
@addaleax addaleax deleted the dgram-try-send branch October 18, 2019 22:26
juanarbol pushed a commit to juanarbol/quic that referenced this pull request Dec 17, 2019
This improves dgram performance by avoiding unnecessary async
operations.

One issue with this commit is that it seems hard to actually create
conditions under which the fallback path to the async case is
actually taken, for all supported OS, so an internal CLI option
is used for testing that path.

Another caveat is that the lack of an async operation means
that there are slight timing differences (essentially `nextTick()`
rather than `setImmediate()` for the send callback).

PR-URL: nodejs/node#29832
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
juanarbol pushed a commit to juanarbol/quic that referenced this pull request Dec 17, 2019
This improves dgram performance by avoiding unnecessary async
operations.

One issue with this commit is that it seems hard to actually create
conditions under which the fallback path to the async case is
actually taken, for all supported OS, so an internal CLI option
is used for testing that path.

Another caveat is that the lack of an async operation means
that there are slight timing differences (essentially `nextTick()`
rather than `setImmediate()` for the send callback).

PR-URL: nodejs/node#29832
Reviewed-By: David Carlier <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ben Noordhuis <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. dgram Issues and PRs related to the dgram subsystem / UDP. performance Issues and PRs related to the performance of Node.js.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants