2017-07-18 01:29:42 +08:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common.js');
|
|
|
|
const path = require('path');
|
|
|
|
const fs = require('fs');
|
|
|
|
const file = path.join(path.resolve(__dirname, '../fixtures'), 'alice.html');
|
|
|
|
|
2017-09-14 09:48:53 +08:00
|
|
|
const bench = common.createBenchmark(main, {
|
2017-07-18 01:29:42 +08:00
|
|
|
requests: [100, 1000, 10000, 100000],
|
|
|
|
streams: [100, 200, 1000],
|
2017-10-17 01:43:40 +08:00
|
|
|
clients: [1, 2],
|
|
|
|
benchmarker: ['h2load']
|
|
|
|
}, { flags: ['--no-warnings', '--expose-http2'] });
|
2017-07-18 01:29:42 +08:00
|
|
|
|
2017-12-30 10:57:31 +08:00
|
|
|
function main({ requests, streams, clients }) {
|
2017-07-18 01:29:42 +08:00
|
|
|
const http2 = require('http2');
|
|
|
|
const server = http2.createServer();
|
|
|
|
server.on('stream', (stream) => {
|
|
|
|
const out = fs.createReadStream(file);
|
|
|
|
stream.respond();
|
|
|
|
out.pipe(stream);
|
|
|
|
stream.on('error', (err) => {});
|
|
|
|
});
|
2018-01-23 20:18:55 +08:00
|
|
|
server.listen(common.PORT, () => {
|
2017-07-18 01:29:42 +08:00
|
|
|
bench.http({
|
|
|
|
path: '/',
|
2017-12-30 10:57:31 +08:00
|
|
|
requests,
|
|
|
|
maxConcurrentStreams: streams,
|
|
|
|
clients,
|
|
|
|
threads: clients
|
2017-07-18 01:29:42 +08:00
|
|
|
}, () => { server.close(); });
|
|
|
|
});
|
|
|
|
}
|