Skip to content

Instantly share code, notes, and snippets.

@DustinAlandzes
Created April 13, 2018 05:15
Show Gist options
  • Save DustinAlandzes/fee86a1aa1bd281b695c12314c72dde4 to your computer and use it in GitHub Desktop.
Save DustinAlandzes/fee86a1aa1bd281b695c12314c72dde4 to your computer and use it in GitHub Desktop.
def check_time(path):
t = time.time()
channel_layer.send(u"http.request", {"reply_channel": u"http.response.test", "path": path, "method": "GET", "headers": {'host': 'localhost'}})
response = channel_layer.receive_many([u'http.response.test'])
print str(time.time() - t) + ' ' + str(len(response[1]['content']) if response and response[1] else '')
There's no full profiling path yet - this is something I hope to work on as we start integrating ASGI code at work early next year.
400ms for a request is already very long; I'm slightly concerned by that (unless that's normal without Channels installed as well).
If you want to do a basic profiling test, you can just write a very basic consumer that sends something onto the reply channel and then:
1) Directly inject requests into the channel layer from a python script, listen for the response, and time the roundtrip. You can import `channel_layer` from your project's `asgi.py` - if you don't have one the docs talk about how to make one. You'll want to call channel_layer.send("http.request", {"reply_channel": "http.response!test", "path": ....}) and channel_layer.receive_many(["http.response!test"]).
2) Directly make HTTP requests on the server running Daphne to it via localhost with a similar round trip measurement. Something like `ab` works well for this; remember to either target a very simple view or compare it with a similar test using a WSGI server.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment