Skip to content

Conversation

@mcollina
Copy link
Member

This PR adds support for:

  • socket.send(buf, port, host, [, callback])
  • socket.send([buf1, buf2, ... ], port, host, [, callback])

Fixes#4302.

This is probably missing some benchmarks, and might like an optimization pass, but I would like to get some feedbacks first :).

cc @ronkorving@indutny@saghul

@mcollinamcollina added dgram Issues and PRs related to the dgram subsystem / UDP. semver-minor PRs that contain new features and should be released in the next minor version. labels Dec 21, 2015
lib/dgram.js Outdated
Copy link
Member

Choose a reason for hiding this comment

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

I guess arguments fit on the same line? ;)

@mcollinamcollinaforce-pushed the new-dgram branch 2 times, most recently from c75640d to 3fe2facCompareDecember 21, 2015 09:16
@ronkorving
Copy link
Contributor

Great start, thanks a ton :) What do the benchmarks say at this time?

@mcollina
Copy link
MemberAuthor

Current benchmarks comes out slightly slower on the "old" API. These are possibly due to: #4374 (diff)

before:
net/dgram.js len=1 num=100 type=send dur=5: 0.00120
net/dgram.js len=1 num=100 type=recv dur=5: 0.00020
net/dgram.js len=64 num=100 type=send dur=5: 0.07730
net/dgram.js len=64 num=100 type=recv dur=5: 0.01255
net/dgram.js len=256 num=100 type=send dur=5: 0.30837
net/dgram.js len=256 num=100 type=recv dur=5: 0.04958
net/dgram.js len=1024 num=100 type=send dur=5: 0.71537
net/dgram.js len=1024 num=100 type=recv dur=5: 0.12022

After:
net/dgram.js len=1 num=100 type=send dur=5: 0.00106
net/dgram.js len=1 num=100 type=recv dur=5: 0.00018
net/dgram.js len=64 num=100 type=send dur=5: 0.06785
net/dgram.js len=64 num=100 type=recv dur=5: 0.01109
net/dgram.js len=256 num=100 type=send dur=5: 0.27151
net/dgram.js len=256 num=100 type=recv dur=5: 0.04330
net/dgram.js len=1024 num=100 type=send dur=5: 0.70451
net/dgram.js len=1024 num=100 type=recv dur=5: 0.11787

I have no benchmarks yet on the new APIs.

Copy link
Contributor

Choose a reason for hiding this comment

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

Use common.mustCall here, so that it will make sure that the test will fail if the callback is not invoked.

@mcollina
Copy link
MemberAuthor

@thefourtheye@indutny I have updated the tests to follow the current conventions. I will update also the other test to the same on another PR.

Copy link
Member

Choose a reason for hiding this comment

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

Not on this PR, but it would probably be nice to use uv_udp_try_send here, just in case we can send it on the spot.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I would do that after this land. Do you see any issue with switching to uv_udp_try_send?
What is the difference anyway? on what conditions it can be sent on the spot?

Copy link
Member

Choose a reason for hiding this comment

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

It's not switching, the idea is to use it to try to send the datagram on the spot, because the socket might be writable. Have a look at how uv_try_write is used in stream_wrap.cc.

Copy link
MemberAuthor

Choose a reason for hiding this comment

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

I'm 👍 on that. I'll get it done after this one.

@mcollinamcollinaforce-pushed the new-dgram branch 3 times, most recently from c1cee98 to 73ada5eCompareDecember 22, 2015 11:59
@mcollina
Copy link
MemberAuthor

I have done a pass of performance optimization in JS-land, which result in better performance for the single buffer use case (and offset/length is now on par with master).

Here are the full results:
https://gist.github.com/mcollina/e8210d26ca6ef2630e23

Unexpectedly, passing multiple buffers in an array is slower (benchmark/dgram/headers.js) than calling Buffer.concat() in js land for a large payload:

dgram/headers.js len=1024 num=100 chunks=1 headers=4 type=concat dur=5: 0.78476 dgram/headers.js len=1024 num=100 chunks=1 headers=4 type=multi dur=5: 0.67456 dgram/headers.js len=1024 num=100 chunks=2 headers=4 type=concat dur=5: 0.78631 dgram/headers.js len=1024 num=100 chunks=2 headers=4 type=multi dur=5: 0.63593 dgram/headers.js len=1024 num=100 chunks=4 headers=4 type=concat dur=5: 0.75965 dgram/headers.js len=1024 num=100 chunks=4 headers=4 type=multi dur=5: 0.63869 dgram/headers.js len=1024 num=100 chunks=8 headers=4 type=concat dur=5: 0.74356 dgram/headers.js len=1024 num=100 chunks=8 headers=4 type=multi dur=5: 0.59303 

