-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
benchmark: add simple https benchmark
Adds a simple benchmark for https server based on the http simple benchmark. Updates benchmarker integration for autocannon and wrk, so that they support https scheme. Also adds a new HTTPS section and improves HTTP/2 section in the benchmark guide. PR-URL: #36612 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]>
- Loading branch information
Showing
5 changed files
with
132 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
'use strict'; | ||
|
||
const fixtures = require('../../test/common/fixtures'); | ||
const https = require('https'); | ||
|
||
const options = { | ||
key: fixtures.readKey('rsa_private.pem'), | ||
cert: fixtures.readKey('rsa_cert.crt') | ||
}; | ||
|
||
const storedBytes = Object.create(null); | ||
const storedBuffer = Object.create(null); | ||
|
||
module.exports = https.createServer(options, (req, res) => { | ||
// URL format: /<type>/<length>/<chunks>/chunkedEnc | ||
const params = req.url.split('/'); | ||
const command = params[1]; | ||
let body = ''; | ||
const arg = params[2]; | ||
const n_chunks = parseInt(params[3], 10); | ||
const chunkedEnc = params.length >= 5 && params[4] === '0' ? false : true; | ||
let status = 200; | ||
|
||
let n, i; | ||
if (command === 'bytes') { | ||
n = ~~arg; | ||
if (n <= 0) | ||
throw new Error('bytes called with n <= 0'); | ||
if (storedBytes[n] === undefined) { | ||
storedBytes[n] = 'C'.repeat(n); | ||
} | ||
body = storedBytes[n]; | ||
} else if (command === 'buffer') { | ||
n = ~~arg; | ||
if (n <= 0) | ||
throw new Error('buffer called with n <= 0'); | ||
if (storedBuffer[n] === undefined) { | ||
storedBuffer[n] = Buffer.allocUnsafe(n); | ||
for (i = 0; i < n; i++) { | ||
storedBuffer[n][i] = 'C'.charCodeAt(0); | ||
} | ||
} | ||
body = storedBuffer[n]; | ||
} else { | ||
status = 404; | ||
body = 'not found\n'; | ||
} | ||
|
||
// example: https://localhost:port/bytes/512/4 | ||
// sends a 512 byte body in 4 chunks of 128 bytes | ||
const len = body.length; | ||
if (chunkedEnc) { | ||
res.writeHead(status, { | ||
'Content-Type': 'text/plain', | ||
'Transfer-Encoding': 'chunked' | ||
}); | ||
} else { | ||
res.writeHead(status, { | ||
'Content-Type': 'text/plain', | ||
'Content-Length': len.toString() | ||
}); | ||
} | ||
// send body in chunks | ||
if (n_chunks > 1) { | ||
const step = Math.floor(len / n_chunks) || 1; | ||
for (i = 0, n = (n_chunks - 1); i < n; ++i) | ||
res.write(body.slice(i * step, i * step + step)); | ||
res.end(body.slice((n_chunks - 1) * step)); | ||
} else { | ||
res.end(body); | ||
} | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
const common = require('../common.js'); | ||
|
||
const bench = common.createBenchmark(main, { | ||
type: ['bytes', 'buffer'], | ||
len: [4, 1024, 102400], | ||
chunks: [1, 4], | ||
c: [50, 500], | ||
chunkedEnc: [1, 0], | ||
benchmarker: ['test-double-https'], | ||
duration: 5 | ||
}); | ||
|
||
function main({ type, len, chunks, c, chunkedEnc, duration }) { | ||
const server = require('../fixtures/simple-https-server.js') | ||
.listen(common.PORT) | ||
.on('listening', () => { | ||
const path = `/${type}/${len}/${chunks}/${chunkedEnc}`; | ||
|
||
bench.http({ | ||
path, | ||
connections: c, | ||
scheme: 'https', | ||
duration | ||
}, () => { | ||
server.close(); | ||
}); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters