ams.rb oktober

23
Lessons Learned while building

Upload: menno-van-der-sman

Post on 10-May-2015

560 views

Category:

Technology


1 download

DESCRIPTION

Presentation given by Menno van der Sman from Wakoopa at Ams.rb

TRANSCRIPT

Page 1: Ams.rb Oktober

Lessons Learnedwhile building

Page 2: Ams.rb Oktober

How To Run Your Big App on OneAndAHalf Server

or...

Page 3: Ams.rb Oktober

Menno van der SmanDeveloper at Wakoopa

since May 2007

Page 4: Ams.rb Oktober

Wakoopa is about software

Page 5: Ams.rb Oktober
Page 6: Ams.rb Oktober

MacPC

Linux

Page 7: Ams.rb Oktober

200GB

Page 8: Ams.rb Oktober

Does it scale?

Page 9: Ams.rb Oktober

Scaling the front is easy

Page 10: Ams.rb Oktober

Scaling the back is harder

Page 11: Ams.rb Oktober

Limits spawn creativity

Page 12: Ams.rb Oktober

Serversat Railsmachine

16GB RAM8 Cores

5GB RAM4 Cores

dedicatedstaging

productiondatabase

sharedarchiving

Page 13: Ams.rb Oktober

Keeping Your Database Happy

or...

Page 14: Ams.rb Oktober

Queuing

DelayedJob for anything else

processing multiple items at a time

efficient cache update

Page 15: Ams.rb Oktober

Smart queries

INSERT INTO hourly_usage (...) VALUES (...) ON DUPLICATE KEY UPDATE active_seconds = active_seconds + ..., idle_seconds = idle_seconds + ...

UPDATE developers SET active_seconds = active_seconds + ...

Allows for concurrency

Page 16: Ams.rb Oktober

Aim for a Small Rowsize

choose a correct datatype

pick the right indexes

sometimes `id` shouldn’t be the PK

Page 17: Ams.rb Oktober

Allows efficient PK

Original implementation by Dr NicMaintained by Darrin Holst

http://github.com/drnic/composite_primary_keys

class HourlyUsage < ActiveRecord::Base set_primary_keys :user_id, :software_id, :used_at ...end

composite_primary_keys

Page 18: Ams.rb Oktober

SELECT ... FROM hourly_usage WHERE used_at < '...' INTO OUTFILE '/path/to/file'

LOAD DATA LOCAL INFILE '/path/to/file' REPLACE INTO TABLE hourly_usage_storage

avoids long locks

Archive old datathat’s not frequently used

Page 19: Ams.rb Oktober

Alternative solutionPartitioning

CREATE TABLE hourly_usage_storage ( ... )PARTITION BY RANGE (software_id) ( PARTITION p0 VALUES LESS THAN (...), PARTITION p1 VALUES LESS THAN (...), PARTITION p2 VALUES LESS THAN (...), PARTITION p3 VALUES LESS THAN (...), .... PARTITION pn VALUES LESS THAN MAXVALUE);

Didn’t work for us

Makes ‘WHERE software_id = ...’ very fast

Page 20: Ams.rb Oktober

Rails 2.3Apache

PassengerREE 1.8.7

MySQL 5.0Memcached

SphinxAmazon EC2

Other Techologies

Page 21: Ams.rb Oktober

Our REE settings

#!/bin/shRUBY_HEAP_MIN_SLOTS=500000RUBY_HEAP_SLOTS_INCREMENT=250000RUBY_HEAP_SLOTS_GROWTH_FACTOR=1RUBY_GC_MALLOC_LIMIT=50000000exec "/opt/ruby-enterprise/bin/ruby" "$@"

Page 22: Ams.rb Oktober

Questions?or suggestions?

Page 23: Ams.rb Oktober