Ruby, Ruby on Rails y Threads

17 views
Skip to first unread message

Angel Java Lopez

unread,
Jun 23, 2012, 6:42:03 AM6/23/12
to rub...@googlegroups.com
Hola gente!

En este thread de la lista de Node.js


alguien afirmo: "Rails is single thread"

No estoy seguro que sea el caso.

Por un lado, encuentro que hay soporte de threads en 1.9 YARV (algo asi habia entendido en la RubyConf del anio pasado, y que antes solo habia "green threads", digamos, threads de mentiritas ;-)
all modern Ruby VMs that run Rails (Ruby 1.9′s YARV, Rubinius, and JRuby) use native threads, eliminating the annoying tax that you need to pay for using threads in Ruby 1.8. 

Por otro lado, leo
Even better, while Ruby originally started out with a "green threads" implementation which executed threads in userspace and could not provide multicore concurrency, newer, more modern Ruby implementations emerged which provided true native multithreading. JRuby and IronRuby, implementations of Ruby on the JVM and .NET CLR respectively, provided truly concurrent native multithreading while still maintaining Ruby's original threading API. Rubinius, a clean-room implementation of a Ruby VM based on the Smalltalk 80 architecture, has started to take steps to remove its global lock and allow concurrent multithreading as well

Que NO MENCIONA a Ruby 1.9 YARV, supongo porque en ese fecha no existia, es asi?

Ahora, dejando de lado si la Ruby VM tiene o no soporte de threads nativos, leo
encuentro que Rails hace algo:
The first item on the rack stack is Rack::Lock. This puts a lock around each request, so only one request is handled at a time. As such a standard rails app is single threaded. You can however spawn new threads within a request that would make your app multi threaded, most people never encounter this.

Sigue siendo asi? Se saco eso en alguna version de Rails? Porque necesita ese lock? Se puede quitar? Como es?

Nos leemos!

Angel "Java" Lopez

Juan Manuel Cuello

unread,
Jun 23, 2012, 1:16:34 PM6/23/12
to rub...@googlegroups.com

On Sat, Jun 23, 2012 at 7:42 AM, Angel Java Lopez <ajlop...@gmail.com> wrote:

En este thread de la lista de Node.js


alguien afirmo: "Rails is single thread"


 
Por un lado, encuentro que hay soporte de threads en 1.9 YARV (algo asi habia entendido en la RubyConf del anio pasado, y que antes solo habia "green threads", digamos, threads de mentiritas ;-)
all modern Ruby VMs that run Rails (Ruby 1.9′s YARV, Rubinius, and JRuby) use native threads, eliminating the annoying tax that you need to pay for using threads in Ruby 1.8. 


Por lo que yo tengo entendido, Ruby 1.9 soporta threads reales.

 
Ahora, dejando de lado si la Ruby VM tiene o no soporte de threads nativos, leo
encuentro que Rails hace algo:
The first item on the rack stack is Rack::Lock. This puts a lock around each request, so only one request is handled at a time. As such a standard rails app is single threaded. You can however spawn new threads within a request that would make your app multi threaded, most people never encounter this.

Sigue siendo asi? Se saco eso en alguna version de Rails? Porque necesita ese lock? Se puede quitar? Como es?

Creo que el parámetro de configuración del que hablo arriba está relacionado a esto. Los links que ahí pongo también aportan algo de info al respecto.

Espero sirva!

Juan

geronimo diaz

unread,
Jun 23, 2012, 2:01:42 PM6/23/12
to rub...@googlegroups.com


2012/6/23 Juan Manuel Cuello <juanma...@gmail.com>


On Sat, Jun 23, 2012 at 7:42 AM, Angel Java Lopez <ajlop...@gmail.com> wrote:

coincido, a partir de Rails 2.2 es thread-safety http://guides.rubyonrails.org/2_2_release_notes.html#thread-safety,  obviamente depende de la infraestructura del web server que se utilize, si el web server genera un proceso por request entonces la rails app sera single-threaded.
 
 
Por un lado, encuentro que hay soporte de threads en 1.9 YARV (algo asi habia entendido en la RubyConf del anio pasado, y que antes solo habia "green threads", digamos, threads de mentiritas ;-)
all modern Ruby VMs that run Rails (Ruby 1.9′s YARV, Rubinius, and JRuby) use native threads, eliminating the annoying tax that you need to pay for using threads in Ruby 1.8. 


Por lo que yo tengo entendido, Ruby 1.9 soporta threads reales.

a partir de Ruby 1.9 la clase Thread representa un thread del s.o y la clase Fiber representa los green threads que se tenia en Ruby 1.8 pero con un mejor algoritmo de scheduling http://www.igvita.com/2009/05/13/fibers-cooperative-scheduling-in-ruby/

 

 
Ahora, dejando de lado si la Ruby VM tiene o no soporte de threads nativos, leo
encuentro que Rails hace algo:
The first item on the rack stack is Rack::Lock. This puts a lock around each request, so only one request is handled at a time. As such a standard rails app is single threaded. You can however spawn new threads within a request that would make your app multi threaded, most people never encounter this.

Sigue siendo asi? Se saco eso en alguna version de Rails? Porque necesita ese lock? Se puede quitar? Como es?

Creo que el parámetro de configuración del que hablo arriba está relacionado a esto. Los links que ahí pongo también aportan algo de info al respecto.

exactamente:
Setting config.threadsafe! voids almost everything I said. That removes Rack::Lock from the stack, and means you will need to set a mutex manually to prevent double entry. Don't do it unless you have a really good reason



Espero sirva!

Juan



--
Geronimo Diaz
RoR Developer

gtalk: geronimod
skype: geronimodiaz

twitter: geronimodiaz


Damian Janowski

unread,
Jun 25, 2012, 12:00:12 AM6/25/12
to rub...@googlegroups.com
On Sat, Jun 23, 2012 at 7:42 AM, Angel Java Lopez <ajlop...@gmail.com> wrote:
> Sigue siendo asi? Se saco eso en alguna version de Rails? Porque necesita
> ese lock? Se puede quitar? Como es?

Como mencionaron otros, se puede sacar pero obviamente termina
dependiendo del web server que uses si efectivamente se usan threads o
no.

For the record, por si a alguno le interesa explorar esta posibilidad,
en Educabilia usamos Rainbows! (variante de Unicorn) [1] con la opción
de ThreadPool [2] en MRI 1.9.3 y anda muy lindo. Algún día probaremos
el deploy con JRuby/Trinidad que también soporta threads nativos.

[1] http://rainbows.rubyforge.org
[2] http://rainbows.rubyforge.org/Rainbows/ThreadPool.html
Reply all
Reply to author
Forward
0 new messages