Ruby on the server

675 views

Published on

slides from 25 Oct 2012 meetup (http://www.meetup.com/madruby/)

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
675
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
2
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Ruby on the server

    1. 1. Ruby on the Server Max out your rubies!
    2. 2. Ruby Version ManagerUse it on the server! Multiple isolated Rubies Easy environment variables Easy install with patch integrationsetup/rvm.rb: https://gist.github.com/3946908
    3. 3. Ruby Garbage Collection Mark and Sweep, more or less: Stop the world Traverse and mark reference tree Free all unused objects (lazy = free) Still no free slots? Allocate 1.8 times more slots than on previous alloc
    4. 4. Typical Web Applications Small variations in used slots 100,000 - 200,000 slots in total 2,000 - 10,000 objects per request Most memory occupied by eternal (never freed) objects (code, classes, etc...)
    5. 5. Ruby 1.9.3-p286Ruby 1.9.3 GC is not copy-on-write friendlyBy default, 10,000 slots are allocated onstartup1.8 growth rate means Ruby is likely toallocate a lot more memory than needed!
    6. 6. falcon patchCopy-on-write friendly GCPerformance++ for require and HashSupported in RVM (--patch falcon)
    7. 7. GC ConfigurationWe want to allocate enough memory, so that rubynever has to resize it’s heapTypically 100,000 to 200,000 initial slotsRUBY_HEAP_MIN_SLOTS environment variable/usr/bin/time -l rails r "User.first(2000); pp GC.stat"
    8. 8. RAINBOWSServes HTTP over a Unix socketDoes not need rootMaster preloads app and forks workersMultiple net concurrency modelsExample config: https://gist.github.com/3946921
    9. 9. FOREMANProcess launcherExports to Upstart, launchd and othersKeeps developers happy!
    10. 10. FOREMAN: PROCFILE Environment-specific config called Procfile Advanced example: https://gist.github.com/3946937# Simple (no rvm) Procfileweb: bundle exec rainbowsresque: bundle exec rake resque:work QUEUE=*scheduler: bundle exec rake resque:scheduler# Run with$ foreman start web# Export with$ sudo foreman export upstart /etc/init -u app_user -a app
    11. 11. Seamless deploymentsTell Rainbows master to restart (USR2)On spawning a new worker, kill an old oneExtra memory requirement:1 worker + 1 masterCode here: https://gist.github.com/3946921
    12. 12. CapistranoMostly “just works” with rvm-capistranorvm_run command + restart_web task here:https://gist.github.com/3947004

    ×