[Django] #25704: Response time in WSGIRequestHandler.log_request

9 views
Skip to first unread message

Django

unread,
Nov 7, 2015, 2:20:49 PM11/7/15
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+--------------------
Reporter: andreif | Owner: nobody
Type: New feature | Status: new
Component: HTTP handling | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/25704>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Nov 7, 2015, 2:30:11 PM11/7/15
to django-...@googlegroups.com
#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.

--

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

unread,
Nov 7, 2015, 2:35:45 PM11/7/15
to django-...@googlegroups.com
#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: Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by andreif):

* stage: Accepted => Unreviewed


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
}}}

or via middleware

{{{
#!python
class ResponseTimeMiddleware(object):
def process_view(self, request, view_func, view_args, view_kwargs):
start = time.time()
response = view_func(request, *view_args, **view_kwargs)

if response and getattr(response, 'is_rendered', True) is False:
response.rendered_content

logging.getLogger('response_time').debug(
'Response time %dms', (time.time() - start) * 1000)
return response
}}}


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.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:2>

Django

unread,
Nov 7, 2015, 2:46:44 PM11/7/15
to django-...@googlegroups.com
#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 andreif):

* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:3>

Django

unread,
Nov 7, 2015, 3:14:24 PM11/7/15
to django-...@googlegroups.com
#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
-------------------------------+------------------------------------

Comment (by andreif):

Kwarg sounds fine to me, but in this case we need kwargs for the other
parts which requires overriding `log_request` instead of `log_format`. I
this is ok then I will make a PR to #25684
(https://github.com/fcurella/django/tree/runserver-logging) to help with
the change. As soon as it's done, adding response time should be trivial.

--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:4>

Django

unread,
Nov 7, 2015, 3:16:22 PM11/7/15
to django-...@googlegroups.com
#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
-------------------------------+------------------------------------

Comment (by charettes):

By kwargs I meant using the `extra` kwarg of `logger.log()`.

--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:5>

Django

unread,
Nov 7, 2015, 3:19:18 PM11/7/15
to django-...@googlegroups.com
#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
-------------------------------+------------------------------------

Comment (by andreif):

Example of time:

{{{
[07/Nov/2015 17:37:05] "GET /inbox/ HTTP/1.1" 200 216874 0ms 5301ms
[07/Nov/2015 17:37:05] "GET /static/CACHE/css/f090a416387d.css HTTP/1.1"
304 0 0ms 4ms
[07/Nov/2015 17:37:05] "GET /static/CACHE/css/df20af4b0d04.css HTTP/1.1"
304 0 0ms 3ms
[07/Nov/2015 17:37:05] "GET /static/img/logo.svg HTTP/1.1" 304 0 0ms 2ms
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:6>

Django

unread,
Nov 7, 2015, 3:34:43 PM11/7/15
to django-...@googlegroups.com
#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
-------------------------------+------------------------------------

Comment (by andreif):

If #25684 will change order of parts in the log message, we could have
something like

{{{
[07/Nov/2015 17:37:05] HTTP/1.1 200 "GET /inbox/" 216874 5301ms
[07/Nov/2015 17:37:05] HTTP/1.1 304 "GET
/static/CACHE/css/f090a416387d.css" 0 4ms
[07/Nov/2015 17:37:05] HTTP/1.1 304 "GET
/static/CACHE/css/df20af4b0d04.css" 0 3ms
[07/Nov/2015 17:37:05] HTTP/1.1 304 "GET /static/img/logo.svg" 0 2ms
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:7>

Django

unread,
Nov 14, 2015, 1:33:15 PM11/14/15
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: andreif | Owner: kganey
Type: New feature | Status: assigned

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 kganey):

* status: new => assigned
* owner: nobody => kganey


--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:8>

Django

unread,
Nov 14, 2015, 1:36:50 PM11/14/15
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: andreif | Owner: kganey
Type: New feature | Status: assigned
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
-------------------------------+------------------------------------

Comment (by andreif):

Hi @kganey, I would rather fix it myself as soon as #25684 is closed.
Sorry for Easy picking

--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:9>

Django

unread,
Nov 14, 2015, 1:37:30 PM11/14/15
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: andreif | Owner: kganey
Type: New feature | Status: assigned
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: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by andreif):

* easy: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:10>

Django

unread,
Nov 14, 2015, 1:55:21 PM11/14/15
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: andreif | Owner: andreif

Type: New feature | Status: assigned
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: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by andreif):

* owner: kganey => andreif


--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:11>

Django

unread,
Jan 7, 2016, 10:09:42 AM1/7/16
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: andreif | Owner: andreif
Type: New feature | Status: assigned
Component: HTTP handling | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1


Comment:

Marking as "patch needs improvement" until it's updated after #25684 is
merged.

--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:12>

Django

unread,
Dec 31, 2021, 1:42:44 AM12/31/21
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: Andrei Fokau | Owner: (none)

Type: New feature | Status: new
Component: HTTP handling | Version: dev

Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* owner: Andrei Fokau => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:13>

Django

unread,
Oct 8, 2023, 11:54:04 AM10/8/23
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: Andrei Fokau | Owner: (none)
Type: New feature | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Tushar):

Is this issue still relevant? I would like to make a PR for this.

--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:14>

Django

unread,
Oct 9, 2023, 1:21:08 PM10/9/23
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: Andrei Fokau | Owner: (none)
Type: New feature | Status: new
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Natalia Bidart):

Replying to [comment:14 Tushar]:


> Is this issue still relevant? I would like to make a PR for this.

After reading the comments it seems so! Please go ahead and assign it to
you if you are ready to work on this. Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:15>

Django

unread,
Oct 11, 2023, 10:14:26 AM10/11/23
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: Andrei Fokau | Owner: Tushar

Type: New feature | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Tushar):

* owner: (none) => Tushar


* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:16>

Django

unread,
Oct 11, 2023, 2:44:40 PM10/11/23
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: Andrei Fokau | Owner: Tushar
Type: New feature | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Sarah Abderemane):

* cc: Sarah Abderemane (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:17>

Django

unread,
Oct 12, 2023, 4:05:59 AM10/12/23
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: Andrei Fokau | Owner: Tushar
Type: New feature | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Tushar):

Needed clarification on whether this should be an optional feature or
should it be there by default. Also, am I correct in my assumption that
the response time should be the amount of time the WSGI application takes
to process the request and send a response?

--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:18>

Django

unread,
Oct 27, 2023, 3:02:10 AM10/27/23
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: Andrei Fokau | Owner: Tushar
Type: New feature | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Sarah Boyce):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:19>

Django

unread,
Oct 27, 2023, 7:56:05 AM10/27/23
to django-...@googlegroups.com
#25704: Response time in WSGIRequestHandler.log_request
-------------------------------+------------------------------------
Reporter: Andrei Fokau | Owner: Tushar
Type: New feature | Status: assigned
Component: HTTP handling | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/25704#comment:20>

Reply all
Reply to author
Forward
0 new messages