kill_child_processes() {
isTopmost=$1
curPid=$2
childPids=`ps -o pid --no-headers --ppid ${curPid}`
for childPid in $childPids
do
kill_child_processes 0 $childPid
done
if [ $isTopmost -eq 0 ]; then
disown $curPid &> /dev/null
kill -9 $curPid &> /dev/null
fi
}
start_bench() {
concurrency=$1
num=50000
echo "Benchmarking nodejs (concurrency: ${concurrency})"
(node bench.js) & (sleep 1 ; exec ab -n ${num} -c ${concurrency} http://localhost:9615/ 2> /dev/null | grep "per second")
echo "Benchmarking tiny-http (concurrency: ${concurrency})"
(./hello_world 1> /dev/null) & (sleep 1 ; exec ab -n ${num} -c ${concurrency} http://localhost:9975/ 2> /dev/null | grep "per second")
echo "Benchmarking apache2 (concurrency: ${concurrency})"
exec ab -n ${num} -c ${concurrency} http://localhost/ 2> /dev/null | grep "per second"
kill_child_processes 1 $$
}
trap "kill_child_processes 1 $$; exit 0" INT
echo "Building tiny-http"
cargo build --release
rustc --opt-level=3 -Z lto -o hello_world -L target/release -L target/release/deps examples/hello-world.rs
echo "var http = require('http');" > bench.js
echo "http.createServer(function (req, res) {" >> bench.js
echo " res.writeHead(200, {'Content-Type': 'text/plain'});" >> bench.js
echo " res.end(\"hello world\");" >> bench.js
echo "}).listen(9615);" >> bench.js
start_bench 1
start_bench 2
start_bench 4
start_bench 8
start_bench 16
start_bench 32
start_bench 64
kill_child_processes 1 $$