Advertisement
Advertisement

More Related Content

Advertisement

Recently uploaded(20)

High Availability Django - Djangocon 2016

  1. High-Availability Django Frankie Dintino The Atlantic
  2. Performance woes…
  3. …and crises
  4. Today
  5. First steps • Monitoring and profiling: understand your bottlenecks • Tackle the “easy” stuff first: query optimization, caching • Don’t neglect front-end performance
  6. Profiling • Hosted services: New Relic, Opbeat • django-debug-toolbar, django-silk • cProfile / pyprof2calltree / KCacheGrind for masochists • WSGI middleware
  7. Monitoring • Downtime notifications: Alertra, New Relic, Opbeat, Chartbeat • Nagios and its many forks, Zabbix
  8. Caching • Use a CDN • Proxy cache (Nginx, Squid, Varnish) • {% cache %}, @cached_property, CachedStaticFilesStorage, cached template loader • Page caching frameworks • ORM caching: a mixed bag
  9. Query optimization • .prefetch_related(), .select_related() • prefetch_related_objects() for generic foreign keys • .values() and .values_list() where it counts, if possible • Database parameter tuning, judicious indexing
  10. Throwing more hardware at the problem also works.
  11. “Request Queuing?”
  12. “Request Queuing?”
  13. theatlantic :4000 citylab :5000 admin :6000 :80
  14. upstream theatlantic { server apps1:4000; server apps2:4000; server apps3:4000; } upstream citylab { server apps1:5000; # ... }
  15. upstream theatlantic_stage { server apps1:4500; server apps2:4500; server apps3:4500; } upstream citylab_stage { server apps1:5500; # ... }
  16. /www/site/ stage/ live/ a/ b/
  17. /www/site/ stage/ live/ a/ b/
  18. Basic principles • “a” and “b” repositories are always “production- ready.” • Force as much Django code to load as possible before defining def application() in your WSGI file. • Before swapping the upstreams, “warm up” the workers with concurrent HTTP requests.
  19. mod_wsgi vs. uWSGI
  20. mod_wsgi • In general, comparable performance • Runs on Apache HTTP server • Mostly the work of a single developer • Documentation terminally out-of-date • Important configuration options missing or only discoverable in the release notes
  21. uWSGI • Broad and active community • Very thorough documentation (overwhelming, in fact) • Highly configurable
  22. github.com/hadjango @frankiedintino frankie@theatlantic.com
  23. High-Availability Django
Advertisement