• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common.js');
3const http = require('http');
4
5const bench = common.createBenchmark(main, {
6  connections: [50], // Concurrent connections
7  headers: [20], // Number of header lines to append after the common headers
8  w: [0, 6], // Amount of trailing whitespace
9  duration: 5
10});
11
12function main({ connections, headers, w, duration }) {
13  const server = http.createServer((req, res) => {
14    res.end();
15  });
16
17  server.listen(common.PORT, () => {
18    const headers = {
19      'Content-Type': 'text/plain',
20      'Accept': 'text/plain',
21      'User-Agent': 'nodejs-benchmark',
22      'Date': new Date().toString(),
23      'Cache-Control': 'no-cache'
24    };
25    for (let i = 0; i < headers; i++) {
26      // Note:
27      // - autocannon does not send header values with OWS
28      // - wrk can only send trailing OWS. This is a side-effect of wrk
29      // processing requests with http-parser before sending them, causing
30      // leading OWS to be stripped.
31      headers[`foo${i}`] = `some header value ${i}${' \t'.repeat(w / 2)}`;
32    }
33    bench.http({
34      path: '/',
35      connections,
36      headers,
37      duration
38    }, () => {
39      server.close();
40    });
41  });
42}
43