Created
October 19, 2017 13:58
-
-
Save jpwilliams/a6205382e5916b9c3e954ff846452d28 to your computer and use it in GitHub Desktop.
HTTP2 services - ~4,000 req/sec (0.25ms per req)
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
const http2 = require('http2') | |
function makeReq (client) { | |
return new Promise((resolve, reject) => { | |
const req = client.request({':path': '/'}) | |
let data = '' | |
req.setEncoding('utf8') | |
req.on('data', (d) => { data += d }) | |
req.on('end', () => resolve(data)) | |
req.end() | |
}) | |
} | |
const client = http2.connect('http://localhost:3149') | |
;(async () => { | |
console.time('Total') | |
// change the number here to alter the total iterations | |
for (let i = 0; i < 500000; i++) { | |
await makeReq(client) | |
} | |
console.timeEnd('Total') | |
client.destroy() | |
})() |
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
const http2 = require('http2') | |
const server = http2.createServer() | |
server.on('stream', (stream, headers) => { | |
stream.respond({ | |
'content-type': 'text/html', | |
':status': 200 | |
}) | |
stream.end('foo') | |
}) | |
server.listen(3149) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment