The Sun GlassFish Enterprise Server v3 Prelude provides a JRuby runtime pool to allow servicing of multiple concurrent requests. However Rails is not currently thread-safe, and while JRuby is able to take advantage of Java's native threading, Rails cannot benefit from it. Each JRuby runtime runs a single instance of Rails, and requests are handed off to whichever instance happens to be available at the time of the request.
JRuby runtime pool is configured in <AS_INSTALL>/domains/domain1/config/domain.xml file. Edit the file and add the elements below with the values that you want the runtime to be configured with as indicated.
<java-config> <jvm-options>-Djruby.runtime.min=1</jvm-options> <jvm-options>-Djruby.runtime=2</jvm-options> <jvm-options>-Djruby.runtime.max=3</jvm-options> </java-config>
The properties of the above elements are explained as follows:
-Djruby.runtime=X sets the initial number of JRuby runtimes that GlassFish starts with. The default value is one. This represents the highest value that GlassFish accepts as minimum runtimes, and the lowest value that GlassFish uses as maximum runtimes.
-Djruby.runtime.max=X sets the maximum number of JRuby runtimes that might be available in the pool. The default value is two. For this element, too high values might result in OutOfMemory errors, either in the heap or in the PermGen.
-Djruby.runtime.min=X sets the minimum number of JRuby runtimes that will be available in the pool. The default value is one. The pool will always be at least this large, but can be larger than this.
The dynamic runtime pool maintains itself with the minimum number of runtimes possible, to allow consistent and fast runtime access for the requesting application. The pool may take a initial runtime value, but that value is not used after pool creation.