Add 'make bench' script
authorRyan Dahl <ry@tinyclouds.org>
Wed, 13 Oct 2010 23:20:24 +0000 (16:20 -0700)
committerRyan Dahl <ry@tinyclouds.org>
Wed, 13 Oct 2010 23:20:24 +0000 (16:20 -0700)
.gitignore
Makefile
benchmark/http_simple.js
benchmark/http_simple_bench.sh [new file with mode: 0755]

index eadb196..7863cee 100644 (file)
@@ -14,3 +14,4 @@ tmp/
 node
 node_g
 *.swp
+.benchmark_reports
index 221111c..bed8f36 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -36,9 +36,6 @@ test-pummel: all
 test-internet: all
        python tools/test.py internet
 
-benchmark: all
-       build/default/node benchmark/run.js
-
 # http://rtomayko.github.com/ronn
 # gem install ronn
 doc: doc/node.1 doc/api.html doc/index.html doc/changelog.html
@@ -85,4 +82,7 @@ dist: doc/node.1 doc/api.html
        rm -rf $(TARNAME)
        gzip -f -9 $(TARNAME).tar
 
-.PHONY: benchmark clean docclean dist distclean check uninstall install all test test-all website-upload
+bench:
+        benchmark/http_simple_bench.sh
+
+.PHONY: bench clean docclean dist distclean check uninstall install all test test-all website-upload
index 93903c4..8d66190 100644 (file)
@@ -74,7 +74,7 @@ var server = http.createServer(function (req, res) {
     body = fixed;
 
   } else if (command == "info") {
-    body = 'rev: ' + rev + '\n' + 'uname: ' + uname + '\n';
+    body = 'rev=' + rev + '\nuname="' + uname + '"\n';
 
   } else {
     status = 404;
diff --git a/benchmark/http_simple_bench.sh b/benchmark/http_simple_bench.sh
new file mode 100755 (executable)
index 0000000..79cbaa7
--- /dev/null
@@ -0,0 +1,77 @@
+#!/bin/sh
+
+SERVER=127.0.0.1
+PORT=8000
+
+# You may want to configure your TCP settings to make many ports available
+# to node and ab. On macintosh use: 
+#   sudo sysctl -w net.inet.ip.portrange.first=32768
+#   sudo sysctl -w net.inet.tcp.msl=1000
+
+if [ ! -d benchmark/ ]; then
+  echo "Run this script from the node root directory"
+  exit 1
+fi
+
+if [ $SERVER == "127.0.0.1" ]; then
+  ./node benchmark/http_simple.js &
+  node_pid=$!
+  sleep 1
+fi
+
+info=`curl -s http://$SERVER:$PORT/info`
+eval $info
+
+date=`date "+%Y%m%d%H%M%S"`
+
+ab_hello_world() {
+  local type="$1"
+  local ressize="$2"
+  if [ $type == "string" ]; then 
+    local uri="bytes/$ressize"
+  else
+    local uri="buffer/$ressize"
+  fi
+
+
+  name="ab-hello-world-$type-$ressize"
+
+  dir=".benchmark_reports/$name/$rev/"
+  if [ ! -d $dir ]; then
+    mkdir -p $dir
+  fi
+
+  summary_fn="$dir/$date.summary"
+  data_fn="$dir/$date.data"
+
+  echo "Bench $name starts in 3 seconds..."
+  # let shit calm down
+  sleep 3
+
+  # hammer that as hard as it can for 10 seconds.
+  ab -g $data_fn -c 100 -t 10 http://$SERVER:$PORT/$uri > $summary_fn
+
+  # add our data about the server
+  echo >> $summary_fn
+  echo >> $summary_fn
+  echo "webserver-rev: $rev" >> $summary_fn
+  echo "webserver-uname: $uname" >> $summary_fn
+
+  grep Req $summary_fn 
+
+  echo "Summary: $summary_fn"
+  echo
+}
+
+# 1k
+ab_hello_world 'string' '1024'
+ab_hello_world 'buffer' '1024'
+
+# 100k 
+ab_hello_world 'string' '102400'
+ab_hello_world 'buffer' '102400'
+
+
+if [ ! -z $node_pid ]; then
+  kill -9 $node_pid
+fi