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/controller.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/controller.py')
-rw-r--r-- | mitmproxy/controller.py | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/mitmproxy/controller.py b/mitmproxy/controller.py index 3b4c3092..582a6683 100644 --- a/mitmproxy/controller.py +++ b/mitmproxy/controller.py @@ -21,26 +21,28 @@ class Channel: Raises: exceptions.Kill: All connections should be closed immediately. """ - m.reply = Reply(m) - asyncio.run_coroutine_threadsafe( - self.master.addons.handle_lifecycle(mtype, m), - self.loop, - ) - g = m.reply.q.get() - if g == exceptions.Kill: - raise exceptions.Kill() - return g + if not self.should_exit.is_set(): + m.reply = Reply(m) + asyncio.run_coroutine_threadsafe( + self.master.addons.handle_lifecycle(mtype, m), + self.loop, + ) + g = m.reply.q.get() + if g == exceptions.Kill: + raise exceptions.Kill() + return g def tell(self, mtype, m): """ Decorate a message with a dummy reply attribute, send it to the master, then return immediately. """ - m.reply = DummyReply() - asyncio.run_coroutine_threadsafe( - self.master.addons.handle_lifecycle(mtype, m), - self.loop, - ) + if not self.should_exit.is_set(): + m.reply = DummyReply() + asyncio.run_coroutine_threadsafe( + self.master.addons.handle_lifecycle(mtype, m), + self.loop, + ) NO_REPLY = object() # special object we can distinguish from a valid "None" reply. |