Administration and Monitoring of Ruby applications on GlassFish v3

GlassFish v3 final has monitoring and administration support for Ruby on Rails or any Ruby Rack based application. Here is how you would go about administering and monitoring your Ruby on Rails application on GlassFish v3:

Setup

GlassFish v3

First you need to install GlassFish v3. Get it from here. After the download simply unzip it to the directory of your choice.

JRuby

Install JRuby 1.4.0 using updatetool

$ /tools/glassfishv3/bin/updatetool

Select JRuby 1.4.0 and click install. JRuby along with Rails 2.3.5, Merb, MySQL JDBC adapters will be installed inside glasfishv3/glassfish/jruby. Now add it to your path.
$ export JRUBY_HOME=/tools/glasfishv3/glassfish/jruby
$ export PATH=$JRUBY_HOME:$PATH

Install JRuby 1.4.0 from jruby.org

Alternatively you can install JRuby form jruby.org. You would also need to install any gem that your application will depend on, such as Rails, Merb, Sinatra or simply Rack incase you are writing your own Rack based framework. You would setup JRUBY_HOME and PATH accordingly.

Configuration

Before you begin, first start GlassFish v3 server
$ glassfishv3/bin/asadmin start-domain

JRuby

In case you are using your own JRuby installation then you need to tell GlassFish where to find it. There are 2 ways you can do it. Using asadmin CLI or using Admin console.

asadmin CLI
$asadmin configure-jruby-container --jruby-home=/tools/jruby-1.4.0
Admin console

In your browser type: http://localhost:4848, then select Configure=>Ruby container and then enter JRuby instalation in JRuby Home field and click Ok.

Ruby Container configuration

JRuby Runtime Pool

You can also setup JRuby runtime pool if you chose to run Rails or any other Ruby framework in non-threadsafe mode. This setting is recommended to be used only for production and for most optimal performance its advised to keep the initial, min and max values same. Basically freeze the pool so that it does not auto adjust between min and max values. Creation of JRuby runtime is a very expensive process, both in terms of time and resources, so you want to be careful with that specially in production uses. You can use the same screen where you setup JRuby Home to configure the runtime pool settings.

Here is how you can  configure JRuby runtime pool using asadmin CLI
$ asadmin configure-jruby-container --jruby-runtime=2
--jruby-runtime-min=2 --jruby-runtime-max=2

Monitoring

GlassFish v3 monitoring infrasutructure lets each of the container define their own set of probes and expose these as dTrace or view the stats using container exposed statistics or you can write javscript code and use the monitoring REST based services to collect the stats of your choice. For details on GlassFish v3 monitoring see Prashant's excellent blog.

asadmin CLI

Here is how you can configuring monitoring for Ruby applications using asadmin CLI
$ asadmin configure-jruby-container --monitoring=true
Setting --monitoring to false will simply disable it.

Admin console

Ruby monitoring configuration

Develop a Ruby application

Now that you have installed GlassFish v3 and JRuby and configured the JRuby container, runtime pool etc. Its time to develop a Ruby web application. To keep this blog simple, I would go for an extremely simple Rackup script config.ru.

config.ru
class HelloWorld
  def call(env)
    [200, {"Content-Type" =>"text/plain"}, ["Hello world!"]]
  end
end
run HelloWorld.new
In the above code HelloWorld class is a Rack application. A Rack application is the one that responds to call and returns array of HTTP status code, HTTP headers and the content. HelloWorld simply returns "HelloWorld!" as the content body.

Now lets deploy it.

Deployment

Assuming you are in the directory where config.ru file is located. Do the following to deploy on GlassFish:
$ asadmin deploy .

If you want to deploy using some other version of JRuby, lets say you have JRuby 1.5.0.dev and want to deploy using this version of JRuby, this is what you would do:
$ asadmin deploy --property jruby.home=/tools/jruby-1.5.0.dev .
If you don't like doing it using asadmin CLI, you can use admin console as well. Simply login to http://locahost:4848/ and chose Applications node and on deployment screen chose applicaton type as Ruby Application. See the image below

Ruby Deployment

Now Run...

Now access the application at http://localhost:8080/rack/

run

Monitoring stats

In earlier step we have already enabled monitoring so now you can use JConsol or Admin console or use asadmin CLI to monitor the stats. You can also use dTrace as well. Let see how you would use Admin console to monitor your stats. Go to http://localhost:4848/ and select Enterprise Server and then Monitor tab. You should see different stats such as JRuby Runtme Pool, HTTP and JRuby container stats.

Monitoring 1


Go get GlassFish v3 and start running, monitoring your Ruby on Rails or Merb or Sinatra or any Rack application. Send us your comments at users@glassfish.dev.java.net.
Comments:

Post a Comment:
  • HTML Syntax: NOT allowed
About

vivekpandey

Search

Categories
Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today