Merge branch 'vanilla-libeio'
[platform/upstream/nodejs.git] / benchmark / http_simple_bench.sh
1 #!/bin/bash
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