Skip to content

Instantly share code, notes, and snippets.

@simone-sanfratello
Created October 29, 2020 09:21
Show Gist options
  • Select an option

  • Save simone-sanfratello/dd67f1b2fa24c88984a1ed98e8f5928b to your computer and use it in GitHub Desktop.

Select an option

Save simone-sanfratello/dd67f1b2fa24c88984a1ed98e8f5928b to your computer and use it in GitHub Desktop.
benchmark express.static etag
var express = require('express')
var app = express()
const etag = process.argv[2] == 'ON'
app.listen(9876, () => process.stdout.write('start'))
app.use(express.static('public', { etag }));
const { spawn } = require('child_process')
const files = ['large.html', 'medium.html', 'small.html']
const etags = ['ON', 'off']
async function main() {
for (const file of files) {
for (const etag of etags) {
await bench(etag, file)
}
}
}
function bench(etag, file) {
return new Promise(resolve => {
console.log(`benchmarking ${file} ${etag}`)
const app = spawn('node', ['app.js', etag])
app.stdout.on('data', data => {
const msg = data.toString()
if (msg.includes('start')){
const wrk = spawn('wrk', ['-t8', '-c100', '-d10', 'http://localhost:9876/' + file])
wrk.stdout.on('data', (data) => {
console.log(data.toString())
})
wrk.on('close', () => {
console.log(`----------------------------`)
app.kill()
resolve()
})
}
})
})
}
main()
{
"name": "etag",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.17.1"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment