6

I'm actually working on a Django website, working with django debug toolbar, on a digital ocean small dropplet. It all work with Postgresql, Django, gunicorn and Nginx.

What's bugging me is that the rending time is about 2.5 sec, and most of it is about the User CPU time.

Resource         Value
User CPU time    2271.395 msec
System CPU time  86.142 msec
Total CPU time   2357.537 msec
Elapsed time     2483.655 msec
Context switches 8 voluntary, 469 involuntary

Browser Chronology
domainLookup 0 (+0)
connect 0 (+0)
request 3 (+-1419272753107)
response 5653 (+-1419272758757)
domLoading 5669 (+-1419272758773)
domInteractive -1419272753104
domContentLoadedEvent -1419272753104 (+0)
loadEvent -1419272753104 (+0)

So, I wanted to increase the speed, I set up a fast Digital Ocean droplet (the biggest one), and the time look like the same. I understand that a biggest droplet mostly means more CPU Core, and thus, more simultaneous request.

But then the questions are those two :

  1. What is that User CPU time in opposite to the system CPU time ?
  2. How can I reduce that User CPU time ?
Spoutnik16
  • 834
  • 1
  • 10
  • 19
  • so you are with debug enabled? can you expand where that time is actually spent? – DRC Dec 22 '14 at 17:45
  • Well, I would like, but I don't know how. I mean, the website is working a few request with geodjango, but they take 140 ms only. (the _SQL_ tab in django-debug-toolbar). And I have no clue how to find where that User CPU Time is spend ( I'm not even sure it's on the server side and not on the client side ) But basically, my website search in a database what "art event" happend after the actual datetime. And then with AJAX and navigator.geolocation search the closest art avent to the user. – Spoutnik16 Dec 22 '14 at 18:24
  • on the debug toolbar when clicking on the Time it tells where that time is spent, also you should look for time spent in queries (even if often that's not the problem), and trying disabling some app like django-compressor (that in some cases lead to this issue) – DRC Dec 22 '14 at 18:29
  • @DRC I added all the info I can take under **Time**. But still, to me, all I understand is this : _the browser waits a long time, because User CPU Time is long_. And I don't know what User CPU Time is about. Is it about python generating the page content ? nginx being lost in the hard drive ? the server having problem with an user ? my website being non optimised ? – Spoutnik16 Dec 22 '14 at 18:35
  • is that every request and not the first ? have you tried disabling debug? also try to see what the [profiling panel of the debug toolbar](http://django-debug-toolbar.readthedocs.org/en/latest/panels.html#profiling) says, maybe you should also add your wsgi (gnunicorn) config. – DRC Dec 22 '14 at 18:42

1 Answers1

10

I have almost the same scenario (Small droplets on Digital Ocean, Postgres, uWSGI...), and break my head to discover why the CPU time was ~ 700ms on a simple page and ~ 3s on more complex page as showed on Django Debug Toolbar. But then I discover that much of this time was being used by the debug toolbar itself. When I turned it off and put another profiler (the middleware on http://djangosnippets.org/snippets/727/) I saw these times going down to ~ 200ms and ~800ms.

So answering your questions:

  1. Check Chris Pratt answer on Django Debug Toolbar: understanding the time panel

  2. There is no unique recipe to reduce CPU time. You'll have to analyze your profile output to discover where the cpu is being used.

I got the profile middleware from Yugal Jindle's answer: How to profile django application with respect to execution time?. Check it for other profiler option using HotShot.

Community
  • 1
  • 1
Ricardo Silva
  • 815
  • 10
  • 12
  • I forward this. First time I ran my local server after setting everything up, the CPU had an average time of almost 3 seconds. Disabled the debug_toolbar by commenting out the first line within the middleware in settings.py, as well as debug_toolbar from installed apps - got 5 times faster. This is actually mentioned by David Winterbottom in an email from 2013: https://groups.google.com/forum/#!topic/django-oscar/phPAfwNbtN4 – William Karlsson May 10 '18 at 05:30
  • You forward this? – John R Perry Aug 22 '22 at 13:19