Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

ScaleFail

2,384 views

Published on

A 5 minute presentation for UK ScaleCamp 2009

  • Be the first to comment

  • Be the first to like this

ScaleFail

  1. 1. ScaleFail(and MPs’ expenses)
  2. 2. Copyright © Steve Bell 2009
  3. 3. How we built it
  4. 4. Crash #1: moreApache children thanMySQL connections
  5. 5. unreviewed_count = Page.objects.filter( votes__isnull = True).distinct().count()
  6. 6. SELECT COUNT(DISTINCT `expenses_page`.`id`)FROM `expenses_page` LEFT OUTER JOIN `expenses_vote` ON ( `expenses_page`.`id` = `expenses_vote`.`page_id` ) WHERE `expenses_vote`.`id` IS NULL
  7. 7. unreviewed_count = cache.get(homepage:unreviewed_count)if unreviewed_count is None: unreviewed_count = Page.objects.filter( votes__isnull = True ).distinct().count() cache.set(homepage: unreviewed_count, unreviewed_count, 60)
  8. 8. • With 70,000 pages and a LOT of votes... • DB takes up 135% of CPU• Cache the count in memcached... • DB drops to %35 of CPU
  9. 9. unreviewed_count = Page.objects.filter( votes__isnull = True).distinct().count()reviewed_count = Page.objects.filter( votes__isnull = False).distinct().count()
  10. 10. unreviewed_count = Page.objects.filter( is_reviewed = False).count()
  11. 11. Migrating to InnoDBon a separate server
  12. 12. ssh mps-live "mysqldump mp_expenses" |sed s/ENGINE=MyISAM/ENGINE=InnoDB/g | sed s/CHARSET=latin1/CHARSET=utf8/g | ssh mysql-big "mysql -u root mp_expenses"
  13. 13. “next” button
  14. 14. def next_global(request): # Next unreviewed page from the whole site all_unreviewed_pages = Page.objects.filter( is_reviewed = False ).order_by(?) if all_unreviewed_pages: return Redirect( all_unreviewed_pages[0].get_absolute_url() ) else: return HttpResponse( All pages have been reviewed! )
  15. 15. def next_global(request): # Next unreviewed page from the whole site all_unreviewed_pages = Page.objects.filter( is_reviewed = False ).order_by(?) if all_unreviewed_pages: return Redirect( all_unreviewed_pages[0].get_absolute_url() ) else: return HttpResponse( All pages have been reviewed! )
  16. 16. import randomdef next_global_from_cache(request): page_ids = cache.get(unreviewed_page_ids) if page_ids: return Redirect( /page/%s/ % random.choice(page_ids) ) else: return next_global(request)
  17. 17. Next time, I’ll use redis
  18. 18. Read-only modesaved our bacon
  19. 19. Copyright © Martin Rowson 2008

×