Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explore the use of Django Debug Toolbar #2939

Open
FroggyFlox opened this issue Dec 18, 2024 · 2 comments
Open

Explore the use of Django Debug Toolbar #2939

FroggyFlox opened this issue Dec 18, 2024 · 2 comments

Comments

@FroggyFlox
Copy link
Member

Now that we're on a more modern version of Django, we can explore the use of niceties and tools to help various aspects of the developer experience. In the Django world, the Django Debug Toolbar is a very popular and highly-recommended tool to provide such enhanced experience. As the project puts it:

The Django Debug Toolbar is a configurable set of panels that display various debug information about the current request/response and when clicked, display more details about the panel's content.

Behind this relatively simple description hides a rather powerful tool to catch and list a lot of information about DJango's operation when one visits a page. This is thus potentially very helpful in identifying slow and sub-optimal operations in Rockstor's backend operations. In particular, the ability to see all SQL queries done should be able to pinpoint unnecessary queries we may be doing and thus highlight bits we can speed up and simplify.

Main repository: https://github.com/django-commons/django-debug-toolbar
License: BSD-3-Clause (https://github.com/django-commons/django-debug-toolbar#BSD-3-Clause-1-ov-file)
Maintainers: Django-commons (https://github.com/django-commons)
Docs: https://django-debug-toolbar.readthedocs.io/en/stable/index.html

As mentioned above, this is a very very popular project that is currently very active.
Django 4.2 is the currently minimum version supported so we still fit.

I'm opening this issue so that we can explore in the open to what extent Django Debug Toolbar (DjDT) can help us and whether it is worth the setup. I'll also open a draft PR to better illustrate what would be needed to use it in Rockstor. Note that this is a developer tool only and should thus not be included in an rpm release.

FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Dec 18, 2024
Add django-debug-toolbar package to the optional `dev` dependency group
Add `--dev` flag to build.sh to run `poetry install` with that flag
Add DjDTB to settings.py
Add DjDTB urls
@FroggyFlox
Copy link
Member Author

With the configuration in FroggyFlox@3b9f8f2, we have:

  • the toolbar showing up
  • requests are caught and the toolbar is automatically updated with the latest AJAX call detected (thanks to UPDATE_ON_FETCH)
  • all previous requests are available in the History panel. For instance, visiting the "Shares" page shows a lost of requests in the history panel:

image

Selecting the one related to the SharesListView (as selected in the screenshot above), and we can see that it made 23 SQL queries in 83 ms, with the details for each of these:
image

@FroggyFlox
Copy link
Member Author

Further illustration with a known heavy page: Rock-on
image
This triggered 452 queries that took a little over 1 sec, but...
image
The page took a little over 6 sec to load, mostly loading the DOM (I think).

FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Dec 24, 2024
FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Dec 24, 2024
FroggyFlox added a commit to FroggyFlox/rockstor-core that referenced this issue Dec 24, 2024
Rely on the DJANGO_DEBUG env variable to set DEBUG boolean that will in
turn decide the installation of the dev group dependencies (includes
the Django debug toolbar) as the appearance of the toolbar in the UI.

Leave commented (= unset) by default to keep the default build NOT in
the dev mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants