django-debug-toolbar icon indicating copy to clipboard operation
django-debug-toolbar copied to clipboard

Extremely long request time when RedirectsPanel is disabled

Open maltebeckmann opened this issue 4 years ago • 15 comments

I returned to django-debug-toolbar after many years now that I am using cookiecutter-django. Awesome that it's still around!

I had extremely long loading times of ~25-30 sec/page load. When deactivating the toolbar, I got down to 1 sec. So the I tried disabling panels but to my surprise, when I activated all panels in DEBUG_TOOLBAR_PANELS list, it was all fine!

Then I realized there was a setting in DEBUG_TOOLBAR_CONFIG that appears to turn off RedirectsPanel by default:

DEBUG_TOOLBAR_CONFIG = { "DISABLE_PANELS": ["debug_toolbar.panels.redirects.RedirectsPanel"], "SHOW_TEMPLATE_CONTEXT": True, }

Not sure this is a default or a default set by the cookiecutter-django team. Either way, when I comment out the DISABLE_PANELS line, i.e. bring the RedirectsPanel line back, the page loads in 2-3 sec, rather than 25-30 sec.

Any idea how that can be?

maltebeckmann avatar May 03 '20 22:05 maltebeckmann

That's very surprising. The redirects panel doesn't do that much: https://github.com/jazzband/django-debug-toolbar/blob/master/debug_toolbar/panels/redirects.py

I'm really not sure why this panel should slow down your page that much especially when no redirects happen at all.

matthiask avatar May 04 '20 08:05 matthiask

Yes, it's very odd indeed. When I enable redirects, I get ~25 sec in the first run, all subsequent reloads come in at 7 sec. All significantly higher than the 0.9 sec when the redirects panel is enabled.

It's all in the request part ~ +7000ms.

maltebeckmann avatar May 04 '20 08:05 maltebeckmann

Anything I can provide to allow for debugging? I can see why the redirect panel is off by default. I essentially run Django 3.0.5 with Django-CMS 3.7.2 in the cookiecutter-django wrapper.

maltebeckmann avatar May 04 '20 08:05 maltebeckmann

After some more testing: If I

  1. comment out 'debug_toolbar.panels.redirects.RedirectsPanel' in DEBUG_TOOLBAR_PANELS
  2. leave all other panels in with DEBUG_TOOLBAR_PANELS
  3. comment out "DISABLE_PANELS": ["debug_toolbar.panels.redirects.RedirectsPanel"],

Then all seems to be fine.

maltebeckmann avatar May 04 '20 09:05 maltebeckmann

1. comment out 'debug_toolbar.panels.redirects.RedirectsPanel' in DEBUG_TOOLBAR_PANELS
2. leave all other panels in with DEBUG_TOOLBAR_PANELS
3. comment out "DISABLE_PANELS": ["debug_toolbar.panels.redirects.RedirectsPanel"],

This improved request time for me, but DJDT still causes causes a latency of about 4s. Fortunately disabling SQL panel from the toolbar itself cuts the time down to <1s.

snmishra avatar Aug 14 '20 20:08 snmishra

I encountered this issue as well, I noticed that even using an empty DISABLE_PANELS: [] in the DEBUG_TOOLBAR_CONFIG makes the requests 20x slower.

mgibeau avatar Sep 24 '20 20:09 mgibeau

V3 of the toolbar will still run parts of the analysis regardless if panels are enabled. That's something that can be changed, but in the mean time, designing applications so that you can enabled/disable the toolbar as needed is probably best.

tim-schilling avatar Sep 25 '20 03:09 tim-schilling

I've just submitted #1394. Same symptom, seemingly different cause, but may be related.

pembo13 avatar Oct 21 '20 05:10 pembo13

Just stumbled on this - removing DEBUG_TOOLBAR_CONFIG results in huge speedup time for me. For weeks I just assumed that the slow load times were due to a completely unrelated Docker for Mac issue 🤦

ahmedaljawahiry avatar Apr 27 '21 21:04 ahmedaljawahiry

Whoa for me as well, removing config did the trick 🤪

webjunkie avatar Jun 02 '21 07:06 webjunkie

Removing config also resolved issue for me.

briang1 avatar Jun 17 '21 20:06 briang1

For me when I turn debug=True, remove config does not work, but add a callback function works and make Django fast again

DEBUG_TOOLBAR_CONFIG = {
    'SHOW_TOOLBAR_CALLBACK': lambda r: False,  # disables it
    # '...
}

xjlin0 avatar Jan 16 '22 01:01 xjlin0

@xjlin0 You should avoid installing the debug toolbar app & middleware at all rather than disabling it via the callback. The toolbar is not meant for production usage and that pattern implies you're still using the toolbar's middleware in a production environment.

@ahmedaljawahiry @webjunkie @briang1 I'm a bit late on this, but what were your previous configs before removing them entirely?

tim-schilling avatar Jan 17 '22 17:01 tim-schilling

@tim-schilling I had the following:

DEBUG_TOOLBAR_CONFIG = {
    'INTERCEPT_REDIRECTS': False
}

briang1 avatar Jan 17 '22 17:01 briang1

Anyone who has commented on this saying removing the redirect panel fixed this for them, can you let me know (if you remember) what view(s) and flows this slowdown occurred for? I can't reproduce this in the example app.

tim-schilling avatar Aug 29 '22 01:08 tim-schilling