• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common.js');
4
5const bench = common.createBenchmark(main, {
6  streams: [100, 200, 1000],
7  length: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024],
8  size: [100000],
9  benchmarker: ['test-double-http2'],
10  duration: 5,
11}, { flags: ['--no-warnings'] });
12
13function main({ streams, length, size, duration }) {
14  const http2 = require('http2');
15  const server = http2.createServer();
16  server.on('stream', (stream) => {
17    stream.respond();
18    let written = 0;
19    function write() {
20      stream.write('ü'.repeat(size));
21      written += size;
22      if (written < length)
23        setImmediate(write);
24      else
25        stream.end();
26    }
27    write();
28  });
29  server.listen(0, () => {
30    bench.http({
31      path: '/',
32      port: server.address().port,
33      requests: 10000,
34      duration,
35      maxConcurrentStreams: streams,
36    }, () => { server.close(); });
37  });
38}
39