summaryrefslogtreecommitdiff
path: root/benchmark
diff options
context:
space:
mode:
authorCalvin Metcalf <cmetcalf@appgeo.com>2017-05-16 11:08:49 -0400
committerMatteo Collina <hello@matteocollina.com>2017-12-15 23:05:45 +0100
commite20af3371bb1f0ee16795528cbcbc674408842cb (patch)
tree0a0426a7c304adcf9b0bfc9c0e3e7c1a762a8fd3 /benchmark
parent31addac8bbcd3e0a8cefba8327cfcc7fd9bdeb68 (diff)
downloadandroid-node-v8-e20af3371bb1f0ee16795528cbcbc674408842cb.tar.gz
android-node-v8-e20af3371bb1f0ee16795528cbcbc674408842cb.tar.bz2
android-node-v8-e20af3371bb1f0ee16795528cbcbc674408842cb.zip
stream: add flow and buffer properties to streams
This adds computed properties to readable and writable streams to allow access to the readable buffer, the writable buffer, and flow state without accessing the readable or writable state. These are the only uses of readable and writable state in the docs so adding these work arounds allows them to be removed from the docs. This also updates net, http_client and http_server to use the new methods instead of manipulating readable and writable state directly. See: https://github.com/nodejs/node/issues/445 PR-URL: https://github.com/nodejs/node/pull/12855 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/http/upgrade.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/benchmark/http/upgrade.js b/benchmark/http/upgrade.js
new file mode 100644
index 0000000000..0feaecc8ff
--- /dev/null
+++ b/benchmark/http/upgrade.js
@@ -0,0 +1,53 @@
+'use strict';
+
+const common = require('../common.js');
+const PORT = common.PORT;
+const net = require('net');
+
+const bench = common.createBenchmark(main, {
+ n: [5, 1000]
+});
+
+const reqData = 'GET / HTTP/1.1\r\n' +
+ 'Upgrade: WebSocket\r\n' +
+ 'Connection: Upgrade\r\n' +
+ '\r\n' +
+ 'WjN}|M(6';
+
+const resData = 'HTTP/1.1 101 Web Socket Protocol Handshake\r\n' +
+ 'Upgrade: WebSocket\r\n' +
+ 'Connection: Upgrade\r\n' +
+ '\r\n\r\n';
+
+function main({ n }) {
+ process.env.PORT = PORT;
+ var server = require('../fixtures/simple-http-server.js')
+ .listen(common.PORT)
+ .on('listening', function() {
+ bench.start();
+ doBench(server.address(), n, function() {
+ bench.end(n);
+ server.close();
+ });
+ })
+ .on('upgrade', function(req, socket, upgradeHead) {
+ socket.resume();
+ socket.write(resData);
+ socket.end();
+ });
+}
+
+function doBench(address, count, done) {
+ if (count === 0) {
+ done();
+ return;
+ }
+
+ const conn = net.createConnection(address.port);
+ conn.write(reqData);
+ conn.resume();
+
+ conn.on('end', function() {
+ doBench(address, count - 1, done);
+ });
+}