Quick Upload

Loading...
Flash Player 9 (or above) is needed to view slideshows. We have detected that you do not have it on your computer.To install it, go here
Post to Twitter Post to Twitter
Share on Facebook
Myspace Hi5 Friendster Xanga LiveJournal Facebook Blogger Tagged Typepad Freewebs BlackPlanet gigya icons
« Prev Comments 1 - 10 of 18 Next »
  • portable
    portable said 1 week Edit Delete

    Quality are cool for slide. http://video-yoga.info

  • bernardes
    bernardes said 2 weeks Edit Delete

    André Bernardes
    Santos - SP - Brazil

    Know my Job:
    http://www.slideshare.net/bernardes/informaes-apresentvei...

    Know me:
    http://al-bernardes.sites.uol.com.br/

  • guest3b2596
  • diegojill
    diegojill said 6 months Edit Delete

    relationship advice is hard to find, but I have some: http://relationshipsadvice.vox.com/

  • andypiper
    andypiper said 7 months Edit Delete

    lmao :-)

  • andypiper
    andypiper said 7 months Edit Delete

    lmao :-)

  • landrew
    landrew said 8 months Edit Delete

    love this presentation!

  • thrashr888
    thrashr888 said 8 months Edit Delete

    what does that do?

  • Georgio_1999
  • Blaine
    Blaine said 2 years Edit Delete

    We didn't use them at first, but should have. :-)

  • richardfriedman
    richardfriedman said 2 years Edit Delete

    Slide 15: Don't be like us. What was that referring to ? Did you use those things? Not use those things at first?

  • Blaine
    Blaine said 2 years Edit Delete

    The difficulty is that the carriers that allow their customers to recharge prepaid cards take our money to do so; in effect, Twitter (and any other service that offers free delivery of SMS messages) becomes a source of free money. It's inherently unsustainable.

    More generally, the point of this slide was that it's not a good scaling practice to allow 'abusive' users to undermine continued access to 'legitimate' users (and that the definition of both of those terms is subject to your own particular situation).

    There's always room for creativity - until we're able to deal directly with Italian carriers to ensure that we don't act as a prepaid card refill service, Italian users are able to send messages via SMS, and are able to receive messages via AIM or the Mobile Web (and soon Email as well).

  • nicolamattina
    nicolamattina said 2 years Edit Delete

    I do not understand what do you mean with The Italians! This slide only shows people willing to recieve updates from a lot of friends: we are a very social country :-D
    Maybe, you should do some research before launching a service globally: you cannot blame people who use services in new creative ways (in this case to recharge the prepaid card ;-)

  • vishwa
    vishwa said 2 years Edit Delete

    Pretty decent pointers on scaling a RoR app

  • spiderweb99
    spiderweb99 said 2 years Edit Delete

    WOW !!! That was MIND BLOWING !!!

  • Klondike
    Klondike said 2 years Edit Delete

    THIS PUZZLE BOX IS FULL OF GLUE

  • bgreenlee
    bgreenlee said 2 years Edit Delete

    Actually, if you're using MySQL, keep in mind that it never uses more than one index per table, so if you're always selecting on two or more columns in a certain table, you're better off having a single multi-column index.

  • jboutelle
    jboutelle said 2 years Edit Delete

    Blain,

    This talk was extremely useful! I had a good chat with the other flicker guys that were at the SVRC, and got some killer ideas for how to speed up slideshare (short version: I think we have way too much code in our templates).

    I was the guy in the back asking all the questions. ;->

    -Jon

