Ams.rb Oktober

756 views

Published on

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

Published in: Technology
  • Be the first to comment

Ams.rb Oktober

  1. 1. Lessons Learned while building
  2. 2. or... How To Run Your Big App on One Server AndAHalf
  3. 3. Menno van der Sman Developer at Wakoopa since May 2007
  4. 4. Wakoopa is about software
  5. 5. PC Mac Linux
  6. 6. 200 GB
  7. 7. Does it scale?
  8. 8. Scaling the front is easy
  9. 9. Scaling the back is harder
  10. 10. Limits spawn creativity
  11. 11. Servers at Railsmachine 16GB RAM 5GB RAM 8 Cores 4 Cores dedicated shared staging archiving production database
  12. 12. or... Keeping Your Database Happy
  13. 13. Queuing processing multiple items at a time efficient cache update DelayedJob for anything else
  14. 14. Smart queries UPDATE developers SET active_seconds = active_seconds + ... INSERT INTO hourly_usage (...) VALUES (...) ON DUPLICATE KEY UPDATE active_seconds = active_seconds + ..., idle_seconds = idle_seconds + ... Allows for concurrency
  15. 15. Aim for a Small Rowsize choose a correct datatype pick the right indexes sometimes `id` shouldn’t be the PK
  16. 16. composite_primary_keys Allows efficient PK class HourlyUsage < ActiveRecord::Base set_primary_keys :user_id, :software_id, :used_at ... end Original implementation by Dr Nic Maintained by Darrin Holst http://github.com/drnic/composite_primary_keys
  17. 17. Archive old data that’s not frequently used 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
  18. 18. Alternative solution Partitioning 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 ); Makes ‘WHERE software_id = ...’ very fast Didn’t work for us
  19. 19. Other Techologies Rails 2.3 Apache Passenger REE 1.8.7 MySQL 5.0 Memcached Sphinx Amazon EC2
  20. 20. Our REE settings #!/bin/sh RUBY_HEAP_MIN_SLOTS=500000 RUBY_HEAP_SLOTS_INCREMENT=250000 RUBY_HEAP_SLOTS_GROWTH_FACTOR=1 RUBY_GC_MALLOC_LIMIT=50000000 exec "/opt/ruby-enterprise/bin/ruby" "$@"
  21. 21. Questions? or suggestions?

×