sqldjangopage-load-timedjango-debug-toolbar

Slow Django Page - Doesn't Appear to be caused by SQL


I'm trying to debug a slow Django listview page. The page currently displays all tests (133), as well as the latest result for each test. There are approximately 60,000 results, each result having a FK relationship to a single test.

I've optimized the SQL (I think) by selecting the latest result for each test, and passing it in as a prefetch related to my tests query. Django Debug Toolbar shows that the SQL is taking ~350ms, but the page load is ~3.5s.

All Tests

If I restrict the list view to a single test though, the SQL is ~7.5ms, and page load is ~100ms.

One Test

I'm not fetching anything from S3 etc, and not rendering any images or the like.

So my question is, what could be causing the slowness? It seems like it is the SQL, since as the result set grows so does page load, but maybe rendering of each item or something similar? Any guidance on what to look into next would be appreciated.


Solution

  • You can force execute your Django query set: test_list = list(your_queryset) and return in your view simple text HttpResponse("return this string"), then you can check time without rendering. Also Django Debug Toolbar and slow your app, maybe here your case: https://github.com/jazzband/django-debug-toolbar/issues/910