From 884b23daf723db60ebe939e6dde492fa5f9230eb Mon Sep 17 00:00:00 2001 From: James M Snell Date: Wed, 15 Aug 2018 17:14:22 -0700 Subject: stream: move process.binding('stream_wrap') to internalBinding PR-URL: https://github.com/nodejs/node/pull/22345 Refs: https://github.com/nodejs/node/issues/22160 Reviewed-By: Matteo Collina Reviewed-By: Jon Moss Reviewed-By: Joyee Cheung Reviewed-By: Ruben Bridgewater --- benchmark/net/tcp-raw-c2s.js | 114 +++++++++++++++++++++--------------------- benchmark/net/tcp-raw-pipe.js | 21 ++++---- benchmark/net/tcp-raw-s2c.js | 81 +++++++++++++++--------------- 3 files changed, 111 insertions(+), 105 deletions(-) (limited to 'benchmark') diff --git a/benchmark/net/tcp-raw-c2s.js b/benchmark/net/tcp-raw-c2s.js index 4b6dd9c3f2..d6666011d5 100644 --- a/benchmark/net/tcp-raw-c2s.js +++ b/benchmark/net/tcp-raw-c2s.js @@ -12,14 +12,15 @@ const bench = common.createBenchmark(main, { len: [102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5] -}); - -const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); -const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; -const WriteWrap = process.binding('stream_wrap').WriteWrap; -const PORT = common.PORT; +}, { flags: [ '--expose-internals', '--no-warnings' ] }); function main({ dur, len, type }) { + const { internalBinding } = require('internal/test/binding'); + const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); + const { TCPConnectWrap } = process.binding('tcp_wrap'); + const { WriteWrap } = internalBinding('stream_wrap'); + const PORT = common.PORT; + const serverHandle = new TCP(TCPConstants.SERVER); var err = serverHandle.bind('127.0.0.1', PORT); if (err) @@ -58,71 +59,70 @@ function main({ dur, len, type }) { }; client(type, len); -} - -function fail(err, syscall) { - throw util._errnoException(err, syscall); -} - -function client(type, len) { - var chunk; - switch (type) { - case 'buf': - chunk = Buffer.alloc(len, 'x'); - break; - case 'utf': - chunk = 'ü'.repeat(len / 2); - break; - case 'asc': - chunk = 'x'.repeat(len); - break; - default: - throw new Error(`invalid type: ${type}`); + function fail(err, syscall) { + throw util._errnoException(err, syscall); } - const clientHandle = new TCP(TCPConstants.SOCKET); - const connectReq = new TCPConnectWrap(); - const err = clientHandle.connect(connectReq, '127.0.0.1', PORT); - - if (err) - fail(err, 'connect'); - - clientHandle.readStart(); - - connectReq.oncomplete = function(err) { - if (err) - fail(err, 'connect'); - - while (clientHandle.writeQueueSize === 0) - write(); - }; - - function write() { - const writeReq = new WriteWrap(); - writeReq.oncomplete = afterWrite; - var err; + function client(type, len) { + var chunk; switch (type) { case 'buf': - err = clientHandle.writeBuffer(writeReq, chunk); + chunk = Buffer.alloc(len, 'x'); break; case 'utf': - err = clientHandle.writeUtf8String(writeReq, chunk); + chunk = 'ü'.repeat(len / 2); break; case 'asc': - err = clientHandle.writeAsciiString(writeReq, chunk); + chunk = 'x'.repeat(len); break; + default: + throw new Error(`invalid type: ${type}`); } - if (err) - fail(err, 'write'); - } + const clientHandle = new TCP(TCPConstants.SOCKET); + const connectReq = new TCPConnectWrap(); + const err = clientHandle.connect(connectReq, '127.0.0.1', PORT); - function afterWrite(err, handle) { if (err) - fail(err, 'write'); + fail(err, 'connect'); + + clientHandle.readStart(); + + connectReq.oncomplete = function(err) { + if (err) + fail(err, 'connect'); - while (clientHandle.writeQueueSize === 0) - write(); + while (clientHandle.writeQueueSize === 0) + write(); + }; + + function write() { + const writeReq = new WriteWrap(); + writeReq.oncomplete = afterWrite; + var err; + switch (type) { + case 'buf': + err = clientHandle.writeBuffer(writeReq, chunk); + break; + case 'utf': + err = clientHandle.writeUtf8String(writeReq, chunk); + break; + case 'asc': + err = clientHandle.writeAsciiString(writeReq, chunk); + break; + } + + if (err) + fail(err, 'write'); + } + + function afterWrite(err, handle) { + if (err) + fail(err, 'write'); + + while (clientHandle.writeQueueSize === 0) + write(); + } } } diff --git a/benchmark/net/tcp-raw-pipe.js b/benchmark/net/tcp-raw-pipe.js index dfde3d40b5..8203abca6e 100644 --- a/benchmark/net/tcp-raw-pipe.js +++ b/benchmark/net/tcp-raw-pipe.js @@ -12,18 +12,21 @@ const bench = common.createBenchmark(main, { len: [102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5] +}, { + flags: [ '--expose-internals', '--no-warnings' ] }); -function fail(err, syscall) { - throw util._errnoException(err, syscall); -} - -const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); -const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; -const WriteWrap = process.binding('stream_wrap').WriteWrap; -const PORT = common.PORT; - function main({ dur, len, type }) { + const { internalBinding } = require('internal/test/binding'); + const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); + const { TCPConnectWrap } = process.binding('tcp_wrap'); + const { WriteWrap } = internalBinding('stream_wrap'); + const PORT = common.PORT; + + function fail(err, syscall) { + throw util._errnoException(err, syscall); + } + // Server const serverHandle = new TCP(TCPConstants.SERVER); var err = serverHandle.bind('127.0.0.1', PORT); diff --git a/benchmark/net/tcp-raw-s2c.js b/benchmark/net/tcp-raw-s2c.js index fe0bffd812..1e42b311ad 100644 --- a/benchmark/net/tcp-raw-s2c.js +++ b/benchmark/net/tcp-raw-s2c.js @@ -12,14 +12,17 @@ const bench = common.createBenchmark(main, { len: [102400, 1024 * 1024 * 16], type: ['utf', 'asc', 'buf'], dur: [5] +}, { + flags: [ '--expose-internals', '--no-warnings' ] }); -const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); -const TCPConnectWrap = process.binding('tcp_wrap').TCPConnectWrap; -const WriteWrap = process.binding('stream_wrap').WriteWrap; -const PORT = common.PORT; - function main({ dur, len, type }) { + const { internalBinding } = require('internal/test/binding'); + const { TCP, constants: TCPConstants } = process.binding('tcp_wrap'); + const { TCPConnectWrap } = process.binding('tcp_wrap'); + const { WriteWrap } = internalBinding('stream_wrap'); + const PORT = common.PORT; + const serverHandle = new TCP(TCPConstants.SERVER); var err = serverHandle.bind('127.0.0.1', PORT); if (err) @@ -89,42 +92,42 @@ function main({ dur, len, type }) { }; client(dur); -} -function fail(err, syscall) { - throw util._errnoException(err, syscall); -} + function fail(err, syscall) { + throw util._errnoException(err, syscall); + } -function client(dur) { - const clientHandle = new TCP(TCPConstants.SOCKET); - const connectReq = new TCPConnectWrap(); - const err = clientHandle.connect(connectReq, '127.0.0.1', PORT); - - if (err) - fail(err, 'connect'); - - connectReq.oncomplete = function() { - var bytes = 0; - clientHandle.onread = function(nread, buffer) { - // we're not expecting to ever get an EOF from the client. - // just lots of data forever. - if (nread < 0) - fail(nread, 'read'); - - // don't slice the buffer. the point of this is to isolate, not - // simulate real traffic. - bytes += buffer.length; - }; + function client(dur) { + const clientHandle = new TCP(TCPConstants.SOCKET); + const connectReq = new TCPConnectWrap(); + const err = clientHandle.connect(connectReq, '127.0.0.1', PORT); - clientHandle.readStart(); - - // the meat of the benchmark is right here: - bench.start(); + if (err) + fail(err, 'connect'); - setTimeout(function() { - // report in Gb/sec - bench.end((bytes * 8) / (1024 * 1024 * 1024)); - process.exit(0); - }, dur * 1000); - }; + connectReq.oncomplete = function() { + var bytes = 0; + clientHandle.onread = function(nread, buffer) { + // we're not expecting to ever get an EOF from the client. + // just lots of data forever. + if (nread < 0) + fail(nread, 'read'); + + // don't slice the buffer. the point of this is to isolate, not + // simulate real traffic. + bytes += buffer.length; + }; + + clientHandle.readStart(); + + // the meat of the benchmark is right here: + bench.start(); + + setTimeout(function() { + // report in Gb/sec + bench.end((bytes * 8) / (1024 * 1024 * 1024)); + process.exit(0); + }, dur * 1000); + }; + } } -- cgit v1.2.1