Skip to content

Instantly share code, notes, and snippets.

@jpwilliams
Created October 19, 2017 13:58
Show Gist options
  • Save jpwilliams/a6205382e5916b9c3e954ff846452d28 to your computer and use it in GitHub Desktop.
Save jpwilliams/a6205382e5916b9c3e954ff846452d28 to your computer and use it in GitHub Desktop.
HTTP2 services - ~4,000 req/sec (0.25ms per req)
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()
})()
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