summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2019-10-02 23:26:51 +0200
committerRich Trott <rtrott@gmail.com>2019-10-05 17:48:10 -0700
commitafdc3d0d187e4e3a336937df17a4c90092405e2a (patch)
treef16e7b4920a24d3ed7e711380450bd8b302ee40b /benchmark
parent28c3a9dd723e124a0e38588826c737eee7bfded5 (diff)
downloadandroid-node-v8-afdc3d0d187e4e3a336937df17a4c90092405e2a.tar.gz
android-node-v8-afdc3d0d187e4e3a336937df17a4c90092405e2a.tar.bz2
android-node-v8-afdc3d0d187e4e3a336937df17a4c90092405e2a.zip
dgram: use `uv_udp_try_send()`
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: https://github.com/nodejs/node/pull/29832 Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/dgram/array-vs-concat.js20
-rw-r--r--benchmark/dgram/multi-buffer.js10
-rw-r--r--benchmark/dgram/offset-length.js10
-rw-r--r--benchmark/dgram/single-buffer.js10
4 files changed, 35 insertions, 15 deletions
diff --git a/benchmark/dgram/array-vs-concat.js b/benchmark/dgram/array-vs-concat.js
index 669cf47df4..d260a48063 100644
--- a/benchmark/dgram/array-vs-concat.js
+++ b/benchmark/dgram/array-vs-concat.js
@@ -29,17 +29,25 @@ function main({ dur, len, num, type, chunks }) {
function onsendConcat() {
if (sent++ % num === 0) {
- for (var i = 0; i < num; i++) {
- socket.send(Buffer.concat(chunk), PORT, '127.0.0.1', onsend);
- }
+ // The setImmediate() is necessary to have event loop progress on OSes
+ // that only perform synchronous I/O on nonblocking UDP sockets.
+ setImmediate(() => {
+ for (var i = 0; i < num; i++) {
+ socket.send(Buffer.concat(chunk), PORT, '127.0.0.1', onsend);
+ }
+ });
}
}
function onsendMulti() {
if (sent++ % num === 0) {
- for (var i = 0; i < num; i++) {
- socket.send(chunk, PORT, '127.0.0.1', onsend);
- }
+ // The setImmediate() is necessary to have event loop progress on OSes
+ // that only perform synchronous I/O on nonblocking UDP sockets.
+ setImmediate(() => {
+ for (var i = 0; i < num; i++) {
+ socket.send(chunk, PORT, '127.0.0.1', onsend);
+ }
+ });
}
}
diff --git a/benchmark/dgram/multi-buffer.js b/benchmark/dgram/multi-buffer.js
index a1c50551b8..7b69a82255 100644
--- a/benchmark/dgram/multi-buffer.js
+++ b/benchmark/dgram/multi-buffer.js
@@ -27,9 +27,13 @@ function main({ dur, len, num, type, chunks }) {
function onsend() {
if (sent++ % num === 0) {
- for (var i = 0; i < num; i++) {
- socket.send(chunk, PORT, '127.0.0.1', onsend);
- }
+ // The setImmediate() is necessary to have event loop progress on OSes
+ // that only perform synchronous I/O on nonblocking UDP sockets.
+ setImmediate(() => {
+ for (var i = 0; i < num; i++) {
+ socket.send(chunk, PORT, '127.0.0.1', onsend);
+ }
+ });
}
}
diff --git a/benchmark/dgram/offset-length.js b/benchmark/dgram/offset-length.js
index 7c672acae2..696fa6a7a0 100644
--- a/benchmark/dgram/offset-length.js
+++ b/benchmark/dgram/offset-length.js
@@ -23,9 +23,13 @@ function main({ dur, len, num, type }) {
function onsend() {
if (sent++ % num === 0) {
- for (var i = 0; i < num; i++) {
- socket.send(chunk, 0, chunk.length, PORT, '127.0.0.1', onsend);
- }
+ // The setImmediate() is necessary to have event loop progress on OSes
+ // that only perform synchronous I/O on nonblocking UDP sockets.
+ setImmediate(() => {
+ for (var i = 0; i < num; i++) {
+ socket.send(chunk, 0, chunk.length, PORT, '127.0.0.1', onsend);
+ }
+ });
}
}
diff --git a/benchmark/dgram/single-buffer.js b/benchmark/dgram/single-buffer.js
index d183b9cd1d..5c95b17887 100644
--- a/benchmark/dgram/single-buffer.js
+++ b/benchmark/dgram/single-buffer.js
@@ -23,9 +23,13 @@ function main({ dur, len, num, type }) {
function onsend() {
if (sent++ % num === 0) {
- for (var i = 0; i < num; i++) {
- socket.send(chunk, PORT, '127.0.0.1', onsend);
- }
+ // The setImmediate() is necessary to have event loop progress on OSes
+ // that only perform synchronous I/O on nonblocking UDP sockets.
+ setImmediate(() => {
+ for (var i = 0; i < num; i++) {
+ socket.send(chunk, PORT, '127.0.0.1', onsend);
+ }
+ });
}
}