drowyek
drowyek

Reputation: 11

Decrease django's CPU Elapsed time from 31353.191 msec

According to the django-debug-toolbar my CPU Time is around 31000ms (on average). This is true for my own pages as well as for the admin. Here is the breakdown when loading http://127.0.0.1:8000/admin/:

Resource usage

User CPU time          500.219 msec
System CPU time        57.526 msec
Total CPU time         557.745 msec
Elapsed time           30236.380 msec
Context switches       11 voluntary, 1345 involuntary

Browser timing (Timing attribute / Milliseconds since navigation start (+length))

domainLookup            2 (+0)
connect                 2 (+0)
request                 7 (+30259)
response                30263 (+3)
domLoading              30279 (+1737)
domInteractive          31154
domContentLoadedEvent   31155 (+127)
loadEvent               32016 (+10) 

As far as I understand the "request" step [7 (+30259)] is the biggest bottleneck here. But what does that tell me? The request panel just shows some variables, and no GET nor POST data.

The same code works fine hosted on pythonanywhere, locally I am running a MacBook Air (i5, 1.3 Ghz, 8GB RAM). The performance hasn't been this poor all the time. IIRC it happened "over night". One day I started the dev server and it was slow. Didn't change anything in the code or DB.

Is it right to assume that it could be an issue with my local machine?

EDIT: I tried running ./manage.py runserver --noreload but the performance didn't improve. Also, starting the dev-server (using ./manage.py runserver) also takes around 40s and accessing the DB using postico takes around 1 minute. Starting the dev-sever while commenting out the database from django's settings makes load times normal.

Upvotes: 0

Views: 648

Answers (1)

drowyek
drowyek

Reputation: 11

Solved it. This post pointed me in the right direction. Essentially, I ended up "reseting" my hostfile according to this post. My hostfile now looks like this:

127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost

Does not, however, explain what caused the sudden "overnight" issue in the first place. My guess: renamed hostname. A couple of days ago my hostname ended up sounding something along the lines of android- (similar to this) which was apparently caused by me using Android's file share tool. Ended up renaming my hostname to my username (see instructions below).

Perform the following tasks to change the workstation hostname using the scutil command. Open a terminal. Type the following command to change the primary hostname of your Mac: This is your fully qualified hostname, for example myMac.domain.com sudo scutil --set HostName Type the following command to change the Bonjour hostname of your Mac: This is the name usable on the local network, for example myMac.local. sudo scutil --set LocalHostName Optional: If you also want to change the computer name, type the following command: This is the user-friendly computer name you see in Finder, for example myMac. sudo scutil --set ComputerName Flush the DNS cache by typing: dscacheutil -flushcache Restart your Mac.

from here

Didn't test the "renaming hostname" theory, though.

Upvotes: 1

Related Questions