2017-08-10 00:52:35 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common.js');
|
|
|
|
const PORT = common.PORT;
|
|
|
|
|
2017-09-14 03:48:53 +02:00
|
|
|
const bench = common.createBenchmark(main, {
|
2017-08-10 00:52:35 +02:00
|
|
|
n: [1e3],
|
2018-10-25 04:23:25 +02:00
|
|
|
nheaders: [0, 10, 100, 1000]
|
2018-05-22 12:10:53 +02:00
|
|
|
}, { flags: ['--no-warnings'] });
|
2017-08-10 00:52:35 +02:00
|
|
|
|
2017-12-30 03:57:31 +01:00
|
|
|
function main({ n, nheaders }) {
|
2017-08-10 00:52:35 +02:00
|
|
|
const http2 = require('http2');
|
2017-11-21 14:46:13 +01:00
|
|
|
const server = http2.createServer({
|
|
|
|
maxHeaderListPairs: 20000
|
|
|
|
});
|
2017-08-10 00:52:35 +02:00
|
|
|
|
2017-08-12 16:49:31 +02:00
|
|
|
const headersObject = {
|
|
|
|
':path': '/',
|
|
|
|
':scheme': 'http',
|
|
|
|
'accept-encoding': 'gzip, deflate',
|
|
|
|
'accept-language': 'en',
|
|
|
|
'content-type': 'text/plain',
|
|
|
|
'referer': 'https://example.org/',
|
|
|
|
'user-agent': 'SuperBenchmarker 3000'
|
|
|
|
};
|
|
|
|
|
2017-08-10 00:52:35 +02:00
|
|
|
for (var i = 0; i < nheaders; i++) {
|
|
|
|
headersObject[`foo${i}`] = `some header value ${i}`;
|
|
|
|
}
|
|
|
|
|
|
|
|
server.on('stream', (stream) => {
|
|
|
|
stream.respond();
|
|
|
|
stream.end('Hi!');
|
|
|
|
});
|
|
|
|
server.listen(PORT, () => {
|
2017-11-21 14:46:13 +01:00
|
|
|
const client = http2.connect(`http://localhost:${PORT}/`, {
|
|
|
|
maxHeaderListPairs: 20000
|
|
|
|
});
|
2017-08-10 00:52:35 +02:00
|
|
|
|
|
|
|
function doRequest(remaining) {
|
|
|
|
const req = client.request(headersObject);
|
2018-10-31 00:17:33 +01:00
|
|
|
req.resume();
|
2017-08-10 00:52:35 +02:00
|
|
|
req.on('end', () => {
|
|
|
|
if (remaining > 0) {
|
|
|
|
doRequest(remaining - 1);
|
|
|
|
} else {
|
|
|
|
bench.end(n);
|
|
|
|
server.close();
|
|
|
|
client.destroy();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
bench.start();
|
|
|
|
doRequest(n);
|
|
|
|
});
|
|
|
|
}
|