summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorisaacs <i@izs.me>2012-12-18 11:56:53 -0800
committerisaacs <i@izs.me>2012-12-18 11:56:53 -0800
commit43538f4f8fc7c3395c53c8fff808d31d8faf79db (patch)
tree2a6455820b39d4afcbc533de9d27ec123e408087
parentd607d856afc744b1e6bc42cdb9b67b6c4e7e4876 (diff)
downloadnode-43538f4f8fc7c3395c53c8fff808d31d8faf79db.tar.gz
benchmark: Add http-flamegraph
This is very similar to http.sh, but generates a flamegraph with dtrace, pruning off the single-hit stacks so that we can more easily see the places where relevant amounts of time are spent.
-rw-r--r--benchmark/http-flamegraph.sh79
1 files changed, 79 insertions, 0 deletions
diff --git a/benchmark/http-flamegraph.sh b/benchmark/http-flamegraph.sh
new file mode 100644
index 000000000..ad1f6a22a
--- /dev/null
+++ b/benchmark/http-flamegraph.sh
@@ -0,0 +1,79 @@
+#!/bin/bash
+cd "$(dirname "$(dirname $0)")"
+if type sysctl &>/dev/null; then
+ sudo sysctl -w net.inet.ip.portrange.first=12000
+ sudo sysctl -w net.inet.tcp.msl=1000
+ sudo sysctl -w kern.maxfiles=1000000 kern.maxfilesperproc=1000000
+fi
+ulimit -n 100000
+
+./node benchmark/http_simple.js &
+nodepid=$!
+echo "node pid = $nodepid"
+sleep 1
+
+# has to stay alive until dtrace exits
+dtrace -n 'profile-97/pid == '$nodepid' && arg1/{ @[jstack(150, 8000)] = count(); } tick-60s { exit(0); }' > stacks.src &
+dtracepid=$!
+echo "dtrace pid = $dtracepid"
+
+test () {
+ n=$1
+ c=$2
+ k=$3
+ ab $k -n $n -c $c http://127.0.0.1:8000/${TYPE:-bytes}/${LENGTH:-1024} \
+ 2>&1 | grep Req
+}
+
+test 10000 100
+test 10000 10 -k
+test 10000 100 -k
+test 30000 100 -k
+test 60000 100 -k
+
+echo 'Keep going until dtrace stops listening...'
+while pargs $dtracepid &>/dev/null; do
+ ab -k -n 60000 -c 100 http://127.0.0.1:8000/${TYPE:-bytes}/${LENGTH:-1024} 2>&1 | grep Req
+done
+
+kill $nodepid
+
+echo 'Pluck off all the stacks that only happen once.'
+
+node -e '
+var fs = require("fs");
+var data = fs.readFileSync("stacks.src", "utf8").split(/\n/);
+var out = fs.createWriteStream("stacks.out");
+function write(l) {
+ out.write(l + "\n");
+}
+write(data[0]);
+write(data[1]);
+write(data[2]);
+
+var stack = [];
+var i = 4;
+var saw2 = false
+for (; i < data.length && !saw2; i++) {
+ if (data[i] === " 2") {
+ stack.forEach(function(line) {
+ write(line);
+ });
+ write(data[i]);
+ saw2 = true;
+ } else if (data[i] === " 1") {
+ stack = [];
+ } else {
+ stack.push(data[i]);
+ }
+}
+
+for (; i < data.length; i++)
+ write(data[i]);
+'
+
+echo 'Turn the stacks into a svg'
+stackvis dtrace flamegraph-svg < stacks.out > stacks.svg
+
+echo ''
+echo 'done. Results in stacks.svg'