Calculate Response Time

98 views
Skip to first unread message

liewsw28

unread,
Dec 22, 2017, 10:09:20 AM12/22/17
to Django users
Hi, 

I wonder how to calculate a response time for an entire Django project from where the user input the search criteria until the information are loaded and displayed onto the page. Please advise.

Thanks.

Jason

unread,
Dec 22, 2017, 10:50:46 AM12/22/17
to Django users
you can use an extension like https://chrome.google.com/webstore/detail/page-load-time/fploionmjgeclbkemipmkogoaohcdbig?hl=en to see how long a page takes to load

you can also use https://github.com/django-silk/silk to see the time queries take to execute

but the biggest factor will be using your browser dev tools network tab to see the actual request/response time for all your resources.

Larry Martell

unread,
Dec 22, 2017, 1:18:58 PM12/22/17
to django...@googlegroups.com
I had a need for this as well, and here is what I did. I split each
request up into 4 parts: Query Time, Process Time, Render Time, and
Network Latency. On the server I have a class all my request handlers
subclass and inherit from. That class has a method for getting the
data from the db and a method for processing the data before sending
the response. The execution of those 2 are grossly timed like this:

start = time.time()
data = self.get_data()
self._query_time = time.time() - start

start = time.time()
processed_data = self.postprocess_data(data)
self._processing_time = time.time() - start

These values are written to the db, and the id of the row is sent in
the context as pull_id. (Also written to the table is the URL, the
user and the datetime.)

On the client side I use the PerformanceTiming module
(https://w3c.github.io/perf-timing-primer/). I have a base template
that all my templates extend from and that has this code:

var t = performance.timing;
var render_time = parseInt(t.loadEventEnd) - parseInt(t.responseEnd);
var network_latency = parseInt(t.responseEnd) - parseInt(t.fetchStart);
var pull_id = {{ pull_id }};
$.ajax({url: 'metrics/' + pull_id + '/' + render_time + '/' +
network_latency});

The metrics handler adds the render_time and network_latency to the
row that the server inserted.

And we have a URL that only admins can access that queries this
metrics table and we can see who ran what when and how long each took.
> --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to django-users...@googlegroups.com.
> To post to this group, send email to django...@googlegroups.com.
> Visit this group at https://groups.google.com/group/django-users.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-users/2d6c71f1-ad71-42c9-8cda-5aef549bebd2%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages