diff --git a/benchmark/README.md b/benchmark/README.md new file mode 100644 index 000000000..fd32f772a --- /dev/null +++ b/benchmark/README.md @@ -0,0 +1,36 @@ +# Benchmarking `node-http-proxy` + +The long-term goal of these scripts and documentation is to provide a consistent and well understood benchmarking process for `node-http-proxy` so that performance does not degrade over time. They were initially created to compare the performance of `v0.10.3` and `v1.0.0` (which was a significant rewrite). + +## Pre-requisites + +All benchmarking shall be done with [wrk](https://github.com/wg/wrk) which _is the same tool used for performance testing by the node.js core team._ **Make sure you have `wrk` installed before continuing**. + +``` +Usage: wrk + Options: + -c, --connections Connections to keep open + -d, --duration Duration of test + -t, --threads Number of threads to use + + -s, --script Load Lua script file + -H, --header Add header to request + --latency Print latency statistics + --timeout Socket/request timeout + -v, --version Print version details + + Numeric arguments may include a SI unit (1k, 1M, 1G) + Time arguments may include a time unit (2s, 2m, 2h) +``` + +## Benchmarks + +1. [Simple HTTP benchmark](#simple-http) + +### Simple HTTP + +_This benchmark requires three terminals running:_ + +1. **A proxy server:** `node benchmark/scripts/proxy.js` +2. **A target server:** `node benchmark/scripts/hello.js` +3. **A wrk process:** `wrk -c 20 -d 60 -t 2 http://127.0.0.1:8000` \ No newline at end of file diff --git a/benchmark/scripts/hello.js b/benchmark/scripts/hello.js new file mode 100644 index 000000000..be09b6388 --- /dev/null +++ b/benchmark/scripts/hello.js @@ -0,0 +1,3 @@ +require('http').createServer(function(req, res) { + res.end('Hello world!'); +}).listen(9000); \ No newline at end of file diff --git a/benchmark/scripts/proxy.js b/benchmark/scripts/proxy.js new file mode 100644 index 000000000..4b06f242f --- /dev/null +++ b/benchmark/scripts/proxy.js @@ -0,0 +1,6 @@ +var http = require('http'), + httpProxy = require('../../lib/node-http-proxy'); +// +// Create your proxy server +// +httpProxy.createServer(9000, 'localhost').listen(8000); diff --git a/benchmark/websockets-throughput.js b/benchmark/scripts/websockets-throughput.js similarity index 98% rename from benchmark/websockets-throughput.js rename to benchmark/scripts/websockets-throughput.js index 6787385ad..866e42461 100644 --- a/benchmark/websockets-throughput.js +++ b/benchmark/scripts/websockets-throughput.js @@ -1,7 +1,7 @@ var crypto = require('crypto'), WebSocket = require('ws'), async = require('async'), - httpProxy = require('../'); + httpProxy = require('../../'); var SERVER_PORT = 8415, PROXY_PORT = 8514;