diff options
author | Weijia Wang <381152119@qq.com> | 2019-02-11 13:30:15 +0800 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-02-13 21:57:54 +0100 |
commit | 51982978ebbf79a74a213b6b274947e9eac363fd (patch) | |
tree | 6e76a9d0f5b7f64e33e7260fae28704231b19ec9 /benchmark | |
parent | 9c9aefe2a09d601a36366062c856f852f3778b00 (diff) | |
download | node-new-51982978ebbf79a74a213b6b274947e9eac363fd.tar.gz |
http: improve performance for incoming headers
PR-URL: https://github.com/nodejs/node/pull/26041
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Diffstat (limited to 'benchmark')
-rw-r--r-- | benchmark/_http-benchmarkers.js | 5 | ||||
-rw-r--r-- | benchmark/http/incoming_headers.js | 35 |
2 files changed, 39 insertions, 1 deletions
diff --git a/benchmark/_http-benchmarkers.js b/benchmark/_http-benchmarkers.js index f456628454..a4d6230039 100644 --- a/benchmark/_http-benchmarkers.js +++ b/benchmark/_http-benchmarkers.js @@ -25,8 +25,11 @@ class AutocannonBenchmarker { '-c', options.connections, '-j', '-n', - `http://127.0.0.1:${options.port}${options.path}`, ]; + for (const field in options.headers) { + args.push('-H', `${field}=${options.headers[field]}`); + } + args.push(`http://127.0.0.1:${options.port}${options.path}`); const child = child_process.spawn(this.executable, args); return child; } diff --git a/benchmark/http/incoming_headers.js b/benchmark/http/incoming_headers.js new file mode 100644 index 0000000000..a1ab57e238 --- /dev/null +++ b/benchmark/http/incoming_headers.js @@ -0,0 +1,35 @@ +'use strict'; +const common = require('../common.js'); +const http = require('http'); + +const bench = common.createBenchmark(main, { + // unicode confuses ab on os x. + c: [50, 500], + headerDuplicates: [0, 5, 20] +}); + +function main({ c, headerDuplicates }) { + const server = http.createServer((req, res) => { + res.end(); + }); + + server.listen(common.PORT, () => { + const headers = { + 'Content-Type': 'text/plain', + 'Accept': 'text/plain', + 'User-Agent': 'nodejs-benchmark', + 'Date': new Date().toString(), + 'Cache-Control': 'no-cache' + }; + for (let i = 0; i < headerDuplicates; i++) { + headers[`foo${i}`] = `some header value ${i}`; + } + bench.http({ + path: '/', + connections: c, + headers + }, () => { + server.close(); + }); + }); +} |