#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: andreif | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by charettes):
* needs_better_patch: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_docs: => 0
Old description:
> It's often useful to know how much time it takes for ` runserver` to
> respond without setting up a middleware or using the debug toolbar.
> Currently, one could monkeypatch WSGIRequestHandler (e.g. in `manage.py`)
> in order to get the time:
>
> {{{
> #!python
> from django.core.servers.basehttp import WSGIRequestHandler
> _handle = WSGIRequestHandler.handle
>
> def handle(self):
> self.request_started = time.time()
> _handle(self)
>
> def log_request(self, code='-', size='-'):
> self.log_message('"%s" %s %s %dms',
> self.requestline, str(code), str(size),
> (time.time() - self.request_started) * 1e3)
>
> WSGIRequestHandler.handle = handle
> WSGIRequestHandler.log_request = log_request
> }}}
>
> It seems easy to add it in the WSGIRequestHandler e.g.
> https://github.com/django/django/pull/5606. The response time is slightly
> longer than actual response time due to late measuring but think an easy
> implementation is better than the exact duration.
>
> This feature is blocked by https://code.djangoproject.com/ticket/25684
New description:
It's often useful to know how much time it takes for `runserver` to
respond without setting up a middleware or using the debug toolbar.
Currently, one could monkeypatch WSGIRequestHandler (e.g. in `manage.py`)
in order to get the time:
{{{
#!python
from django.core.servers.basehttp import WSGIRequestHandler
_handle = WSGIRequestHandler.handle
def handle(self):
self.request_started = time.time()
_handle(self)
def log_request(self, code='-', size='-'):
self.log_message('"%s" %s %s %dms',
self.requestline, str(code), str(size),
(time.time() - self.request_started) * 1e3)
WSGIRequestHandler.handle = handle
WSGIRequestHandler.log_request = log_request
}}}
It seems easy to add it in the WSGIRequestHandler e.g.
https://github.com/django/django/pull/5606. The response time is slightly
longer than actual response time due to late measuring but think an easy
implementation is better than the exact duration.
This feature is blocked by https://code.djangoproject.com/ticket/25684
--
Comment:
I'm not sure this should be part of the actual output of runserver but it
would make sense to at least provide it as a kwarg to the logger calls to
allow third party and users to refer to it in a formater or filter.
e.g. one could write a formatter that turns the text bold if request
latest more than X ms.
--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:1>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/065.ddc8b713a5433ba3ae2fcd1d8aceadcd%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.