Rails Deployment with NginX (english)

Loading...

Flash Player 9 (or above) is needed to view presentations.
We have detected that you do not have it on your computer. To install it, go here.

0 comments

Post a comment

    Post a comment
    Embed Video
    Edit your comment Cancel

    12 Favorites

    Rails Deployment with NginX (english) - Presentation Transcript

    1. Rails Deployment with NginX the quest for the perfect rails stack
    2. Who Am I? Stoyan Zhekov ➲ Bulgarian in Japan ➲ 3 kids (boys) ➲ web: http://zhekov.net/ ➲
    3. Deploying Rails What is deployment? ➲ Too many changes last years ➲ Money matters ➲ EngineYard: $299/mo per slice ● RailsMachine: $245/mo + $60 setup ●
    4. Basics are the same Frontend web server ➲ processing static requests ● Backend (application) server(s) ➲ processing dynamic requests ● Database ➲
    5. Basics are the same (2) image by Ezra Zygmuntowicz
    6. History Lesson Apache + CGI ➲ Apache + FastCGI ➲ Lighttpd + FastCGI ➲ Lighttpd + SCGI ➲ Litespeed ➲ etc. etc. (mod_fcgi, mod_ruby) ➲ Mongrel ➲
    7. Enter Mongrel
    8. What is Mongrel? image by Ezra Zygmuntowicz
    9. What is Mongrel? (2) flickr image
    10. What is Mongrel? (3) HTTP server and library by Zed Shaw ➲ Almost pure Ruby (HTTP parser in C) ➲ Modular = can have my own handlers ➲ Library = can have my own framework ➲ Merb: http://merb.rubyforge.org/ ● Ramaze: http://ramaze.rubyforge.org/ ●
    11. Why Mongrel (and HTTP)? HTTP is well know protocol ➲ Mongrel is easy to setup ➲ Fast ➲ Easy management (monit) ➲ Scale easy ➲
    12. Dynamic Requests Mongrel != Rails ➲ Mongrel is Thread safe ➲ Rails isn't thread save (CGI.rb) ➲ Giant Mutex Lock around the Dispatcher ➲ Mongrel serving one request per time ➲
    13. Mutex Lock around the Dispatcher image by Ezra Zygmuntowicz
    14. What to do?
    15. Scale with processes mongrel_cluster ➲ load balancer ➲
    16. Load Balancer pen (no SSL) ➲ pound (restart to reload the config) ➲ balance ➲ HAproxy ➲ LiteSpeed Load Balancer ($1299) ➲
    17. The common problem? No static file serving ➲ Load is shifting to the backends (bad) ➲
    18. Static Requests JavaScript – bigger and bigger (AJAX) ➲ Multimedia – video, images ➲ Rails caching - .html ➲ Distributed assets - assets%i.dot.com ➲
    19. Frontend Web Server Apache – not enough RAM in VPS ➲ Lighttpd – memory leak under heavy load ➲ Litespeed – 300 simultaneous req limit ➲
    20. NginX: from Russia with love Name: nginx [engine x] ➲ HTTP server and IMAP/POP3/SMTP proxy ➲ 20% of russian sites ➲ fastmail.fm ➲ EngineYard ➲
    21. Problems? One man project ➲ Do you read/speak russian? - I do ;) ➲ No CGI support ➲
    22. Why NginX? Good performance ➲ Small memory footprint (VPS) ➲ No memory leaks in the proxy ➲ name- and IP-based virtual servers ➲ PUT, DELETE, MKCOL, COPY and MOVE ➲ Modular ➲ FLV streaming ➲
    23. Good Performance Serious Web servers use event loops ➲ http://www.kegel.com/c10k.html ● Optimized for every OS (async) ➲ BSD – kqueue ● Linux 2.6 – epool ● Solaris 10 – EventPorts (Joyent.com) ●
    24. High availability Management by unix signals ➲ kill -HUP – reload the config ● kill -USR2 – BINARY RELOAD ●
    25. Coding style if (m[1] == 'O') { if (m[0] == 'P' && m[2] == 'S' && m[3] == 'T') { r->method = NGX_HTTP_POST; break; } if (m[0] == 'C' && m[2] == 'P' && m[3] == 'Y') { r->method = NGX_HTTP_COPY; break; } ...
    26. NginX Installation Two versions: 0.5.x (stable) and 0.6.x (devel) (Debian/Ubuntu) # apt-get install libssl-dev http://zhware.net/code/shell/mk_nginx.sh.txt
    27. NginX Configuration Ezra Zygmuntowicz (merb, BackgroundDRb): http://brainspl.at/nginx.conf.txt http://pastie.caboo.se/84928 # gem install nginx_config_generator # generate_nginx_config –example > config.yml # generate_nginx_config config.yml nginx.conf
    28. Config: OS tuning user www-data; worker_processes 1; events { worker_connections 1024; use epoll; }
    29. Config: HTTP block http { include conf/mime.types; include conf/optimize.conf; upstream mybackends { server b1.example.com weight=5; server b2.example.com:8080; server unix:/tmp/backend3; } server { ... }
    30. Config: server block server { listen 80; name s1.example.com; location / { } } server { listen 80; name s2.example.com; ... }
    31. Config: location blog location / { ... proxy_pass http://mybackends; ... }
    32. Interesting features Virtual SSI ➲ <!--# include virtual=”/foo” --> ● Mirror on demand ➲ memcached module ➲
    33. NginX Rails config location / { # static files if (-f $request_filename) { break; } # rails caching if (-f $request_filename.html) { rewrite (.*) $1.html break; } if (!-f $request_filename) { proxy_pass http://mongrel; break; } }
    34. Links english: http://nginx.net/ ➲ wiki: http://wiki.codemongers.com/ ➲ my notes: http://wiki.zhekov.net/nginx ➲ links: http://del.icio.us/zh/nginx ➲ chat: #nginx on FreeNode, ➲ http://www.lingr.com/room/nginx/
    35. What else? Combinations ➲ nginx + Litespeed backends ● Backend optimizations ➲ Swiftiply Proxy: http://swiftiply.swiftcore.org/ ● Evented Mongrel (eventmachine) ● Edge Side Includes (ESI):http://www.esi.org/ ➲ Merb instead of Rails ➲
    36. Questions?

    + Stoyan ZhekovStoyan Zhekov, 3 years ago

    custom

    6968 views, 12 favs, 6 embeds more stats

    The quest for the perfect Rails stack

    More info about this document

    CC Attribution License

    Go to text version

    • Total Views 6968
      • 6950 on SlideShare
      • 18 from embeds
    • Comments 0
    • Favorites 12
    • Downloads 231
    Most viewed embeds
    • 12 views on http://blog.bbox.selfip.net
    • 2 views on http://blog.bbox2.selfip.net
    • 1 views on http://209.85.135.104
    • 1 views on http://tt.zhekov.net
    • 1 views on http://64.233.183.104

    more

    All embeds
    • 12 views on http://blog.bbox.selfip.net
    • 2 views on http://blog.bbox2.selfip.net
    • 1 views on http://209.85.135.104
    • 1 views on http://tt.zhekov.net
    • 1 views on http://64.233.183.104
    • 1 views on http://g33k.tumblr.com

    less

    Flagged as inappropriate Flag as inappropriate
    Flag as inappropriate

    Select your reason for flagging this presentation as inappropriate. If needed, use the feedback form to let us know more details.

    Cancel
    File a copyright complaint
    Having problems? Go to our helpdesk?

    Categories