Top Banner
How to build a state-of-the-art rails cluster Tim Lossen Infopark AG, Berlin
53

How to build a state-of-the-art rails cluster

Aug 17, 2014

Download

Economy & Finance

Tim Lossen

presented at 'ostrava on rails' on 2007-06-22. there exists also a video recording:

http://www.rails.cz/articles/2007/06/27/oor-videos
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: How to build a state-of-the-art rails cluster

How to build a state-of-the-art

rails cluster

Tim LossenInfopark AG, Berlin

Page 2: How to build a state-of-the-art rails cluster

You mean ...like this?

Page 3: How to build a state-of-the-art rails cluster

System X

• Virginia Tech

• 1100 x Apple XServe G5

• 2 CPUs each (2,3 GHz)

• Infiniband network

• 12 Teraflops

Page 4: How to build a state-of-the-art rails cluster

How to build a state-of-the-art

rails cluster for 100.000 Koruny

Tim LossenInfopark AG, Berlin

Page 5: How to build a state-of-the-art rails cluster

100.000 Koruny=

4700 $=

3500 €

Page 6: How to build a state-of-the-art rails cluster

• Evolving a cluster setup

• Scaling

• Make or buy?

• Discussion

Page 7: How to build a state-of-the-art rails cluster

• performance

• efficiency

• availability

• scalability

Aims

Page 8: How to build a state-of-the-art rails cluster

Performance

• pages / second

• throughput

• 10 Mbit connection = max. about 1 million unique page impressions per day

Page 9: How to build a state-of-the-art rails cluster

Efficiency

• bang per buck

• bang per watt

Page 10: How to build a state-of-the-art rails cluster

Availability

• uptime

• can be expressed in ‚nines‘

• 99% (2 nines) = max. 100 minutes downtime per week

• 99,9999% (6 nines) = max. 0,6 seconds downtime per week

Page 11: How to build a state-of-the-art rails cluster

Scalability

• grow (or shrink) app as needed

• ideal: linear with number of machines

Page 12: How to build a state-of-the-art rails cluster

Setup 1

Page 13: How to build a state-of-the-art rails cluster

Example software

• nginx

• mongrel cluster

• mysql

Page 14: How to build a state-of-the-art rails cluster

Ideas

• put everything on one machine

• use top quality hardware

• go for high processor speed

Page 15: How to build a state-of-the-art rails cluster

Example hardware

• Sun Fire X2200 M2

• 2 x Opteron 2220 (dual core / 2,8 GHz)

• 4 GB ram

• 250 GB disk

• 3290 €

Page 16: How to build a state-of-the-art rails cluster

Result

• performance ✔

• efficiency

• availability

• scalability

Page 17: How to build a state-of-the-art rails cluster

Setup 2

Page 18: How to build a state-of-the-art rails cluster

Ideas

• put app and database on separate machines

• use cheap commodity hardware

• like Google!

• go for high number of CPUs

Page 19: How to build a state-of-the-art rails cluster

Example hardware

• Dell PowerEdge SC 1435

• 2 x Opteron 2212 (dual core / 2 GHz)

• 4 GB ram, 160 GB disk

• 2 machines = 8 cores

• 3340 €

Page 20: How to build a state-of-the-art rails cluster

Result

• performance ✔

• efficiency ✔

• availability

• scalability

Page 21: How to build a state-of-the-art rails cluster

Setup 3

Page 22: How to build a state-of-the-art rails cluster

Ideas

• cluster of identical nodes

• loadbalancing

• failover

• eliminate single points of failure through redundancy

Page 23: How to build a state-of-the-art rails cluster

Setup 3a

Page 24: How to build a state-of-the-art rails cluster

Virtualization

• partition one physical machine into multiple virtual machines

• assign dedicated ressources (cpu, ram) to virtual machines

• example: xen (linux), zones (solaris)

Page 25: How to build a state-of-the-art rails cluster

Why virtualization?

• flexibility

• simplified deployment

• move images between machines

• optimization

• hardware utilization

• tuning

Page 26: How to build a state-of-the-art rails cluster

Why virtualization?

• isolation

• use different operating systems

• contain intrusion

• multiple environments (staging, production)

• but: small performance overhead (ca. 5%)

Page 27: How to build a state-of-the-art rails cluster

Setup 3a

Page 28: How to build a state-of-the-art rails cluster

Loadbalancer

• openBSD

• CARP: shared virtual ip, automatic failover

• pf: firewall + loadbalancer

• openBSD on xen: currently only on ramdisk

• better use dedicated hardware instead

Page 29: How to build a state-of-the-art rails cluster

Redundant firewall

Page 30: How to build a state-of-the-art rails cluster

Database

• mysql

• master-master replication

• caveat: avoid primary key clashes!

• other possibilities:

• master-slave replication

• mysql cluster

Page 31: How to build a state-of-the-art rails cluster

Result

• performance ✔

• efficiency ✔

• availability ✔

• scalability ?

Page 32: How to build a state-of-the-art rails cluster

• Evolving a cluster setup

• Scaling

• Make or buy?

• Discussion

Page 33: How to build a state-of-the-art rails cluster

Scaling

• not a rails-specific problem

• find and eliminate bottlenecks!

Page 34: How to build a state-of-the-art rails cluster

Scaling approaches

• scaling up

• increase power of machines

• scaling out

• increase number of machines

Page 35: How to build a state-of-the-art rails cluster

Scaling up: memory

• add more memory

• mongrel can be very memory-hungry

• useful for caching (memcached)

• hint: check crucial.com for low prices

Page 36: How to build a state-of-the-art rails cluster

Scaling up: CPU

• upgrade to quad-core Opterons

• available later this year

• same socket

• same power / heat envelope

• use as drop-in replacement

Page 37: How to build a state-of-the-art rails cluster

Scaling out

Page 38: How to build a state-of-the-art rails cluster

Scaling out

• app servers scale (almost) linearly

• use same hardware (if possible)

• one type of processor, memory, disk

• simplifies maintenance / repair

Page 39: How to build a state-of-the-art rails cluster

Bottleneck: application

• lots of concurrent users

• rails is single threaded (mutex lock)

• solution: add more mongrels

• rule of thumb: 10 mongrels per cpu

• twitter runs on ca. 300 mongrels

Page 40: How to build a state-of-the-art rails cluster

Bottleneck: database

• avoid to hit database

• cache as much as possible

• scale up database masters

• more disks = faster access

• add read-only db slaves

Page 41: How to build a state-of-the-art rails cluster

Scaling 2.0

Page 42: How to build a state-of-the-art rails cluster

Scaling storage

• disk failure very common

• use RAID1 for database masters

• network storage

• example: ATA-over-Ethernet (AoE)

• accessible as block device

• combine with cluster file system

Page 43: How to build a state-of-the-art rails cluster

Coraid EtherDrive, 11 TB, 200MB/s

Page 44: How to build a state-of-the-art rails cluster

• Evolving a cluster setup

• Scaling

• Make or buy?

• Discussion

Page 45: How to build a state-of-the-art rails cluster

Make or buy?

• think about total cost of ownership (TCO)

• not only hardware costs

• rackspace, power, bandwidth

• administration overhead

• „Utility? Or generator in the back yard?“ (David Young)

Page 46: How to build a state-of-the-art rails cluster

Our cluster

• hardware: 3340 €

• colocation with burst.net (for 1 year)

• 60 $ + 12 x 140 $ = 900 $ = 670 €

• 4000 € + administration

Page 47: How to build a state-of-the-art rails cluster

Rails hosting

• example: Engine Yard

• 1 slice = 1 CPU core, 400 MB ram

• 4 slices (for 1 year)

• 796 $ + 12 x 1116 $ = 14.200 $

• 10.500 €

Page 48: How to build a state-of-the-art rails cluster

• Evolving a cluster setup

• Scaling

• Make or buy?

• Discussion

Page 49: How to build a state-of-the-art rails cluster

• 2-machine cluster is cool (and quite affordable) setup

• virtualization is a Good Thing

• scaling the database can be tricky

• make or buy depends on concrete situation

Summary

Page 50: How to build a state-of-the-art rails cluster

Questions?

Page 51: How to build a state-of-the-art rails cluster
Page 52: How to build a state-of-the-art rails cluster