Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reduce User CPU Time on django

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 ?
like image 529
Spoutnik16 Avatar asked Jan 09 '23 05:01

Spoutnik16


1 Answers

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.

like image 65
Ricardo Silva Avatar answered Jan 17 '23 12:01

Ricardo Silva