Skip to content

Commit ff456b3

Browse files
committed
Add 'make bench' script
1 parent cdde22a commit ff456b3

File tree

4 files changed

+83
-5
lines changed

4 files changed

+83
-5
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ tmp/
1414
node
1515
node_g
1616
*.swp
17+
.benchmark_reports

Makefile

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@ test-pummel: all
3636
test-internet: all
3737
python tools/test.py internet
3838

39-
benchmark: all
40-
build/default/node benchmark/run.js
41-
4239
# http://rtomayko.github.com/ronn
4340
# gem install ronn
4441
doc: doc/node.1 doc/api.html doc/index.html doc/changelog.html
@@ -85,4 +82,7 @@ dist: doc/node.1 doc/api.html
8582
rm -rf $(TARNAME)
8683
gzip -f -9 $(TARNAME).tar
8784

88-
.PHONY: benchmark clean docclean dist distclean check uninstall install all test test-all website-upload
85+
bench:
86+
benchmark/http_simple_bench.sh
87+
88+
.PHONY: bench clean docclean dist distclean check uninstall install all test test-all website-upload

benchmark/http_simple.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ var server = http.createServer(function (req, res) {
7474
body = fixed;
7575

7676
} else if (command == "info") {
77-
body = 'rev: ' + rev + '\n' + 'uname: ' + uname + '\n';
77+
body = 'rev=' + rev + '\nuname="' + uname + '"\n';
7878

7979
} else {
8080
status = 404;

benchmark/http_simple_bench.sh

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
#!/bin/sh
2+
3+
SERVER=127.0.0.1
4+
PORT=8000
5+
6+
# You may want to configure your TCP settings to make many ports available
7+
# to node and ab. On macintosh use:
8+
# sudo sysctl -w net.inet.ip.portrange.first=32768
9+
# sudo sysctl -w net.inet.tcp.msl=1000
10+
11+
if [ ! -d benchmark/ ]; then
12+
echo "Run this script from the node root directory"
13+
exit 1
14+
fi
15+
16+
if [ $SERVER == "127.0.0.1" ]; then
17+
./node benchmark/http_simple.js &
18+
node_pid=$!
19+
sleep 1
20+
fi
21+
22+
info=`curl -s http://$SERVER:$PORT/info`
23+
eval $info
24+
25+
date=`date "+%Y%m%d%H%M%S"`
26+
27+
ab_hello_world() {
28+
local type="$1"
29+
local ressize="$2"
30+
if [ $type == "string" ]; then
31+
local uri="bytes/$ressize"
32+
else
33+
local uri="buffer/$ressize"
34+
fi
35+
36+
37+
name="ab-hello-world-$type-$ressize"
38+
39+
dir=".benchmark_reports/$name/$rev/"
40+
if [ ! -d $dir ]; then
41+
mkdir -p $dir
42+
fi
43+
44+
summary_fn="$dir/$date.summary"
45+
data_fn="$dir/$date.data"
46+
47+
echo "Bench $name starts in 3 seconds..."
48+
# let shit calm down
49+
sleep 3
50+
51+
# hammer that as hard as it can for 10 seconds.
52+
ab -g $data_fn -c 100 -t 10 http://$SERVER:$PORT/$uri > $summary_fn
53+
54+
# add our data about the server
55+
echo >> $summary_fn
56+
echo >> $summary_fn
57+
echo "webserver-rev: $rev" >> $summary_fn
58+
echo "webserver-uname: $uname" >> $summary_fn
59+
60+
grep Req $summary_fn
61+
62+
echo "Summary: $summary_fn"
63+
echo
64+
}
65+
66+
# 1k
67+
ab_hello_world 'string' '1024'
68+
ab_hello_world 'buffer' '1024'
69+
70+
# 100k
71+
ab_hello_world 'string' '102400'
72+
ab_hello_world 'buffer' '102400'
73+
74+
75+
if [ ! -z $node_pid ]; then
76+
kill -9 $node_pid
77+
fi

0 commit comments

Comments
 (0)