diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2018-04-07 07:48:58 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@corte.si> | 2018-04-16 09:19:14 +1200 |
commit | b663a224a3655aab95a39eab2450f1f0e98997f2 (patch) | |
tree | 81e3f5445c0af49fbfe09a6bcbd3c89dc3e7904e /mitmproxy/master.py | |
parent | 5f74adc2df6d2a9452a9e3a6923fe05ba579e9e6 (diff) | |
download | mitmproxy-b663a224a3655aab95a39eab2450f1f0e98997f2.tar.gz mitmproxy-b663a224a3655aab95a39eab2450f1f0e98997f2.tar.bz2 mitmproxy-b663a224a3655aab95a39eab2450f1f0e98997f2.zip |
Improve benchmarking
- The benchmark addon now manages setting up and tearing down the backend and
traffic processes itself.
- Use wrk instead of hey. I get more consistent results with this tool, and hey
shows a strange tail-latency bump that seems artificial.
- Make termination behaviour simpler. The bencmark revealed a bug where .done
events were not called if the proxy was shut down by an addon.
Diffstat (limited to 'mitmproxy/master.py')
-rw-r--r-- | mitmproxy/master.py | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/mitmproxy/master.py b/mitmproxy/master.py index 51aed1e0..dff8ca5c 100644 --- a/mitmproxy/master.py +++ b/mitmproxy/master.py @@ -81,7 +81,6 @@ class Master: self.addons.trigger("running") while True: if self.should_exit.is_set(): - asyncio.get_event_loop().stop() return self.addons.trigger("tick") await asyncio.sleep(0.1) @@ -94,13 +93,18 @@ class Master: loop.run_forever() finally: self.shutdown() + pending = asyncio.Task.all_tasks() + loop.run_until_complete(asyncio.gather(*pending)) loop.close() self.addons.trigger("done") def shutdown(self): - if self.server: - self.server.shutdown() - self.should_exit.set() + if not self.should_exit.is_set(): + if self.server: + self.server.shutdown() + self.should_exit.set() + loop = asyncio.get_event_loop() + loop.stop() def _change_reverse_host(self, f): """ |