Escalabilidad en Rails

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.

1 comments

Comments 1 - 1 of 1 previous next Post a comment

  • + guest966ab0 guest966ab0 2 years ago
    Muy bueno el caso de éxito expuesto! :o)

    Muy didactico nene!

Post a comment
Embed Video
Edit your comment Cancel

2 Favorites

Escalabilidad en Rails - Presentation Transcript

  1. Escalabilidad Pablo A. Delgado New Bamboo Web Development London, UK
  2. Escalabilidad RAILS NO ESCALA
  3. Escalabilidad RAILS NO ESCALA Out of the box ...hay que ayudarle un poco...
  4. Rails stack
  5. Rails stack
  6. From Russia with love NGINX
  7. NGINX Nginx = Performance seria en HTTP * Escrito por Igor Sysoev * Casi no utiliza memoria * Soporta alta carga sin tener memory leaks * Joyas: modulos de rewrite y proxy * Documentación, comunidad en crecimiento http://sysoev.ru/en/ http://wiki.codemongers.com/
  8. Nginx Reglas ‘a la mod_rewrite’ en nginx.conf (compatibles con los tipos de cache en rails) if (-f $request_filename) { break; } if (-f $request_filename/index.html) { rewrite (.*) $1/index.html break; } if (-f $request_filename.html) { rewrite (.*) $1.html break; } if (!-f $request_filename) { proxy_pass http://mongrels ; break; }
  9. Nginx Arma tus propias reglas para nginx.conf location / { ssi on; if (-f $request_filename) { break; } if (-f $document_root/static/$uri.html) { rewrite (.*) /static/$1.html break; } if (!-f $request_filename) { proxy_pass http://mongrel; break; } } location ~ ^/(images|javascripts|stylesheets|photo|icon|style)/ { expires 10y; }
  10. Nginx Round robin proxy hacia los mongrels+rails upstream mongrels { server 127.0.0.1:5000; server 127.0.0.1:5001; server 127.0.0.1:5002; } location / { ... if (!-f $request_filename) { proxy_pass http://mongrels; break; } }
  11. Nginx Engineyard’s FAIR round robin proxy upstream mongrels { fair server 127.0.0.1:5000; server 127.0.0.1:5001; server 127.0.0.1:5002; } Con FAIR round-robin, nginx escoge el mongrel que está menos ocupado y le asigna la petición, evitando a los mongrels que demoran mucho. http://www.brainspl.at/articles/2007/11/09/a-fair-proxy-balancer-for-nginx-and-mongrel
  12. Nginx DEMO Engineyard’s FAIR round robin proxy http://www.brainspl.at/articles/2007/11/09/a-fair-proxy-balancer-for-nginx-and-mongrel
  13. MONGREL
  14. Rails stack
  15. Mongrel Mongrel es un servidor HTTP * Escrito por Zed A. Shaw * Super-rápido y liviano * Multithreaded * Dispobible como gem. http://mongrel.rubyforge.org
  16. Mongrel + RAILS Secuencia de dispatch de RAILS Request comes in ** Mutex gets locked ** Parse CGI + Mime (expensive) Route recognition (expensive) Before filter chain Call controller action Render Templates ** Mutext unlocked ** Result returned to client extraido de RUBY HOEDOWN 2007 conference, por Ezra Zygmuntowicz
  17. Mongrel + RAILS Mongrel + RAILS = NO MULTITHREADING -Mutex lock gigante alrededor de todo el ciclo de dispatch. Resultado, si tienes a un mongrel demorando al servir un request, ese mongrel queda bloqueado hasta haber terminado. - Simplificar el problema utilizando EVENTED MONGREL. EVENTED MONGREL corre el ciclo de dispatch de requests dentro de un event loop. Resultado NOS EVITAMOS toda la complicación (y el coste de ejecución) de los locks y la syncronización. Y nuestra aplicacion rails responderá mas rápido. Otra opción es utilizar SWIFTIPLY proxy.
  18. Mongrel + RAILS UPLOADS ? - Facil: usamos el plugin attachment_fu - Subimos los ficheros y los colocamos directamente en la base de datos.
  19. Mongrel + RAILS UPLOADS ? - Facil: usamos el plugin attachment_fu - Subimos los ficheros y los colocamos directamente en la base de datos. NO
  20. Mongrel + RAILS UPLOADS. Por qué no. - MONGREL+RAILS ==> problema de bloqueo - Si bloqueamos todos los mongrels, luego no serviremos ningun request. - SOLUCION: hacer los uploads fuera de rails.
  21. MERB
  22. MERB MERB = Mongrel +ERB * Escrito por Ezra Zygmuntowicz * Basado en Mongrel * Thread safe, Multithreaded * Dispobible como gem. * NO UTILIZA cgi.rb !! http://merbivore.com/
  23. MERB Dispatch de RAILS Dispatch de MERB Request comes in Request comes in ** Mutex gets locked ** Parse CGI + Mime (expensive) Parse CGI + Mime (expensive) Route recognition (expensive) Route recognition (expensive) ** Mutex gets locked ** Before filter chain Before filter chain Call controller action Call controller action Render Templates Render Templates ** Mutext unlocked ** ** Mutext unlocked ** Result returned to client Result returned to client extraido de RUBY HOEDOWN 2007 conference, por Ezra Zygmuntowicz
  24. MERB Gestionar UPLOADS con merb * Merb utiliza el mismo mecanismo de session store que rails * Puedes utilizar activerecod, cookie store o memcached para compartir la session entre RAILS y MERB * Un upload con merb no bloquea este merb, pudiendo servir otros request * Se pueden preguntar a merb por el upload_progress.
  25. NGINX - MERB
  26. MERB MEJOR SIN NGINX UPLOAD
  27. MERB CLUSTER
  28. ID PARTITIONING Utilizar el File System para guardar “files”. * El plugin attachement_fu utiliza mysql para guardar el nombre del fichero. * “Convention over configuration” generar un path y nombre de fichero directamente basado en su id. * Recordar la limitación de num. de ficheros que tienen los SO. * Ejemplo: para el ID 241621 http://s1.fotolog.com.ar/photo/q/000/241/241621_1065520677.jpg
  29. ID PARTITIONING ActionController::Base.asset_host = \"s%d.fotolog.com.ar\" def host_for(id) sprintf(\"http://\"+ActionController::Base.asset_host, id.modulo(4)) end def path_for(id) (\"%09d\" % id).scan(/.../)[0..1] end def filename_for(id) id.to_s+\"_\"+(Zlib.crc32(id.to_s+\"secret\")).to_s+\".jpg\" end def unique_path_for(model_name,size,id) File.join(host_for(id),model_name,size, parth_for(id), filename_for(id) ) end
  30. DIMENSIONAR
  31. Pensar en req/seg Calculo simple de requests/segundo 3 mongrels/(1 seg/req) = 3req/seg 10 mongrels/(1 seg/req) = 10req/seg 10 mongrels/(200req/seg) = 0.050 seg/req (50ms) 10 mongrels por cada CORE (aconsejable) 20 mongrels en DUAL CORE soportando 200req/seg equivale a un limite de 0.100seg/req 100ms. 24hs x 60min x 60seg = 86.400seg x 200 req/seg = 17millones req/dia!!!
  32. Pensar en req/seg Cuánto tráfico tiene tu sitio? (1 día = 86400 seg) 10.000 req al día /86.400 ~ 0.1 req/seg 100.000 req al día /86.400 ~ 1 req/seg 500.000 req al día /86.400 ~ 6 req/seg Qué error cometemos al hacer estos cálculos?
  33. Pensar en req/seg El tráfico no es uniforme durante el día Regla de seguridad...multiplica por 3 para los picos te tráfico
  34. Rails stack
  35. Pensar en req/seg Cuántas queries a mysql haces por cada request? 1a4 queries ==> ideal 5 a 10 queries ==> zona critica 10+ queries ==> arreglalo ya! 30+ queries ... te conviene matarte “te conviene matarte” -Marcelo Peralta,2000
  36. MYSQL OPTIMIZAR LOS ACCESOS A MYSQL - Desnormalización de ActiveRecord Fernando Blat (http://2006.conferenciarails.org) - Utilizar los siguientes plugins - MySQL Query Analizer (añade EXPLAIN al sql) - Active Record Context (utiliza query cache) http://svn.umesd.k12.or.us/plugins/query_analyzer/ http://activereload.net/2007/5/23/spend-less-time-in-the-database-and-more-time-outdoors
  37. MYSQL Especificos de MYSQL - Las tablas MyISAM usan full-table locking Inconveniente entre INSERTs y SELECTs - MySQL guarda los indices solo en orden ascendente. Solucion? (Wikipedia ultiliza esto) Crear un campo extra en la tabla reverse_created_at = 2030 - created_at Actualizar con un after_save :update_reverse
  38. From Russia with much more love! SPHINXSEARCH
  39. SPHINXSEARCH Full Text Search in C++ - Escrito por Andrew Aksyonoff - Motor de búsquedas Standalone - Rápido, eficiente en tamaño - Indexa documentos en filesystem - Interface a varios SQL engines (MySQL) - Indexa utilizando pipes en xml (think REST) - Segun version 0.9.8 búsquedas geográficas - API en Ruby, Perl, Php, Python... http://www.sphinxsearch.com/
  40. ULTRASPHINX Plugin para RAILS - Escrito por Evan Weaever (chown.com) - Utiliza riddle ruby api (0.9.8 / 0.9.7) - Es un wrapper alrededor de la api - Funciona bien con los plugins cache_fu y will_paginate - Utiliza ActiveRecord o Memcached para obtener los modelos de los resultados http://blog.evanweaver.com/files/doc/fauna/ultrasphinx/
  41. ultrasphinx-riddle-sphinxsearch
  42. http://fotolog.com.ar/ http://webcamole.com/
  43. http://fotolog.com.ar/ http://webcamole.com/
  44. Rails stack http://fotolog.com.ar/ http://webcamole.com/

+ pabletepablete, 2 years ago

custom

1869 views, 2 favs, 2 embeds more stats

Escalabilidad en rails.
Rails stack para alto rendi more

More info about this document

CC Attribution-ShareAlike LicenseCC Attribution-ShareAlike License

Go to text version

  • Total Views 1869
    • 1867 on SlideShare
    • 2 from embeds
  • Comments 1
  • Favorites 2
  • Downloads 30
Most viewed embeds
  • 1 views on http://localhost:9292
  • 1 views on http://192.168.10.100

more

All embeds
  • 1 views on http://localhost:9292
  • 1 views on http://192.168.10.100

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