Created
October 29, 2020 09:21
-
-
Save simone-sanfratello/dd67f1b2fa24c88984a1ed98e8f5928b to your computer and use it in GitHub Desktop.
benchmark express.static etag
This file contains hidden or 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
| 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 })); |
This file contains hidden or 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 { 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() |
This file contains hidden or 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
| { | |
| "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