The small buffer case (up to 256 bytes) is way faster than calling Buffer.concat().

Any ideas why this is happening? I expected it to be faster.

@thefourtheye
Copy link
Contributor

@trevnorris

lib/dgram.js Outdated
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: function name is slightly incomplete? maybe something like fixAndSumBuffers(). this is nothing serious, and not a blocker.

mcollina added a commit that referenced this pull request Feb 8, 2016
Fixes: #5124 See: #4374 PR-URL: #5130 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
rvagg pushed a commit that referenced this pull request Feb 9, 2016
Fixes: #5124 See: #4374 PR-URL: #5130 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
rvagg pushed a commit that referenced this pull request Feb 9, 2016
Fixes: #5124 See: #4374 PR-URL: #5130 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
rvagg pushed a commit that referenced this pull request Feb 10, 2016
Added ability to dgram.send to send multiple buffers, _writev style. The offset and length parameters in dgram.send are now optional. Refactored the dgram benchmarks, and seperated them from net. Added docs for the new signature. Reviewed-By: James M Snell <[email protected]> Reviewed-By: Saúl Ibarra Corretgé <[email protected]> Fixes: #4302 PR-URL: #4374
@AndreasMadsenAndreasMadsen mentioned this pull request Feb 14, 2016
rvagg added a commit that referenced this pull request Feb 21, 2016
* buffer: - You can now supply an encoding argument when filling a Buffer Buffer#fill(string[, start[, end]][, encoding]), supplying an existing Buffer will also work with Buffer#fill(buffer[, start[, end]]). See the API documentation for details on how this works. (Trevor Norris) #4935 - Buffer#indexOf() no longer requires a byteOffset argument if you also wish to specify an encoding: Buffer#indexOf(val[, byteOffset][, encoding]). (Trevor Norris) #4803 * child_process: spawn() and spawnSync() now support a 'shell' option to allow for optional execution of the given command inside a shell. If set to true, cmd.exe will be used on Windows and /bin/sh elsewhere. A path to a custom shell can also be passed to override these defaults. On Windows, this option allows .bat. and .cmd files to be executed with spawn() and spawnSync(). (Colin Ihrig) #4598 * http_parser: Update to http-parser 2.6.2 to fix an unintentionally strict limitation of allowable header characters. (James M Snell) #5237 * dgram: socket.send() now supports accepts an array of Buffers or Strings as the first argument. See the API docs for details on how this works. (Matteo Collina) #4374 * http: Fix a bug where handling headers will mistakenly trigger an 'upgrade' event where the server is just advertising its protocols. This bug can prevent HTTP clients from communicating with HTTP/2 enabled servers. (Fedor Indutny) #4337 * net: Added a listening Boolean property to net and http servers to indicate whether the server is listening for connections. (José Moreira) #4743 * node: The C++ node::MakeCallback() API is now reentrant and calling it from inside another MakeCallback() call no longer causes the nextTick queue or Promises microtask queue to be processed out of order. (Trevor Norris) #4507 * tls: Add a new tlsSocket.getProtocol() method to get the negotiated TLS protocol version of the current connection. (Brian White) #4995 * vm: Introduce new 'produceCachedData' and 'cachedData' options to new vm.Script() to interact with V8's code cache. When a new vm.Script object is created with the 'produceCachedData' set to true a Buffer with V8's code cache data will be produced and stored in cachedData property of the returned object. This data in turn may be supplied back to another vm.Script() object with a 'cachedData' option if the supplied source is the same. Successfully executing a script from cached data can speed up instantiation time. See the API docs for details. (Fedor Indutny) #4777 * performance: Improvements in: - process.nextTick() (Ruben Bridgewater) #5092 - path module (Brian White) #5123 - querystring module (Brian White) #5012 - streams module when processing small chunks (Matteo Collina) #4354
rvagg added a commit that referenced this pull request Feb 21, 2016
* buffer: - You can now supply an encoding argument when filling a Buffer Buffer#fill(string[, start[, end]][, encoding]), supplying an existing Buffer will also work with Buffer#fill(buffer[, start[, end]]). See the API documentation for details on how this works. (Trevor Norris) #4935 - Buffer#indexOf() no longer requires a byteOffset argument if you also wish to specify an encoding: Buffer#indexOf(val[, byteOffset][, encoding]). (Trevor Norris) #4803 * child_process: spawn() and spawnSync() now support a 'shell' option to allow for optional execution of the given command inside a shell. If set to true, cmd.exe will be used on Windows and /bin/sh elsewhere. A path to a custom shell can also be passed to override these defaults. On Windows, this option allows .bat. and .cmd files to be executed with spawn() and spawnSync(). (Colin Ihrig) #4598 * http_parser: Update to http-parser 2.6.2 to fix an unintentionally strict limitation of allowable header characters. (James M Snell) #5237 * dgram: socket.send() now supports accepts an array of Buffers or Strings as the first argument. See the API docs for details on how this works. (Matteo Collina) #4374 * http: Fix a bug where handling headers will mistakenly trigger an 'upgrade' event where the server is just advertising its protocols. This bug can prevent HTTP clients from communicating with HTTP/2 enabled servers. (Fedor Indutny) #4337 * net: Added a listening Boolean property to net and http servers to indicate whether the server is listening for connections. (José Moreira) #4743 * node: The C++ node::MakeCallback() API is now reentrant and calling it from inside another MakeCallback() call no longer causes the nextTick queue or Promises microtask queue to be processed out of order. (Trevor Norris) #4507 * tls: Add a new tlsSocket.getProtocol() method to get the negotiated TLS protocol version of the current connection. (Brian White) #4995 * vm: Introduce new 'produceCachedData' and 'cachedData' options to new vm.Script() to interact with V8's code cache. When a new vm.Script object is created with the 'produceCachedData' set to true a Buffer with V8's code cache data will be produced and stored in cachedData property of the returned object. This data in turn may be supplied back to another vm.Script() object with a 'cachedData' option if the supplied source is the same. Successfully executing a script from cached data can speed up instantiation time. See the API docs for details. (Fedor Indutny) #4777 * performance: Improvements in: - process.nextTick() (Ruben Bridgewater) #5092 - path module (Brian White) #5123 - querystring module (Brian White) #5012 - streams module when processing small chunks (Matteo Collina) #4354
rvagg added a commit that referenced this pull request Feb 23, 2016
* buffer: - You can now supply an encoding argument when filling a Buffer Buffer#fill(string[, start[, end]][, encoding]), supplying an existing Buffer will also work with Buffer#fill(buffer[, start[, end]]). See the API documentation for details on how this works. (Trevor Norris) #4935 - Buffer#indexOf() no longer requires a byteOffset argument if you also wish to specify an encoding: Buffer#indexOf(val[, byteOffset][, encoding]). (Trevor Norris) #4803 * child_process: spawn() and spawnSync() now support a 'shell' option to allow for optional execution of the given command inside a shell. If set to true, cmd.exe will be used on Windows and /bin/sh elsewhere. A path to a custom shell can also be passed to override these defaults. On Windows, this option allows .bat. and .cmd files to be executed with spawn() and spawnSync(). (Colin Ihrig) #4598 * http_parser: Update to http-parser 2.6.2 to fix an unintentionally strict limitation of allowable header characters. (James M Snell) #5237 * dgram: socket.send() now supports accepts an array of Buffers or Strings as the first argument. See the API docs for details on how this works. (Matteo Collina) #4374 * http: Fix a bug where handling headers will mistakenly trigger an 'upgrade' event where the server is just advertising its protocols. This bug can prevent HTTP clients from communicating with HTTP/2 enabled servers. (Fedor Indutny) #4337 * net: Added a listening Boolean property to net and http servers to indicate whether the server is listening for connections. (José Moreira) #4743 * node: The C++ node::MakeCallback() API is now reentrant and calling it from inside another MakeCallback() call no longer causes the nextTick queue or Promises microtask queue to be processed out of order. (Trevor Norris) #4507 * tls: Add a new tlsSocket.getProtocol() method to get the negotiated TLS protocol version of the current connection. (Brian White) #4995 * vm: Introduce new 'produceCachedData' and 'cachedData' options to new vm.Script() to interact with V8's code cache. When a new vm.Script object is created with the 'produceCachedData' set to true a Buffer with V8's code cache data will be produced and stored in cachedData property of the returned object. This data in turn may be supplied back to another vm.Script() object with a 'cachedData' option if the supplied source is the same. Successfully executing a script from cached data can speed up instantiation time. See the API docs for details. (Fedor Indutny) #4777 * performance: Improvements in: - process.nextTick() (Ruben Bridgewater) #5092 - path module (Brian White) #5123 - querystring module (Brian White) #5012 - streams module when processing small chunks (Matteo Collina) #4354 PR-URL: #5295
@mcollina
Copy link
MemberAuthor

