#33700: APPEND_SLASH adds significant latency to all requests not ending in / 
(even
if successful)
-------------------------------------+-------------------------------------
               Reporter:  Anders     |          Owner:  nobody
  Kaseorg                            |
                   Type:             |         Status:  new
  Cleanup/optimization               |
              Component:  HTTP       |        Version:  4.0
  handling                           |
               Severity:  Normal     |       Keywords:  CommonMiddleware
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Originally, `APPEND_SLASH` worked by looking for 404 responses and
 replacing them with redirects, so as not to unnecessarily impact the
 performance of successful responses. However, commit
 9390da7fb6e251eaa9a785692f987296cb14523f in 1.9.5/1.10 changed this to
 check `should_redirect_with_slash()` on every request, resulting in a
 moderately expensive extra `urlconf` lookup for every request not ending
 with `/`, whether or not it succeeds as written.

 This performance impact was not considered in the commit message or the
 corresponding ticket #26293, so I assume it was an oversight. That ticket
 asserted “This doesn't really make sense, since the two settings are not
 interdependent”, which is incorrect—performance was the reason for the
 interdependence.

 The overhead was found to be significant enough in Zulip to merit
 [https://github.com/zulip/zulip/commit/229090a3a58de15eb2a76a8e513fa5d9a190170c
 subclassing] `CommonMiddleware` to skip it in certain conditions.

 Here’s a [https://gist.github.com/andersk/0140318d32f1657ff40cad9e7e353bd2
 minimal test project] with an exaggerated number of routes so the overhead
 can be easily observed.

 {{{
 $ ./manage.py runserver
 }}}

 {{{
 $ wrk http://127.0.0.1:8000/url9999
 Running 10s test @ http://127.0.0.1:8000/url9999
   2 threads and 10 connections
   Thread Stats   Avg      Stdev     Max   +/- Stdev
     Latency   232.40ms   73.85ms 570.86ms   69.16%
     Req/Sec    21.70      9.47    40.00     63.35%
   426 requests in 10.01s, 64.90KB read
 Requests/sec:     42.56
 Transfer/sec:      6.48KB
 $ sed -i 's/# APPEND_SLASH = False/APPEND_SLASH = False/'
 slash_test_settings.py
 $ wrk http://127.0.0.1:8000/url9999
 Running 10s test @ http://127.0.0.1:8000/url9999
   2 threads and 10 connections
   Thread Stats   Avg      Stdev     Max   +/- Stdev
     Latency   139.80ms   52.07ms 352.19ms   69.09%
     Req/Sec    36.46     12.23    60.00     58.12%
   714 requests in 10.01s, 108.79KB read
 Requests/sec:     71.32
 Transfer/sec:     10.87KB
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/33700>
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 view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070180b64975a6-86b0be84-4478-46f5-97d6-8104a74e88d9-000000%40eu-central-1.amazonses.com.

Reply via email to