Friday, December 22, 2017

Re: Calculate Response Time

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.

On Fri, Dec 22, 2017 at 2:08 AM, liewsw28 <liewsw28@gmail.com> wrote:
> 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.
>
> --
> 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+unsubscribe@googlegroups.com.
> To post to this group, send email to django-users@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.

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@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/CACwCsY70AyYEhdaMaa1EwoU-W2uAx6YXDAmvEKikCR4TVwaDCQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment