11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common.js'); 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_ciconst bench = common.createBenchmark(main, { 61cb0ef41Sopenharmony_ci streams: [100, 200, 1000], 71cb0ef41Sopenharmony_ci length: [64 * 1024, 128 * 1024, 256 * 1024, 1024 * 1024], 81cb0ef41Sopenharmony_ci size: [100000], 91cb0ef41Sopenharmony_ci benchmarker: ['test-double-http2'], 101cb0ef41Sopenharmony_ci duration: 5, 111cb0ef41Sopenharmony_ci}, { flags: ['--no-warnings'] }); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_cifunction main({ streams, length, size, duration }) { 141cb0ef41Sopenharmony_ci const http2 = require('http2'); 151cb0ef41Sopenharmony_ci const server = http2.createServer(); 161cb0ef41Sopenharmony_ci server.on('stream', (stream) => { 171cb0ef41Sopenharmony_ci stream.respond(); 181cb0ef41Sopenharmony_ci let written = 0; 191cb0ef41Sopenharmony_ci function write() { 201cb0ef41Sopenharmony_ci stream.write('ü'.repeat(size)); 211cb0ef41Sopenharmony_ci written += size; 221cb0ef41Sopenharmony_ci if (written < length) 231cb0ef41Sopenharmony_ci setImmediate(write); 241cb0ef41Sopenharmony_ci else 251cb0ef41Sopenharmony_ci stream.end(); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci write(); 281cb0ef41Sopenharmony_ci }); 291cb0ef41Sopenharmony_ci server.listen(0, () => { 301cb0ef41Sopenharmony_ci bench.http({ 311cb0ef41Sopenharmony_ci path: '/', 321cb0ef41Sopenharmony_ci port: server.address().port, 331cb0ef41Sopenharmony_ci requests: 10000, 341cb0ef41Sopenharmony_ci duration, 351cb0ef41Sopenharmony_ci maxConcurrentStreams: streams, 361cb0ef41Sopenharmony_ci }, () => { server.close(); }); 371cb0ef41Sopenharmony_ci }); 381cb0ef41Sopenharmony_ci} 39