Thread pooling w/Merb vs. Rails in a JEE Web app. context

It appears that there is some kind of built-in thread pooling that you
get if you deploy a Rails app. into a JEE container using Goldspike or
Warbler and you have a couple of parameters to set the upper and lower
bounds of that thread pool.

If you deploy a Merb app. using Warbler, however, it appears that there
is no such built-in thread pool.

However, I found this on the JRuby wiki:

"Ruby scripts frequently take advantage of the C impl’s lightweight
(green) threading by spinning up hundreds or thousands of threads during
a run. Under JRuby, this can often mean that hundreds or thousands of
native threads are spun up and thrown away, which is inefficient in many
cases and on many platforms. As an alternative to straight-up 1:1
threading in JRuby, you may also enable thread pooling. When pooling is
enabled, JRuby starts up only as many threads as are needed for
concurrent tasks. Repeatedly launching short-lived Ruby threads then
will reuse native threads. This can improve performance in many cases,
especially when libraries like /timeout/ are employed that spin up a
thread-per-call.

To enable pooling, set the Java system property “jruby.thread.pooling”
to true:

jruby -J-Djruby.thread.pooling=true myscript.rb
"
which would appear to give me some kind of thread pooling ability in the
Merb scenario.

Is this worth trying to set up for my Merb Web app.? Will it help?

If it will help, then how would I pass the -J-Djruby.thread.pooling=true
flag into the jruby process running inside of my Web app. though? I’m
not sure I understand where the JRuby process is invoked in that case.

Thanks,
Wes


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Wes G. wrote:

It appears that there is some kind of built-in thread pooling that you
get if you deploy a Rails app. into a JEE container using Goldspike or
Warbler and you have a couple of parameters to set the upper and lower
bounds of that thread pool.

If you deploy a Merb app. using Warbler, however, it appears that there
is no such built-in thread pool.

The pool for which you can set max and min when deploying Rails is a
pool of JRuby instances. Rails is not currently thread-safe, so in
order to handle multiple concurrent requests, we spin up several JRuby
instances and only let them each be used by a single thread at a time.
Merb has no such requirement since it is (mostly) thread-safe, and so
this setting is not necessary. One JRuby instance will be used across
however many threads the server decides to throw at it.

As far as actual native threads, basically all Java servers you’ll
deploy to already do their own thread pooling and have their own
settings for increasing or decreasing the size of that pool. But
generally you won’t need to fiddle with those settings, and e.g Merb
will work fine across those threads.

will reuse native threads. This can improve performance in many cases,
especially when libraries like /timeout/ are employed that spin up a
thread-per-call.

The JRuby thread pool works well if you have an app that’s spinning up
lots and lots of Ruby threads, which is not really the case in Merb.
JRuby’s pool is more for when running specific applications that use
Threads as a generic asynchronous call mechanism without considering the
cost of spinning up all those threads.

  • Cahrlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Charles Oliver N. wrote:

pool of JRuby instances. Rails is not currently thread-safe, so in
will work fine across those threads.
Charlie,

Thanks for that. That pretty much jived with what I was thinking, so it
was nice to get some feedback.

One last, potentially nitpicky question: you said above that Merb is
“mostly” thread-safe. Can you elaborate a bit, or should I just take it
up on the Merb list?

Thanks,
Wes


To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email

Wes G. wrote:

Thanks for that. That pretty much jived with what I was thinking, so it
was nice to get some feedback.
One last, potentially nitpicky question: you said above that Merb is
“mostly” thread-safe. Can you elaborate a bit, or should I just take it
up on the Merb list?

Unfortunately I can’t…we’ve just gotten occasional offhand reports of
thread-related failures/bugs in Merb. I don’t know if any of those
reports made it back to the Merb guys or if they were just user errors
though.

Of course, as far as I know there’s been very little testing done by the
Merb guys on any impl that supports “real” threading, so there’s bound
to be a few issues. I’m sure they’d be speedily fixed if they do come
up.

  • Charlie

To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email