-
Notifications
You must be signed in to change notification settings - Fork 0
JRubyOnRailsInGlassFish
» JRuby Project Wiki Home Page » JRuby on Rails: GlassFish V3 Deployment
GlassFish V2 is an open source Java EE 5 application server. Java EE is a long tested deployment environment, and by combining the benefits of GlassFish with JRuby, we provide the best deployment environment for Rails applications. Here are some of the benefits of using GlassFish as the deployment environment for JRuby on Rails applications :- Use the time-tested Java EE deployment platform.
- Avoid the complex Mongrel-based deployment environment for Rails applications.
- With the availability of Goldspike, you can deploy a WAR file of your Rails application directly to a GlassFish instance.
- Java EE and Ruby-on-Rails applications can be easily integrated in one container. This enables you to host JRuby-on-Rails applications in organizations that have already made investment in Java EE.
- Rails applications benefit from the out-of-the-box clustering and high-availability support provided by GlassFish.
- Reuse your database connections with GlassFish's database connection pooling mechanism.
- Leverage the extensive set of Java libraries in your JRuby on Rails applications..
In GlassFish v2, we currently support the WAR mode of deployment for your JRuby on Rails applications. You can create the .war file from your existing Rails applications by using Warbler.
Refer to the section titled "GlassFish V2" of the Getting Started Guide. At the end of these steps ensure that you have the following environment variables defined :
GLASSFISH_ROOT - pointing to the directory where GlassFish V2 is installed JRUBY_HOME - the JRuby version which would point to $GLASSFISH_ROOT/jruby/jruby-1_0_3/jruby-1.0.3. PATH - add $GLASSFISH_ROOT/bin and $JRUBY_HOME/bin to your existing PATH environment variable.
If you're ready to deploy your own JRuby on Rails application, skip this section and go to the next section, How to deploy JRuby on Rails applications.
Here are some steps for creating a very simple JRuby on Rails "hello" application. The application uses the JRuby version that you installed in the "Setup" section above.
cd $GLASSFISH_ROOT/jruby/samples jruby -S rails hello jruby script/generate controller say message
The last line creates a controller say with a view message.
This section describes how to deploy this application to GlassFish v2 in both Standalone Mode and Shared Mode.
Note: In the instructions listed below, change the directory name if you are deploying your own JRuby on Rails application.
If you already have a .war file for your JRuby on Rails application (created using Warbler or Goldspike), skip the prelminary instructions and go to "To deploy the Rails application" in either the Standalone Mode section or the Shared Mode section below.
- Go the Rails application directory and enter the following commands:
cd $GLASSFISH_ROOT/jruby/samples/hello<br/>
You can now see a WEB-INF directory under the hello sample directory that contains web.xml and the two directories lib and gems.
- Before doing a directory deployment of the sample to GlassFish, ensure that the GlassFish application server is running as follows:
cd ..<br/> asadmin start-domain
Note: If the application server is already running, the command safely exits. - To deploy the Rails application, enter the following commands:
cd $GLASSFISH_ROOT/jruby/samples<br/> asadmin deploy hello - Access the following URLs in a browser:
http://localhost:8080/hello/say/message<br/> http://localhost:8080/hello
To deploy an application in shared mode, ensure that you have followed the "Post Installations" steps of the Getting Started Guide. Please note that the steps have to be done only once for a GlassFish installation.
Note: I don't see a Post Installations section in the GlassFish Getting Started Guide above.
You can now see a WEB-INF directory under the hello sample directory that contains just the file web.xml.
To deploy the Rails application:
cd $GLASSFISH_ROOT/jruby/samples/hello $GLASSFISH_ROOT/lib/ant/bin/ant -f $GLASSFISH_ROOT/jruby/install.xml create-shared
Access the following URLs in a browser:
http://localhost:8080/hello/say/message http://localhost:8080/hello
Before deploying Glassfish on Microsoft Windows, be aware that this operating system presents a unique set of challenges. JRuby doesn't seem to be as well tested on Microsoft Windows as on other platforms. Here are some of the issues you might encounter and some workarounds for them.
If you are new to Microsoft Windows, be aware that it likes to "lock" files on you. When you try to delete, move, or change a file, you can get a message saying, "The file is in use." What can cause this message? For example, if you redploy your .war file, you often see, "The file jnidispatch.dll is in use and wasn't overwritten". You can ignore this message if you haven't updated your version of JRuby. But if you have, you should :
- undeploy your app
- stop your domain
- start your domain
- deploy the new version of your app
You especially have to watch case in Microsoft Windows because the operating system doesn't pay attention to case, so you might forget that GlassFish does. When deploying a .war file via script (for example, you layer Ruby over the asadmin command set and use rake to deploy the file), watch the case of the file name in your script.
For example, a file is deployed with the following capitalization:
asadmin deploy "MyApp.war"
Make sure if you undeploy in your script, you undeploy MyApp.war and not myApp.war.
Note: This tip applies to all operating systems, not just Microsoft Windows.
Take the time to profile your application under load and at steady state and find the right set of JVM parameters that will make your app sing. Glassfish handles a heavy load well, but you have to tune to get the best performance.
For example, here's a subset of JVM options in a sample domain xml:
<jvm-options>-XX:SurvivorRatio=2</jvm-options>
<jvm-options>-XX:MaxPermSize=192m</jvm-options>
<jvm-options>-server</jvm-options>
<jvm-options>-Xmx1000m</jvm-options>
<jvm-options>-Xms1000m</jvm-options>
<jvm-options>-XX:NewRatio=2</jvm-options>
<jvm-options>-Djavax.net.ssl.sessionCacheSize=10000</jvm-options>
Note: The -server option makes a big difference.
Note: This tip applies to all operating systems, not just Microsoft Windows.
GlassFish v2 doesn't like colons (:) in URLs. For example, if you have some REST based web services with resources that have colons in the resource IDs, you'll have to code around them. (FWIW: I believe that V3 and Tomcat don't have this issue).
If you use SSL, front your application server with something like Apache and have it handle the SSL stuff.
Setting up SSL is pretty straightforward. However, you might encounter some odd issues. First off, under load you could run out of memory. When that happened in one installation, diagnosing the problem with Jconsole heap dumps and a Java profiler showed that there was a cache for the SslSessionContextImpl softreferences (which didn't even point to anything), and the cache was growing unbounded. From looking at the source code of the class, it appeared that there was a default timeout of 24 hours to clean up this cache. There didn't seem to be a way to change the timeout, but there was a way to limit the size of the cache. (See the last JVM-OPTION in the list above, the one that sets the ssl.sessionCacheSize).
Setting this option caused another problem to come up for this installation. It was handling 400 simultaneous users under a supremely heavy load, and the memory was holding great until the application crashed because Microsoft Windows ran out of nonpaged pool memory. The problem is described at Win 2k3 non paged pool. Changing the blocking characteristic to true for Grizzly stopped the nonpaged pool leak but had the potential to reduce the load the application could handle. The fix was applied only to the SSL listener because the problem didn't occur before switching to SSL.
GlassFish V3 is the next major release of the GlassFish application server with the focus on modularization, enablement of non Java EE containers, and embedability. As part of GlassFish V3 we have created a gem which would help users to launch their Ruby on Rails (ROR) applications embedded within the JRuby VM space.
Refer to the the section titled "GlassFish V3" of the Getting Started Guide.
At the end of these steps ensure that you have the following environment variables are defined :
JRUBY_HOME - the jruby version.
PATH - add $JRUBY_HOME/bin to your existing PATH environment variable.
Refer to the instructions provided in the "Sample Application" section of GlassFish V2 to create a very simple "hello" application. The directory name where you create the application would be different. Again for users who would like to use their own application please feel free to do so.
To deploy a Rails application with GlassFish v3 gem :
cd <directory_that_contains_the_hello_application> jruby -S glassfish_rails hello
That's it! You would see an output similar to the one listed below in the console where you started the Gem:
Jan 4, 2008 3:35:52 PM com.sun.grizzly.standalone.StaticResourcesAdapter <init> INFO: New Servicing page from: /Users/pramodgopinath/jruby-1.0.3/bin/hello/public Jan 4, 2008 3:36:00 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: Startup service : Application Loader Jan 4, 2008 3:36:00 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: Startup service : Grizzly on port 8080 Jan 4, 2008 3:36:00 PM com.sun.enterprise.v3.server.AppServerStartup run INFO: Glassfish v3 started in 8567 msThe application is deployed and ready to accept requests.
Use the following urls to check out the application :
http://localhost:8080/hello
http://localhost:8080/hello/say/message
GlassFish JRuby Wiki
Rails powered by GlassFish Application Server
Email dev@glassfish.dev.java.net aliasto discuss problems/issues with GlassFish deployments of JRuby on Rails applictions