Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-08-10 01:52:35 +0300
committerAnna Henningsen <anna@addaleax.net>2017-08-14 14:20:41 +0300
commit92c37fe5fde36581532312fd44abea919c645e41 (patch)
tree47f3536c3a67917a8e03ddd35951c8e76cb89055 /benchmark
parent66788fc4d003ac9752084b719aeeec54f1703592 (diff)
http2: improve perf of passing headers to C++
By passing a single string rather than many small ones and a single block allocation for passing headers, save expensive interactions with JS values and memory allocations. PR-URL: https://github.com/nodejs/node/pull/14723 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r--benchmark/http2/headers.js47
1 files changed, 47 insertions, 0 deletions
diff --git a/benchmark/http2/headers.js b/benchmark/http2/headers.js
new file mode 100644
index 00000000000..09449d1e92f
--- /dev/null
+++ b/benchmark/http2/headers.js
@@ -0,0 +1,47 @@
+'use strict';
+
+const common = require('../common.js');
+const PORT = common.PORT;
+
+var bench = common.createBenchmark(main, {
+ n: [1e3],
+ nheaders: [100, 1000],
+}, { flags: ['--expose-http2', '--no-warnings'] });
+
+function main(conf) {
+ const n = +conf.n;
+ const nheaders = +conf.nheaders;
+ const http2 = require('http2');
+ const server = http2.createServer();
+
+ const headersObject = { ':path': '/' };
+ for (var i = 0; i < nheaders; i++) {
+ headersObject[`foo${i}`] = `some header value ${i}`;
+ }
+
+ server.on('stream', (stream) => {
+ stream.respond();
+ stream.end('Hi!');
+ });
+ server.listen(PORT, () => {
+ const client = http2.connect(`http://localhost:${PORT}/`);
+
+ function doRequest(remaining) {
+ const req = client.request(headersObject);
+ req.end();
+ req.on('data', () => {});
+ req.on('end', () => {
+ if (remaining > 0) {
+ doRequest(remaining - 1);
+ } else {
+ bench.end(n);
+ server.close();
+ client.destroy();
+ }
+ });
+ }
+
+ bench.start();
+ doRequest(n);
+ });
+}