aboutsummaryrefslogtreecommitdiffstats
path: root/test/bench
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@corte.si>2018-03-17 10:06:46 +1300
committerAldo Cortesi <aldo@corte.si>2018-03-17 10:06:46 +1300
commitc5ad026cbe21e1dfe1d189dfd7f7f0751b7dbb75 (patch)
treea38d8e14264877e1a9a74d10c8d6770493071833 /test/bench
parentca75e2738ab9f783cb9a4e675e8353b98eb208fc (diff)
downloadmitmproxy-c5ad026cbe21e1dfe1d189dfd7f7f0751b7dbb75.tar.gz
mitmproxy-c5ad026cbe21e1dfe1d189dfd7f7f0751b7dbb75.tar.bz2
mitmproxy-c5ad026cbe21e1dfe1d189dfd7f7f0751b7dbb75.zip
bench: Add some very simple manual benchmarking helpers
This includes a profiler addon that we might consider for promotion to a builtin down the track.
Diffstat (limited to 'test/bench')
-rw-r--r--test/bench/.gitignore1
-rw-r--r--test/bench/README.md56
-rwxr-xr-xtest/bench/backend3
-rw-r--r--test/bench/profiler.py25
-rwxr-xr-xtest/bench/simple.mitmproxy5
-rwxr-xr-xtest/bench/simple.traffic3
6 files changed, 93 insertions, 0 deletions
diff --git a/test/bench/.gitignore b/test/bench/.gitignore
new file mode 100644
index 00000000..1a06816d
--- /dev/null
+++ b/test/bench/.gitignore
@@ -0,0 +1 @@
+results
diff --git a/test/bench/README.md b/test/bench/README.md
new file mode 100644
index 00000000..05741c07
--- /dev/null
+++ b/test/bench/README.md
@@ -0,0 +1,56 @@
+
+This directory contains a set of tools for benchmarking and profiling mitmproxy.
+At the moment, this is simply to give developers a quick way to see the impact
+of their work. Eventually, this might grow into a performance dashboard with
+historical data, so we can track performance over time.
+
+
+# Setup
+
+Install the following tools:
+
+ go get -u github.com/rakyll/hey
+ go get github.com/cortesi/devd/cmd/devd
+
+You may also want to install snakeviz to make viewing profiles easier:
+
+ pip install snakeviz
+
+In one window, run the devd server:
+
+ ./backend
+
+
+# Running tests
+
+Each run consists of two files - a mitproxy invocation, and a traffic generator.
+Make sure the backend is started, then run the proxy:
+
+ ./simple.mitmproxy
+
+Now run the traffic generator:
+
+ ./simple.traffic
+
+After the run is done, quit the proxy with ctrl-c.
+
+
+# Reading results
+
+Results are placed in the ./results directory. You should see two files - a
+performance log from **hey**, and a profile. You can view the profile like so:
+
+ snakeviz ./results/simple.prof
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/test/bench/backend b/test/bench/backend
new file mode 100755
index 00000000..12a05d70
--- /dev/null
+++ b/test/bench/backend
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+devd -p 10001 . \ No newline at end of file
diff --git a/test/bench/profiler.py b/test/bench/profiler.py
new file mode 100644
index 00000000..9072e17d
--- /dev/null
+++ b/test/bench/profiler.py
@@ -0,0 +1,25 @@
+import cProfile
+from mitmproxy import ctx
+
+
+class Profile:
+ """
+ A simple profiler addon.
+ """
+ def __init__(self):
+ self.pr = cProfile.Profile()
+
+ def load(self, loader):
+ loader.add_option(
+ "profile_path",
+ str,
+ "/tmp/profile",
+ "Destination for the run profile, saved at exit"
+ )
+ self.pr.enable()
+
+ def done(self):
+ self.pr.dump_stats(ctx.options.profile_path)
+
+
+addons = [Profile()] \ No newline at end of file
diff --git a/test/bench/simple.mitmproxy b/test/bench/simple.mitmproxy
new file mode 100755
index 00000000..9de32981
--- /dev/null
+++ b/test/bench/simple.mitmproxy
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+mkdir -p results
+mitmdump -p 10002 --mode reverse:http://devd.io:10001 \
+ -s ./profiler.py --set profile_path=./results/simple.prof
diff --git a/test/bench/simple.traffic b/test/bench/simple.traffic
new file mode 100755
index 00000000..08200e05
--- /dev/null
+++ b/test/bench/simple.traffic
@@ -0,0 +1,3 @@
+#!/bin/sh
+
+hey -disable-keepalive http://localhost:10002/profiler.py | tee ./results/simple.perf \ No newline at end of file