Djangocon: two short talks about django-oscar and about performance gains

Tags: djangocon, django

(One of the summaries of a talk at 2014 djangocon.eu)

An introduction to django-oscar - David Winterbottom

David Winterbottom is, which I just now noticed, the originator of the very useful www.commandlinefu.com website that I’ve had in in my RSS reader for the past few years. Recommended: you get a useful tip out of it every month or so.

More related to django: he’s the author of the e-commerce framework ‘django-oscar’. In e-commerce, especially B2B (business to business), you get loads and loads of exceptions. He originally worked on a PHP system that basically broke down under all those exceptions to the standard rules.

He now works on django-oscar, which is used by a number of very large customers. Ecommerce: products, baskets, orders. Overridable apps. It could be added to your site without modifying anything: it won’t take over your whole site. It doesn’t use the django admin though, but a custom edit site.

Philosophically, oscar isn’t an out-of-the box product. It is a generic product, so it cannot know how your tax system works. Which payment provider you use, How you’ve handled shipping. So you’ll have to add that yourself. Oscar provides a base platform you can build upon.

He started it to make his life easier. The goal was to build complex but maintainable e-commerce sites.

He comments that having small kids is perfect for programming. Walking around with a kid-that-won’t-go-to-sleep for three hours gives you lots of time to think away from the keyboard about what you’re going to program. We often grab for the keyboard way too quickly!

Extensibility: you could work with pluggable strategies. Pluggable tax calculations. Per-customer pricing. Multi-currency and multi-territory shops.

With the replaceable user model in django, django uses a get_user_model() function to get to the user model. They took this a “bit” further by adding get_model() and get_class(). This way you can always customize things: simply provide a new model or class with a proper name. If not found, oscar falls back to oscar’s default one.

(Personal note: sounds a bit like a custom partial version of Zope’s component architecture or the much simpler Reg).

Oscar is for people with difficult e-commerce problems.

The roadmap? See an article on his site.

Frequently missed performance gains - Frank Wiles

Frank Wiles talks about things he sees as a consultant: small easy changes that can make a huge difference. As an illustration, he made a sample app and filled it with quite a lot of data to get some proper measurements out of it.

Measurements were made with siege A baseline check was between DEBUG=TRUE and DEBUG=False, the difference was 17 versus 120 requests per second.

  • You can tell django to cache templates. The cached loader gave 140 instead of 120/second.

  • Cached sessions: normally every request means a database hit to get your session. Normally the session isn’t even really used to store data. You can get them from the cache just fine in those cases. No need to store empty unused sessions, right?

    He set SESSION_ENGINE to the cached version and this one configuration line changes got him from 120 to 155 req/sec.

  • Since django 1.6, cached database connections are easy to use. The default is off, so set CONN_MAX_AGE to some value and you can get 25% performance gains.

  • Are you using all of your machine? How many cores do you have? How many gunicorn processes do you have? Or do you have too many processes? 2 processes on an 8 core machine doesn’t utilize it fully. 16 processes on an 8 core machine hoses it.

  • You can often optimize other things than django. nginx for instance:

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    types_hash_max_size 2048;
    server_tokens off;

    This was another 13% improvement!

  • Combine CSS and JS. Not doing it costs so much time. With many css/js files, half a second per page is typical. Use django-compressor or django-pipeline for instance.

  • What also really really helps: far future expire headers on your static files. Note: it doesn’t actually have to be that far in the future. 5 minutes is often enough. Most people only look at your site for a few minutes at most, right?

Why would you go through the effort? It could save you 10% in hosting costs. But perhaps that doesn’t convince you. So: do it for django. Optimize even your own small blog. Sites made with django should be speedy!

blog comments powered by Disqus
 
vanrees.org logo

About me

My name is Reinout van Rees and I work a lot with Python (programming language) and Django (website framework). I live in The Netherlands and I'm happily married to Annie van Rees-Kooiman.

Weblog feeds

Most of my website content is in my weblog. You can keep up to date by subscribing to the automatic feeds (for instance with Google reader):