Comments on: Django performance testing – a real world example http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/ Code and comments on web development, Django, Python and things (un)related. Wed, 03 Apr 2013 13:15:20 +0000 hourly 1 http://wordpress.org/?v=4.3 By: Maciej Zaleski http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/comment-page-1/#comment-1018 Thu, 14 Apr 2011 12:24:32 +0000 http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/#comment-1018 Very good post. I’m going to have a look at httperf, never heard about it before.

As for the vmstat command I would recommend running it within a scree so that it will still run even if the ssh connection to the server is closed. This might prove very useful for longer tests.

Also adding -n will stop the vmstat headers from being reprented

screen vmstat -n 2

To leave the screen use Ctrl+a Ctrl+d and to return to it use screen -r

]]>
By: Jan Paricka http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/comment-page-1/#comment-770 Wed, 27 Jan 2010 12:36:33 +0000 http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/#comment-770 Oh, boy. Easily half a gig per httpd process.. Anyone have seen this before? http://twitpic.com/zzem4 Great article, btw. Thanks for putting it together.

]]>
By: Scott http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/comment-page-1/#comment-630 Sat, 17 Jan 2009 22:06:51 +0000 http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/#comment-630 @SJS

Sorry, I don’t have any experience using this. The authentication I used was faked by setting the cookie header to a known value. In your case, httperf is handling sessions by itself – receiving a cookie and sending it on subsequent requests.

]]>
By: SJS http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/comment-page-1/#comment-627 Fri, 16 Jan 2009 02:26:08 +0000 http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/#comment-627 Could you please explain bit more about ‘authenticated requests with httperf’. I am wondering about the format of my session file with the POST data. The site I am trying to log in have a one cookie. Two different urls in the same session ends us receiving two different vales for the cookie though I use –session-cookie with –wsesslog option.Thx

]]>
By: Sephi http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/comment-page-1/#comment-419 Mon, 08 Sep 2008 09:18:03 +0000 http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/#comment-419 First check if you can reduce the number of queries executed (using this snippet for example : http://www.djangosnippets.org/snippets/93/), then profile them using the SQL EXPLAIN statement (not sure if it’s a standard one though, but it works on MySQL). With this, you’ll be able to identify “greedy” queries and try to optimize them by, for example, setting indexes on the right columns.

And if your indexes are already good, cache the objects for which queries are the most expensive. You could also check your my.cnf values and try to tune it, but 256Mb of RAM is a bit short…

Nice article though !

]]>
By: Scott http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/comment-page-1/#comment-194 Tue, 29 Apr 2008 15:00:55 +0000 http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/#comment-194 @S.

Thanks for the suggestion to disable keep-alive for the dynamic content. I tried it, but it seems to have made no difference.

The Lighttpd docs refer to disabling keep-alive as “the last resort”. Reducing the requests and idle time from the defaults didn’t seem to make a difference either.

@jeo

We’re old SQL hounds, so we know all about joins and unions. :)

A wall has multiple items. Each item is sent by a user and can have several pieces of media (e.g. photos).

The initial/naive approach was one query (through normal Django ORM) for the wall then in the template something like:

{% for item in wall.items.all %}

{% with item.sender as sender %}
{{ sender.name }} etc…
{% endwith %}

{% for media in item.media.all %}

{% endfor %}

{% endfor %}

I would say this is pretty standard — it’s the easy, natural way to work with the ORM. Of course, it means we are doing one query for the items and then two queries for each item, which is bad news. In some cases, select_related() will help, but not in this case as we had some nullable foreign keys.

This can be done far more efficiently, as you say, by joining the tables, or doing a couple of queries and stitching the data together in Python. That’s what we did during optimisation.

@Vance

The point of newforms and ORM and all this stuff is to make it easier/quicker to develop and maintain. There’s obviously a big performance trade-off. I totally agree with you that Django makes it easy to drop down a level when you want to trade ease for performance.

@Doug

Thanks for sharing some numbers for the PyCon website. What’s the hardware spec of the server?

Hundreds of req/s is certainly more appealing. We are using values() now to avoid lots of queries, but no caching yet.

When you benchmarked at 800 req/s, did your test make requests as multiple users? It occurs to me that caching could be misleading when testing performance since one user making 800 requests is very different from 800 users making one request each!

I might have a play with mod_wsgi at some point — looks interesting.

]]>
By: sean http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/comment-page-1/#comment-193 Tue, 29 Apr 2008 04:33:46 +0000 http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/#comment-193 i’ve done some similar test around Django, and the database ORM seems to be the bottle neck to me…

]]>
By: Doug Napoleone http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/comment-page-1/#comment-192 Tue, 29 Apr 2008 04:15:06 +0000 http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/#comment-192 Wow, that is bad performance even after tuning.
the PyCon website can handle about 800 requests per second (all highly personalized w/ login and custom navbar). Sounds like you are not using select_related, values, and sub template caching.

I also recommend using mod_wsgi in deamon mode instead of fastcgi, using file based session caching, and memcached.

looking at the site, I see no reason why you should not be able to do 1000 requests per second.

]]>
By: Joe http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/comment-page-1/#comment-190 Tue, 29 Apr 2008 02:25:03 +0000 http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/#comment-190 Really nice article walking through the performance evaluation of your site! Nice work, and thanks for posting it so others can do the same for themselves!

]]>
By: Vance Dubberly http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/comment-page-1/#comment-189 Mon, 28 Apr 2008 23:15:31 +0000 http://scottbarnham.com/blog/2008/04/28/django-performance-testing-a-real-world-example/#comment-189 That is insanely bad performance, though ultimately it may be “Good” enough. I often think people don’t realize the trade offs they make when using frameworks like Django and Rails. Resource and performance wise it’s like moving back into the days of CGI. Forget RAM, forget concurrency, and learn to buy big boxes . Literally if you want to see your performance increase 10x, drop the framework.

Personally I’ve taken to using a hybrid approach, use some of the framework and hand code alot. For instance lose newforms entirely it’s an amazing waste of memory and cpu cycles ( still can’t figure out why it exists ), don’t use Models on any queries that happen alot, if you do use Models use ‘select_all’, QuerySet is the devil when it comes to speed.

One of the most beautiful things about Django is that you can subvert Django when you need to and go straight to the underlying tools.

]]>