aboutsummaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorAndrey Pechkurov <apechkurov@gmail.com>2020-10-22 12:04:35 +0300
committerAndrey Pechkurov <apechkurov@gmail.com>2020-10-28 16:07:29 +0300
commit761c1b0797a73f5442b2a28de5a1d508efbc70ad (patch)
treeb61ceb5dff38aee978f4941d8fc2c68bf5fd5a48 /benchmark
parentab660a541605a0a823f0c9471ff667a6620be2a5 (diff)
downloadios-node-v8-761c1b0797a73f5442b2a28de5a1d508efbc70ad.tar.gz
ios-node-v8-761c1b0797a73f5442b2a28de5a1d508efbc70ad.tar.bz2
ios-node-v8-761c1b0797a73f5442b2a28de5a1d508efbc70ad.zip
tls: allow reading data into a static buffer
Refs: #25436 PR-URL: https://github.com/nodejs/node/pull/35753 Refs: https://github.com/nodejs/node/pull/25436 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/tls/throughput-c2s.js (renamed from benchmark/tls/throughput.js)0
-rw-r--r--benchmark/tls/throughput-s2c.js104
2 files changed, 104 insertions, 0 deletions
diff --git a/benchmark/tls/throughput.js b/benchmark/tls/throughput-c2s.js
index f3a96abcbc..f3a96abcbc 100644
--- a/benchmark/tls/throughput.js
+++ b/benchmark/tls/throughput-c2s.js
diff --git a/benchmark/tls/throughput-s2c.js b/benchmark/tls/throughput-s2c.js
new file mode 100644
index 0000000000..a505a719d3
--- /dev/null
+++ b/benchmark/tls/throughput-s2c.js
@@ -0,0 +1,104 @@
+'use strict';
+const common = require('../common.js');
+const bench = common.createBenchmark(main, {
+ dur: [5],
+ type: ['buf', 'asc', 'utf'],
+ sendchunklen: [256, 32 * 1024, 128 * 1024, 16 * 1024 * 1024],
+ recvbuflen: [0, 64 * 1024, 1024 * 1024],
+ recvbufgenfn: ['true', 'false']
+});
+
+const fixtures = require('../../test/common/fixtures');
+let options;
+let recvbuf;
+let received = 0;
+const tls = require('tls');
+
+function main({ dur, type, sendchunklen, recvbuflen, recvbufgenfn }) {
+ if (isFinite(recvbuflen) && recvbuflen > 0)
+ recvbuf = Buffer.alloc(recvbuflen);
+
+ let encoding;
+ let chunk;
+ switch (type) {
+ case 'buf':
+ chunk = Buffer.alloc(sendchunklen, 'b');
+ break;
+ case 'asc':
+ chunk = 'a'.repeat(sendchunklen);
+ encoding = 'ascii';
+ break;
+ case 'utf':
+ chunk = 'ΓΌ'.repeat(sendchunklen / 2);
+ encoding = 'utf8';
+ break;
+ default:
+ throw new Error('invalid type');
+ }
+
+ options = {
+ key: fixtures.readKey('rsa_private.pem'),
+ cert: fixtures.readKey('rsa_cert.crt'),
+ ca: fixtures.readKey('rsa_ca.crt'),
+ ciphers: 'AES256-GCM-SHA384'
+ };
+
+ let socketOpts;
+ if (recvbuf === undefined) {
+ socketOpts = { port: common.PORT, rejectUnauthorized: false };
+ } else {
+ let buffer = recvbuf;
+ if (recvbufgenfn === 'true') {
+ let bufidx = -1;
+ const bufpool = [
+ recvbuf,
+ Buffer.from(recvbuf),
+ Buffer.from(recvbuf),
+ ];
+ buffer = () => {
+ bufidx = (bufidx + 1) % bufpool.length;
+ return bufpool[bufidx];
+ };
+ }
+ socketOpts = {
+ port: common.PORT,
+ rejectUnauthorized: false,
+ onread: {
+ buffer,
+ callback: function(nread, buf) {
+ received += nread;
+ }
+ }
+ };
+ }
+
+ const server = tls.createServer(options, (socket) => {
+ socket.on('data', (buf) => {
+ socket.on('drain', write);
+ write();
+ });
+
+ function write() {
+ while (false !== socket.write(chunk, encoding));
+ }
+ });
+
+ let conn;
+ server.listen(common.PORT, () => {
+ conn = tls.connect(socketOpts, () => {
+ setTimeout(done, dur * 1000);
+ bench.start();
+ conn.write('hello');
+ });
+
+ conn.on('data', (chunk) => {
+ received += chunk.length;
+ });
+ });
+
+ function done() {
+ const mbits = (received * 8) / (1024 * 1024);
+ bench.end(mbits);
+ process.exit(0);
+ }
+}