[Django] #24720: using middleware.common to append slashes causes extra overhead to all requests that do not end in a slash

7 views
Skip to first unread message

Django

unread,
Apr 28, 2015, 1:59:41 AM4/28/15
to django-...@googlegroups.com
#24720: using middleware.common to append slashes causes extra overhead to all
requests that do not end in a slash
-------------------------------------+-------------------------------------
Reporter: electricjay | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core (Other) | Version: master
Severity: Normal | Keywords: optimization middleware
| common
Triage Stage: Unreviewed | Has patch: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Checking if a url is valid is just as costly as fully resolving the url,
so when the common middleware checks if it should append a slash it is
fully doubling the url resolution overhead (which is about 5%) (this
overhead only applies to urls that do not already end in a slash)

By deferring the checks until the ''process_response'' phase we can make
sure that we only pay the price for urls that actually need a slash
appended (that is to say would actually return a 404).

Pull request:
https://github.com/django/django/pull/4574

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

Django

unread,
Apr 28, 2015, 9:40:04 AM4/28/15
to django-...@googlegroups.com
#24720: using middleware.common to append slashes causes extra overhead to all
requests that do not end in a slash
-------------------------------------+-------------------------------------
Reporter: electricjay | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: optimization | Triage Stage: Accepted
middleware common |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_docs: => 0
* stage: Unreviewed => Accepted
* needs_tests: => 0
* needs_better_patch: => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/24720#comment:1>

Django

unread,
May 22, 2015, 1:20:00 PM5/22/15
to django-...@googlegroups.com
#24720: using middleware.common to append slashes causes extra overhead to all
requests that do not end in a slash
-------------------------------------+-------------------------------------
Reporter: electricjay | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: optimization | Triage Stage: Accepted
middleware common |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: 1 => 0


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

Django

unread,
May 26, 2015, 4:38:01 PM5/26/15
to django-...@googlegroups.com
#24720: using middleware.common to append slashes causes extra overhead to all
requests that do not end in a slash
-------------------------------------+-------------------------------------
Reporter: electricjay | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: optimization | Triage Stage: Accepted
middleware common |
Has patch: 1 | Needs documentation: 1

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* needs_docs: 0 => 1


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

Django

unread,
Jul 31, 2015, 12:05:25 PM7/31/15
to django-...@googlegroups.com
#24720: using middleware.common to append slashes causes extra overhead to all
requests that do not end in a slash
-------------------------------------+-------------------------------------
Reporter: electricjay | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Core (Other) | Version: master
Severity: Normal | Resolution: fixed

Keywords: optimization | Triage Stage: Accepted
middleware common |
Has patch: 1 | Needs documentation: 1
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"434d309ef6dbecbfd2b322d3a1da78aa5cb05fa8" 434d309e]:
{{{
#!CommitTicketReference repository=""
revision="434d309ef6dbecbfd2b322d3a1da78aa5cb05fa8"
Fixed #24720 -- Avoided resolving URLs that don't end in a slash twice in
CommonMiddleware.

This speeds up affected requests by about 5%.
}}}

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

Reply all
Reply to author
Forward
0 new messages