mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-25 18:03:50 +00:00
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.
This commit is contained in:
parent
ca75e2738a
commit
c5ad026cbe
1
test/bench/.gitignore
vendored
Normal file
1
test/bench/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
results
|
56
test/bench/README.md
Normal file
56
test/bench/README.md
Normal file
@ -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
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
3
test/bench/backend
Executable file
3
test/bench/backend
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
devd -p 10001 .
|
25
test/bench/profiler.py
Normal file
25
test/bench/profiler.py
Normal file
@ -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()]
|
5
test/bench/simple.mitmproxy
Executable file
5
test/bench/simple.mitmproxy
Executable file
@ -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
|
3
test/bench/simple.traffic
Executable file
3
test/bench/simple.traffic
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
hey -disable-keepalive http://localhost:10002/profiler.py | tee ./results/simple.perf
|
Loading…
Reference in New Issue
Block a user