11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ciconst path = require('path'); 51cb0ef41Sopenharmony_ciconst fs = require('fs'); 61cb0ef41Sopenharmony_ciconst file = path.join(path.resolve(__dirname, '../fixtures'), 'alice.html'); 71cb0ef41Sopenharmony_ci 81cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 91cb0ef41Sopenharmony_ci requests: [100, 1000, 5000], 101cb0ef41Sopenharmony_ci streams: [1, 10, 20, 40, 100, 200], 111cb0ef41Sopenharmony_ci clients: [2], 121cb0ef41Sopenharmony_ci benchmarker: ['test-double-http2'], 131cb0ef41Sopenharmony_ci duration: 5, 141cb0ef41Sopenharmony_ci}, { flags: ['--no-warnings'] }); 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_cifunction main({ requests, streams, clients, duration }) { 171cb0ef41Sopenharmony_ci const http2 = require('http2'); 181cb0ef41Sopenharmony_ci const server = http2.createServer(); 191cb0ef41Sopenharmony_ci server.on('request', (req, res) => { 201cb0ef41Sopenharmony_ci const out = fs.createReadStream(file); 211cb0ef41Sopenharmony_ci res.setHeader('content-type', 'text/html'); 221cb0ef41Sopenharmony_ci out.pipe(res); 231cb0ef41Sopenharmony_ci out.on('error', (err) => { 241cb0ef41Sopenharmony_ci res.destroy(); 251cb0ef41Sopenharmony_ci }); 261cb0ef41Sopenharmony_ci }); 271cb0ef41Sopenharmony_ci server.listen(0, () => { 281cb0ef41Sopenharmony_ci bench.http({ 291cb0ef41Sopenharmony_ci path: '/', 301cb0ef41Sopenharmony_ci port: server.address().port, 311cb0ef41Sopenharmony_ci requests, 321cb0ef41Sopenharmony_ci maxConcurrentStreams: streams, 331cb0ef41Sopenharmony_ci clients, 341cb0ef41Sopenharmony_ci threads: clients, 351cb0ef41Sopenharmony_ci duration, 361cb0ef41Sopenharmony_ci }, () => { server.close(); }); 371cb0ef41Sopenharmony_ci }); 381cb0ef41Sopenharmony_ci} 39