Scaling Rails for Melbourne RORO

38
SCALING RAILS A topic no longer as amusingly controversial as when I first started speaking on the topic, but Twitter does still have the odd lolz (ha ha, scala!)

description

A talk I gave at the August meeting of the Melbourne RORO group on scaling a rails application. It's a quick overview of what I think you need to do early in the life of a rails app to be ready for scale further down the road. Read http://jrb.tumblr.com/post/30570014929/scaling-rails-at-melbourne-roro to add more context to the slides.

Transcript of Scaling Rails for Melbourne RORO

Page 1: Scaling Rails for Melbourne RORO

SCALING RAILS

A topic no longer as amusingly controversial as when I first started speaking on the topic, but Twitter does still have the odd lolz (ha ha, scala!)

Page 3: Scaling Rails for Melbourne RORO

Why me?

Because shut up, that’s why.

Page 4: Scaling Rails for Melbourne RORO

Because the Envato Marketplaces are really big in

traffic and workload...

Page 5: Scaling Rails for Melbourne RORO

... and I helped make the computer machines do that

At a point in time where people thought Rails couldn’t do that because Twitter crashed a lot and that’s all people thought of when they said “Big Rails”

Page 6: Scaling Rails for Melbourne RORO

50 Million Dynamic Requests a week when I left

or 80ish requests a second

Page 7: Scaling Rails for Melbourne RORO

Before that I did loads of performance work at

MyCareer.com.au

Page 8: Scaling Rails for Melbourne RORO

After that I’m building ROFL scale social network thingo.

You know, for movies.

Go sign up at http://goodfil.ms, so I don’t get rusty at web scale.

Page 9: Scaling Rails for Melbourne RORO

There is a risk of me veering into my grand theory of software

development and the universe and everything.

Page 10: Scaling Rails for Melbourne RORO

What does “Scaling Rails” mean?

Page 11: Scaling Rails for Melbourne RORO

Predictably serving more customers (with your rails app)

next week/month/year than you have right now

Page 12: Scaling Rails for Melbourne RORO

It’s a game of tradeoffs

Cost vs. Performance vs. Reliability vs. Flexibility

Page 13: Scaling Rails for Melbourne RORO

“Complex systems that work evolve from simple systems that

work”

Page 14: Scaling Rails for Melbourne RORO

Growing a stack for scale is a similar exercise in managing

complexity as a growing codebase and you can use the

same mental models

Page 15: Scaling Rails for Melbourne RORO

Coupling is the #1 enemy and beating it is an elaborate game

of divide and conquer

Page 16: Scaling Rails for Melbourne RORO

Anyway, so some concrete things about Rails

I can save the hand-wavy stuff for a devops meetup

Page 17: Scaling Rails for Melbourne RORO

Step #0Measure everything you can

afford to measure

I would hope that goes without saying.New Relic and Scout are my favourite tools for that.

Page 18: Scaling Rails for Melbourne RORO

Step #0.5Actually check up on what you

are measuring

And learn how to interpret that data correctly (read books).

Page 19: Scaling Rails for Melbourne RORO

Step #1YAGNI

You Aint Gonna Need it (with caveats - you need a wee safety buffer)

Page 20: Scaling Rails for Melbourne RORO

Know your end game

Based on what kind of app you are working on.

Social Network, Online News, Ecommerce all have different work loads and optimal stacks. There is no one size fits all stack at the pointy end.

Page 21: Scaling Rails for Melbourne RORO

Know your techniques

You need to know how to get yourself out of trouble when your metrics say that you are in it. I will give a reading list for that the end.

Page 22: Scaling Rails for Melbourne RORO

Then you fake it till you make it

Page 23: Scaling Rails for Melbourne RORO

Deploy to the cloud

Probably Rackspace or Amazon,Heroku if you are lazy and rich

Page 24: Scaling Rails for Melbourne RORO

Avoid vendor lock in for the full stack

But it can be OK for smaller independent components. You will want to move hosting companies in your future. Probably more than once.

Page 25: Scaling Rails for Melbourne RORO

JB’s Golden Mini Stack

one “magic vendor cloud load balancer” + 2 app servers + one datastore + frequent backups

Page 26: Scaling Rails for Melbourne RORO

Rent the high memory instances for app servers

it’s almost invariably the limiting factor

Page 27: Scaling Rails for Melbourne RORO

Stick with SQL

Rails tooling is heavily biased that way and you will get the most stuff for free.

Page 28: Scaling Rails for Melbourne RORO

IT DOES NOT MATTER IF YOU CHOOSE MYSQL OR

POSTGRESQL BOTH WORKFINE AND BOTH SCALE

Page 29: Scaling Rails for Melbourne RORO

Use DB backed queues...

delayed_job or roll your ownDBAs will roll their eyes at this

Page 30: Scaling Rails for Melbourne RORO

... for the short to mid term

it is a simpler “whole stack” at the expense of doing things right

Page 31: Scaling Rails for Melbourne RORO

Put job queue workers on your app slices...

...in direct proportion to the amount of jobs your web processes can make. If each “app” box can do all of the ruby work for N number of requests, you can

keep adding boxes until your database explodes.

Page 32: Scaling Rails for Melbourne RORO

Then build a brand spanking “job system”

With Redis and whatever else magic job shit you want, and dedicated machines to working off that queue, and probably split your codebase too.

Page 33: Scaling Rails for Melbourne RORO

Caching is your get out of jail free card

Page 34: Scaling Rails for Melbourne RORO

Be careful, it can hide genuine performance problems

and once caching runs out... you are well and truly cooked

Page 35: Scaling Rails for Melbourne RORO

YMMV

“I hate to advocate drugs, alcohol, violence, or insanity to anyone, but they’ve always worked for me”