Get memory-use serverside when rendering a view?

7 views
Skip to first unread message

Christopher Welborn

unread,
Dec 12, 2013, 6:52:33 PM12/12/13
to django...@googlegroups.com
My previous post was lengthy. I just need to find out how much memory
is being used server-side when a view is rendered. I know it's possible
to do this for regular python scripts, but I'm not sure how to measure
my Django site. Django 1.6, Python 3.3, apache2, postgresql.


Any help would be much appreciated, I won't mention it again if I
don't receive an answer.

--

- Christopher Welborn <cjwe...@live.com>
http://welbornprod.com

Jonathan Baker

unread,
Dec 12, 2013, 7:19:24 PM12/12/13
to django...@googlegroups.com
Django is just Python, after all, so you can use the same approach that you would in "regular python scripts". "when a view is rendered" is a pretty vague description of what you're aiming to profile. If your start point is the request coming in to Django, and your stop point is the rendered response exiting Django, then I'd write a piece of custom middleware. If, on the other hand, you're aiming to profile a specific method of a view (like rendering a template), then you'll want to target the method itself. You could do this with a decorator if you're using FBVs, or a abstract base class if you're using CBVs. This approach is nice because you're abstracting away the profiling code which allows you to easily reuse it.

Hope this helps a little,
JDB


--
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...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/l8di7q%24ig8%241%40ger.gmane.org.
For more options, visit https://groups.google.com/groups/opt_out.



--
Jonathan D. Baker
Developer
http://jonathandbaker.com

Christopher Welborn

unread,
Dec 12, 2013, 10:08:19 PM12/12/13
to django...@googlegroups.com
On 12/12/2013 06:19 PM, Jonathan Baker wrote:
> Django is just Python, after all, so you can use the same approach that
> you would in "regular python scripts". "when a view is rendered" is a
> pretty vague description of what you're aiming to profile. If your start
> point is the request coming in to Django, and your stop point is the
> rendered response exiting Django, then I'd write a piece of custom
> middleware. If, on the other hand, you're aiming to profile a specific
> method of a view (like rendering a template), then you'll want to target
> the method itself. You could do this with a decorator if you're using
> FBVs, or a abstract base class if you're using CBVs. This approach is
> nice because you're abstracting away the profiling code which allows you
> to easily reuse it.
>
> Hope this helps a little,
> JDB
>

> --
> Jonathan D. Baker
> Developer
> http://jonathandbaker.com
>

I appreciate your response, instead of using a lot of third-party apps
I have written everything on my site from scratch to get things
exactly the way I want them. I was actually hoping for a third-party
solution for this one, but if it takes me writing my own middleware
then thats just what I'll do. It is the whole request and response I
am trying to look at, but finer grain control would be good too.

Thanks again, I'm going to study up on middleware.

Jonathan D. Baker

unread,
Dec 12, 2013, 10:57:32 PM12/12/13
to django...@googlegroups.com
There definitely could already be middleware that accomplishes this (I've never looked). Even if you end up writing your own, I think you'll enjoy the process of grokking the django request/response cycle and seeing how powerful middleware can be.

Good luck with the task, and cheers.

Sent from my iPhone
> --
> 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 http://groups.google.com/group/django-users.
> To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/l8dtmt%241lm%241%40ger.gmane.org.
Reply all
Reply to author
Forward
0 new messages