Add a comment If you have a SlideShare account, login to comment; otherwise comment as a guest.

    Scaling Twitter

    from Blaine, 2 years ago Add as contact

    76277 views | 18 comments | 204 favorites | 72 embeds (Stats)

    Desc: Scaling Twitter - Slides for a talk presented at the SDForum Silicon Valley Ruby Conference 2007 on Twitter's challenges scaling Rails.

    Embed customize close
     

    More Info

    This slideshow is Public

    Views: 76277 Comments: 18 Favorites: 204 Downloads: 3158

    View Details: 74423 on Slideshare 1854 from embeds
    All Embeds: Less
    Flagged as inappropriate Flag as inappropriate

    Flag as inappropriate

    Select your reason for flagging this slideshow as inappropriate.

    If needed, use the feedback form to let us know more details.

    Slideshow Transcript

    1. Slide 1: Big Bird. (scaling twitter)
    2. Slide 2: Rails Scales. (but not out of the box)
    3. Slide 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. Slide 7: Joy Pain Oct Nov Dec Jan Feb March Apr
    5. Slide 8: IM IN UR RAILZ MAKIN EM GO FAST
    6. Slide 9: 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. Slide 10: 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. Slide 11: the more you know { Part the First }
    9. Slide 12: We Failed at This.
    10. Slide 13: Don’t Be Like Us • Munin • Nagios • AWStats & Google Analytics • Exception Notifier / Exception Logger • Immediately add reporting to track problems.
    11. Slide 14: 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. Slide 15: <!-- 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. Slide 16: The Database { Part the Second }
    14. Slide 17: “The Next Application I Build is Going to Be Easily Partitionable” - S. Butterfield
    15. Slide 18: “The Next Application I Build is Going to Be Easily Partitionable” - S. Butterfield
    16. Slide 19: “The Next Application I Build is Going to Be Easily Partitionable” - S. Butterfield
    17. Slide 20: Too Late.
    18. Slide 21: Index Everything
    19. Slide 22: 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. Slide 23: Denormalize A Lot
    21. Slide 24: 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. Slide 25: 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. Slide 26: Don’t be Stupid
    24. Slide 27: bob.friends.map(&:email) Status.count() “email like ‘%#{search}%’”
    25. Slide 28: 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. Slide 29: Partitioning Comes Later. (we’ll let you know how it goes)
    27. Slide 30: The Cache { Part the Third }
    28. Slide 31: MemCache
    29. Slide 32: MemCache
    30. Slide 33: MemCache
    31. Slide 34: !
    32. Slide 35: 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. Slide 36: 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. Slide 37: The Future ve d ti r co Ac e R
    35. Slide 38: 90% API Requests Cache Them!
    36. Slide 39: “There are only two hard things in CS: cache invalidation and naming things.” – Phil Karlton, via Tim Bray
    37. Slide 40: Messaging { Part the Fourth }
    38. Slide 41: You Already Knew All That Other Stuff, Right?
    39. Slide 42: Producer Consumer Message Producer Consumer Queue Producer Consumer
    40. Slide 43: DRb • The Good: • Stupid Easy • Reasonably Fast • The Bad: • Kinda Flaky • Zero Redundancy • Tightly Coupled
    41. Slide 44: ejabberd Jabber Client (drb) Incoming Outgoing Presence Messages Messages MySQL
    42. Slide 45: Server DRb.start_service ‘druby://localhost:10000’, myobject Client myobject = DRbObject.new_with_uri(‘druby://localhost:10000’)
    43. Slide 46: Rinda • Shared Queue (TupleSpace) • Built with DRb • RingyDingy makes it stupid easy • See Eric Hodel’s documentation • O(N) for take(). Sigh.
    44. Slide 47: 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. Slide 48: It Scales. (except it stopped on Tuesday)
    46. Slide 49: Options • ActiveMQ (Java) • RabbitMQ (erlang) • MySQL + Lightweight Locking • Something Else?
    47. Slide 50: erlang? What are you doing? Stabbing my eyes out with a fork.
    48. Slide 51: Starling • Ruby, will be ported to something faster • 4000 transactional msgs/s • First pass written in 4 hours • Speaks MemCache (set, get)
    49. Slide 52: Use Messages to Invalidate Cache (it’s really not that hard)
    50. Slide 53: Abuse { Part the Fifth }
    51. Slide 54: The Italians
    52. Slide 55: 9000 friends in 24 hours (doesn’t scale)
    53. Slide 56: 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/