Thursday, August 23, 2018

Django performance issue that's troubling

I have a Django app in development that performed perfectly with about 20 client records. Each client could have one or more support records and there are 40 potential support records, connected to the client with a ForeignKey (client_id). Then, I loading about 37K client records. Search queries perform almost instantaneously. A paginated list of support records with 40 pages and 10 clients per page comes back in half a second. Great performance.

However, when I click on any record in the list to go to update a specific support record for that specific client (it uses the PK in the URL so is a direct call to the UpdateView routine), I get about 10 second response times and these kind of statistics from Django-debug-toolbar:
SQL: 5 queries, 20ms (so clearly not a DB related performance issue)
TIME Resource usage:
User CPU time 8827 msec
System CPU time 137 msec
Elapsed time 9003 msec
Context switches 1 voluntary, 9639 involuntary
Browser timing:
domLoading 9026 (+52130) msec

CACHE: 0 calls in 0.00ms (so clearly not a cache issue either)

Here are some details: Django 2.1, python 3.6.3
Hardware: iMac with 32GB, i7 quad core
Installed apps: Bootstrap3 v9.1.0, crispy forms v1.7.0, easyPDF v0.1.1, registration-redux v2.2, Pillow v4.3.0

Here's one of the specific UpdateView routines being executed - there are only 5 fields in the AddictionForm plus the prime key (no image or file attachments).
class AddictionUpdate(PermissionRequiredMixin, UpdateView):
model = Addiction
form_class = AddictionForm
template_name = 'addiction_update.html'
permission_required = 'clientapp.change_addiction'
The slow response appears to be on UpdateView pages only, even though all updates are called with the prime key (ID) in the URL. Can anyone give me guidance where to look for improving the performance? Why all the involuntary context switches? Why the large domLoading time?

Thanks in advance -
Jim

No comments:

Post a Comment