Scaling Twitter

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

30 comments

Comments 1 - 10 of 30 previous next Post a comment

Comments 1 - 10 of 30 previous next

Post a comment
Embed Video
Edit your comment Cancel

262 Favorites & 7 Groups

Scaling Twitter - Presentation Transcript

  1. Big Bird. (scaling twitter)
  2. Rails Scales. (but not out of the box)
  3. First, Some Facts • 600 requests per second. Growing fast. • 180 Rails Instances (Mongrel). Growing fast. • 1 Database Server (MySQL) + 1 Slave. • 30-odd Processes for Misc. Jobs • 8 Sun X4100s • Many users, many updates.
  4. Joy Pain Oct Nov Dec Jan Feb March Apr
  5. IM IN UR RAILZ MAKIN EM GO FAST
  6. It’s Easy, Really. 1. Realize Your Site is Slow 2. Optimize the Database 3. Cache the Hell out of Everything 4. Scale Messaging 5. Deal With Abuse
  7. It’s Easy, Really. 1. Realize Your Site is Slow 2. Optimize the Database 3. Cache the Hell out of Everything 4. Scale Messaging 5. Deal With Abuse 6. Profit
  8. the more you know { Part the First }
  9. We Failed at This.
  10. Don’t Be Like Us • Munin • Nagios • AWStats & Google Analytics • Exception Notifier / Exception Logger • Immediately add reporting to track problems.
  11. Test Everything • Start Before You Start • No Need To Be Fancy • Tests Will Save Your Life • Agile Becomes Important When Your Site Is Down
  12. <!-- served to you through a copper wire by sampaati at 22 Apr 15:02 in 343 ms (d 102 / r 217). thank you, come again. --> <!-- served to you through a copper wire by kolea.twitter.com at 22 Apr 15:02 in 235 ms (d 87 / r 130). thank you, come again. --> <!-- served to you through a copper wire by raven.twitter.com at 22 Apr 15:01 in 450 ms (d 96 / r 337). thank you, come again. --> Benchmarks? let your users do it. <!-- served to you through a copper wire by kolea.twitter.com at 22 Apr 15:00 in 409 ms (d 88 / r 307). thank you, come again. --> <!-- served to you through a copper wire by firebird at 22 Apr 15:03 in 2094 ms (d 643 / r 1445). thank you, come again. --> <!-- served to you through a copper wire by quetzal at 22 Apr 15:01 in 384 ms (d 70 / r 297). thank you, come again. -->
  13. The Database { Part the Second }
  14. “The Next Application I Build is Going to Be Easily Partitionable” - S. Butterfield
  15. “The Next Application I Build is Going to Be Easily Partitionable” - S. Butterfield
  16. “The Next Application I Build is Going to Be Easily Partitionable” - S. Butterfield
  17. Too Late.
  18. Index Everything
  19. class AddIndex < ActiveRecord::Migration def self.up add_index :users, :email end def self.down remove_index :users, :email end end Repeat for any column that appears in a WHERE clause Rails won’t do this for you.
  20. Denormalize A Lot
  21. class DenormalizeFriendsIds < ActiveRecord::Migration def self.up add_column "users", "friends_ids", :text end def self.down remove_column "users", "friends_ids" end end
  22. class Friendship < ActiveRecord::Base belongs_to :user belongs_to :friend after_create :add_to_denormalized_friends after_destroy :remove_from_denormalized_friends def add_to_denormalized_friends user.friends_ids << friend.id user.friends_ids.uniq! user.save_without_validation end def remove_from_denormalized_friends user.friends_ids.delete(friend.id) user.save_without_validation end end
  23. Don’t be Stupid
  24. bob.friends.map(&:email) Status.count() “email like ‘%#{search}%’”
  25. That’s where we are. Seriously. If your Rails application is doing anything more complex than that, you’re doing something wrong*. * or you observed the First Rule of Butterfield.
  26. Partitioning Comes Later. (we’ll let you know how it goes)
  27. The Cache { Part the Third }
  28. MemCache
  29. MemCache
  30. MemCache
  31. !
  32. class Status < ActiveRecord::Base class << self def count_with_memcache(*args) return count_without_memcache unless args.empty? count = CACHE.get(“status_count”) if count.nil? count = count_without_memcache CACHE.set(“status_count”, count) end count end alias_method_chain :count, :memcache end after_create :increment_memcache_count after_destroy :decrement_memcache_count ... end
  33. class User < ActiveRecord::Base def friends_statuses ids = CACHE.get(“friends_statuses:#{id}”) Status.find(:all, :conditions => [“id IN (?)”, ids]) end end class Status < ActiveRecord::Base after_create :update_caches def update_caches user.friends_ids.each do |friend_id| ids = CACHE.get(“friends_statuses:#{friend_id}”) ids.pop ids.unshift(id) CACHE.set(“friends_statuses:#{friend_id}”, ids) end end end
  34. The Future ve d ti r co Ac e R
  35. 90% API Requests Cache Them!
  36. “There are only two hard things in CS: cache invalidation and naming things.” – Phil Karlton, via Tim Bray
  37. Messaging { Part the Fourth }
  38. You Already Knew All That Other Stuff, Right?
  39. Producer Consumer Message Producer Consumer Queue Producer Consumer
  40. DRb • The Good: • Stupid Easy • Reasonably Fast • The Bad: • Kinda Flaky • Zero Redundancy • Tightly Coupled
  41. ejabberd Jabber Client (drb) Incoming Outgoing Presence Messages Messages MySQL
  42. Server DRb.start_service ‘druby://localhost:10000’, myobject Client myobject = DRbObject.new_with_uri(‘druby://localhost:10000’)
  43. Rinda • Shared Queue (TupleSpace) • Built with DRb • RingyDingy makes it stupid easy • See Eric Hodel’s documentation • O(N) for take(). Sigh.
  44. Timestamp: 12/22/06 01:53:14 (4 months ago) Author: lattice Message: Fugly. Seriously. Fugly. SELECT * FROM messages WHERE substring(truncate(id,0),-2,1) = #{@fugly_dist_idx}
  45. It Scales. (except it stopped on Tuesday)
  46. Options • ActiveMQ (Java) • RabbitMQ (erlang) • MySQL + Lightweight Locking • Something Else?
  47. erlang? What are you doing? Stabbing my eyes out with a fork.
  48. Starling • Ruby, will be ported to something faster • 4000 transactional msgs/s • First pass written in 4 hours • Speaks MemCache (set, get)
  49. Use Messages to Invalidate Cache (it’s really not that hard)
  50. Abuse { Part the Fifth }
  51. The Italians
  52. 9000 friends in 24 hours (doesn’t scale)
  53. http://flickr.com/photos/heather/464504545/ http://flickr.com/photos/curiouskiwi/165229284/ http://flickr.com/photo_zoom.gne?id=42914103&size=l http://flickr.com/photos/madstillz/354596905/ http://flickr.com/photos/laughingsquid/382242677/ http://flickr.com/photos/bng/46678227/

+ BlaineBlaine, 3 years ago

custom

96909 views, 262 favs, 81 embeds more stats

Scaling Twitter - Slides for a talk presented at th more

More info about this document

© All Rights Reserved

Go to text version

  • Total Views 96909
    • 94672 on SlideShare
    • 2237 from embeds
  • Comments 30
  • Favorites 262
  • Downloads 3711
Most viewed embeds
  • 608 views on http://poorbuthappy.com
  • 316 views on http://scaleordie.com
  • 308 views on http://www.simpleentrepreneur.com
  • 252 views on http://www.jonathanboutelle.com
  • 215 views on http://www.webforth.com

more

All embeds
  • 608 views on http://poorbuthappy.com
  • 316 views on http://scaleordie.com
  • 308 views on http://www.simpleentrepreneur.com
  • 252 views on http://www.jonathanboutelle.com
  • 215 views on http://www.webforth.com
  • 162 views on http://www.datacenterknowledge.com
  • 45 views on http://www.poorbuthappy.com
  • 40 views on http://somkiatspns.blogspot.com
  • 28 views on http://scaleordie.wordpress.com
  • 25 views on http://jesperatwork.blogspot.com
  • 18 views on http://esteinar.blogspot.com
  • 17 views on http://webforth.com
  • 16 views on http://falkayn.blogspot.com
  • 16 views on http://rapd.wordpress.com
  • 15 views on http://www.netvibes.com
  • 14 views on http://www.asiermarques.com
  • 12 views on http://localhost
  • 8 views on http://headstart.in
  • 7 views on http://lj-toys.com
  • 6 views on http://sourcode.net
  • 5 views on http://www.assoce.bem.edu
  • 5 views on http://www.twitterati.tv
  • 4 views on http://webdevcampsp.ning.com
  • 4 views on http://www.webspiritus.com
  • 4 views on http://wildfire.gigya.com
  • 4 views on http://b01.telcomsoft.com
  • 3 views on http://www.lonerunners.net
  • 3 views on http://blog.macuyiko.com
  • 3 views on http://mywheel.net
  • 3 views on http://chatter.citcat.com:3002
  • 3 views on http://c17-cne-admin-bld1.cnet.com:8081
  • 3 views on http://okyuu.com
  • 2 views on http://www.cars-and-motorcycles-and-trucks.com
  • 2 views on http://www.incredibleslideshows.com
  • 2 views on http://aula.iesjaroso.es
  • 2 views on http://www.filescon.com
  • 2 views on http://datacenterknowledge.com
  • 2 views on http://startuptweet.com
  • 2 views on http://www.planetlotto.co.uk
  • 2 views on http://www.game-games-gamer.com
  • 2 views on http://gpessia.wordpress.com
  • 2 views on http://www.slideshare.net
  • 2 views on http://azam1.synthasite.com
  • 2 views on http://kaloyan.info
  • 2 views on http://www.traveltravellers.com
  • 2 views on http://a2.vox-data.com
  • 2 views on http://onlinevideogamerental.org
  • 2 views on http://mambler.net
  • 1 views on http://www.sport-xblog.com
  • 1 views on http://tutorialart.com
  • 1 views on http://74.125.39.132
  • 1 views on http://web-and-host.com
  • 1 views on http://www.filestube.com
  • 1 views on http://www.beauty-fashion-jewelry.com
  • 1 views on http://www.business1-finance1.com
  • 1 views on http://static.slidesharecdn.com
  • 1 views on http://www.marketing-xblog.com
  • 1 views on http://spf13.com
  • 1 views on https://s3.amazonaws.com
  • 1 views on http://longevitygenetics.com
  • 1 views on http://www.bidderdirectory.com
  • 1 views on http://www.newsss.com
  • 1 views on http://www.camillejourdain.fr
  • 1 views on http://feeds.feedburner.com
  • 1 views on http://www.erwinblom.nl
  • 1 views on http://www.egostrippen.nl
  • 1 views on http://www.maitrella.com
  • 1 views on http://twiki.corp.yahoo.com
  • 1 views on https://webvpn.techtarget.com
  • 1 views on http://www.njwebworks.com
  • 1 views on http://www.marketingfacts.nl
  • 1 views on http://209.85.173.104
  • 1 views on http://www.moviecern.com
  • 1 views on http://www.o53.net
  • 1 views on http://static.slideshare.net
  • 1 views on http://railsandruby.blogspot.com
  • 1 views on http://64.233.183.104
  • 1 views on http://jazaruma.iwebutpl.com
  • 1 views on http://staging.askmego.com
  • 1 views on http://www.twitteritaly.com
  • 1 views on http://km2factory.sud.capgemini.fr

less

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

Cancel
File a copyright complaint
Having problems? Go to our helpdesk?

Categories