Skip to content

Commit 0a40686

Browse files
committed
bench: Replace tls-fragmentation with tls/throughput
1 parent bafc51c commit 0a40686

File tree

2 files changed

+74
-63
lines changed

2 files changed

+74
-63
lines changed

benchmark/tls-fragmentation.js

Lines changed: 0 additions & 63 deletions
This file was deleted.

benchmark/tls/throughput.js

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
var common = require('../common.js');
2+
var bench = common.createBenchmark(main, {
3+
dur: [1, 3],
4+
type: ['buf', 'asc', 'utf'],
5+
size: [2, 1024, 1024 * 1024]
6+
});
7+
8+
var dur, type, encoding, size;
9+
var server;
10+
11+
var path = require('path');
12+
var fs = require('fs');
13+
var cert_dir = path.resolve(__dirname, '../../test/fixtures');
14+
var options;
15+
var tls = require('tls');
16+
17+
function main(conf) {
18+
dur = +conf.dur;
19+
type = conf.type;
20+
size = +conf.size;
21+
22+
var chunk;
23+
switch (type) {
24+
case 'buf':
25+
chunk = new Buffer(size);
26+
chunk.fill('b');
27+
break;
28+
case 'asc':
29+
chunk = new Array(size + 1).join('a');
30+
encoding = 'ascii';
31+
break;
32+
case 'utf':
33+
chunk = new Array(size/2 + 1).join('ü');
34+
encoding = 'utf8';
35+
break;
36+
default:
37+
throw new Error('invalid type');
38+
}
39+
40+
options = { key: fs.readFileSync(cert_dir + '/test_key.pem'),
41+
cert: fs.readFileSync(cert_dir + '/test_cert.pem'),
42+
ca: [ fs.readFileSync(cert_dir + '/test_ca.pem') ] };
43+
44+
server = tls.createServer(options, onConnection);
45+
setTimeout(done, dur * 1000);
46+
server.listen(common.PORT, function() {
47+
var opt = { port: common.PORT, rejectUnauthorized: false };
48+
var conn = tls.connect(opt, function() {
49+
bench.start();
50+
conn.on('drain', write);
51+
write();
52+
});
53+
54+
function write() {
55+
var i = 0;
56+
while (false !== conn.write(chunk, encoding));
57+
}
58+
});
59+
60+
var received = 0;
61+
function onConnection(conn) {
62+
conn.on('data', function(chunk) {
63+
received += chunk.length;
64+
});
65+
}
66+
67+
function done() {
68+
var mbits = (received * 8) / (1024 * 1024);
69+
bench.end(mbits);
70+
conn.destroy();
71+
server.close();
72+
}
73+
}
74+

0 commit comments

Comments
 (0)