So happy this is released!! Thx to everyone!

rvagg added a commit that referenced this pull request Feb 24, 2016
* buffer: - You can now supply an encoding argument when filling a Buffer Buffer#fill(string[, start[, end]][, encoding]), supplying an existing Buffer will also work with Buffer#fill(buffer[, start[, end]]). See the API documentation for details on how this works. (Trevor Norris) #4935 - Buffer#indexOf() no longer requires a byteOffset argument if you also wish to specify an encoding: Buffer#indexOf(val[, byteOffset][, encoding]). (Trevor Norris) #4803 * child_process: spawn() and spawnSync() now support a 'shell' option to allow for optional execution of the given command inside a shell. If set to true, cmd.exe will be used on Windows and /bin/sh elsewhere. A path to a custom shell can also be passed to override these defaults. On Windows, this option allows .bat. and .cmd files to be executed with spawn() and spawnSync(). (Colin Ihrig) #4598 * http_parser: Update to http-parser 2.6.2 to fix an unintentionally strict limitation of allowable header characters. (James M Snell) #5237 * dgram: socket.send() now supports accepts an array of Buffers or Strings as the first argument. See the API docs for details on how this works. (Matteo Collina) #4374 * http: Fix a bug where handling headers will mistakenly trigger an 'upgrade' event where the server is just advertising its protocols. This bug can prevent HTTP clients from communicating with HTTP/2 enabled servers. (Fedor Indutny) #4337 * net: Added a listening Boolean property to net and http servers to indicate whether the server is listening for connections. (José Moreira) #4743 * node: The C++ node::MakeCallback() API is now reentrant and calling it from inside another MakeCallback() call no longer causes the nextTick queue or Promises microtask queue to be processed out of order. (Trevor Norris) #4507 * tls: Add a new tlsSocket.getProtocol() method to get the negotiated TLS protocol version of the current connection. (Brian White) #4995 * vm: Introduce new 'produceCachedData' and 'cachedData' options to new vm.Script() to interact with V8's code cache. When a new vm.Script object is created with the 'produceCachedData' set to true a Buffer with V8's code cache data will be produced and stored in cachedData property of the returned object. This data in turn may be supplied back to another vm.Script() object with a 'cachedData' option if the supplied source is the same. Successfully executing a script from cached data can speed up instantiation time. See the API docs for details. (Fedor Indutny) #4777 * performance: Improvements in: - process.nextTick() (Ruben Bridgewater) #5092 - path module (Brian White) #5123 - querystring module (Brian White) #5012 - streams module when processing small chunks (Matteo Collina) #4354 PR-URL: #5295
mcollina added a commit to mcollina/node that referenced this pull request Feb 27, 2016
Fixes a regression introduced by: nodejs#4374. Adds a new test to avoid similar issue in the future. Fixes: nodejs#5398
mcollina added a commit to mcollina/node that referenced this pull request Feb 28, 2016
Fixes a regression introduced by: nodejs#4374. Adds a new test to avoid similar issue in the future. The test is disabled on windows, because this feature never worked there. Fixes: nodejs#5398 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
Fishrock123 pushed a commit that referenced this pull request Mar 2, 2016
Fixes a regression introduced by: #4374. Adds a new test to avoid similar issue in the future. The test is disabled on windows, because this feature never worked there. Fixes: #5398 Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Rod Vagg <[email protected]> Reviewed-By: Evan Lucas <[email protected]>
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
Added ability to dgram.send to send multiple buffers, _writev style. The offset and length parameters in dgram.send are now optional. Refactored the dgram benchmarks, and seperated them from net. Added docs for the new signature. Reviewed-By: James M Snell <[email protected]> Reviewed-By: Saúl Ibarra Corretgé <[email protected]> Fixes: nodejs#4302 PR-URL: nodejs#4374
scovetta pushed a commit to scovetta/node that referenced this pull request Apr 2, 2016
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dgramIssues and PRs related to the dgram subsystem / UDP.semver-minorPRs that contain new features and should be released in the next minor version.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants

@mcollina@ronkorving@thefourtheye@trevnorris@saghul@indutny@jasnell@cjihrig@mafintosh@reqshark