DjangoCon 2015

Escalando una aplicación e-commerce con Django

Nate Pinchot  · 




Extracto de la transcripción automática del vídeo realizada por YouTube.

thank you all for coming so my name is Nate pincha and this talk is ecommerce with Django at scale effective performance lessons learned so I'm going to take you through some of the things we learned while building our e-commerce site at undercover tourist

I've got four topics for you database read replicas and failover data caching strategy to pass rendering with class-based views and migration rules go a lot to cover and just a little bit of time so we're going to go quickly first up we have database

read replicas and failover I'm going to show you how we can implement a simple custom database back-end that allows for read replica failover so why do we need read replicas and why are they important hey one of the easiest ways to scale your database

read operations of course there are other options shouting partitioning and if you have tons of money you can just pay Oracle and everything will magically work so what can we get out of the box let's take a look before we implement a custom database back-end

Django has a functional example in their documentation and you can use it as a great starting point for getting read replicas working you can get up and running quickly by adding your read replicas to the databases setting and by using Django's built in

database routers so this is a quick example of and it's taken from the documentation it's extremely simple and straightforward you may have seen this before if you haven't please go check out Jacobs documentation it's great there is a problem

with this implementation though and it could be kind of a big one there's no support for failover so just because you have read replicas doesn't mean you'll have a hundred percent up time or you'll have a hundred percent up time for your site

because one of them goes down some of your queries might fail read replicas are used for scaling but they can also be a great fault tolerance mechanism so if one of you read replicas were to go down some of the people visit your site who could have been potential

customers are now going to see an error page at best or a loading bar until a connection timeout at worst and either way you're going to end up losing potential customers so let's go through the implementation I should note that this read replica database

back-end is only for Django's ORM and not for third party or Em's like sqlalchemy and I'm also going to be referencing my sequel here but this should also work for postgres before we look at the code I'm going to warn you that this is using

monkey patching in order to accomplish failing over from read replica connection errors why well we don't really need to but it's the most reasonable option the other choice would be to implement a full database back-end either way the best way I've

found it possible to recover from a database connection failure is inside the database back-end unfortunately there's no way in a database router to handle a connection error also Django unfortunately stores references to the database on private properties

of the ORM instance objects and these references are used in multiple places whenever Django needs to reconnect to the database so the best place to recover from a database connection failure is inside the database back-end this is an overview of the code

we're going to use to implement our backend and let's walk through it so in order for Django to recognize her back in we need to implement the database wrapper class since we're piggybacking off Django's implementation we can just import it

and use it like it's our own next we need a reference to the get new connection method so we can call it whenever our custom method is called after we've stored a reference to the original method we can overwrite it with our custom method that handles

[ ... ]

Nota: se han omitido las otras 1.953 palabras de la transcripción completa para cumplir con las normas de «uso razonable» de YouTube.