The Source for Java Technology Collaboration
User: Password:



Jean-Francois Arcand

Jean-Francois Arcand's Blog

JRuby on Grizzly 1.5 now ready.....with asynchronous request processing support and soon Comet!

Posted by jfarcand on May 30, 2007 at 12:38 PM | Comments (7)

The very tiny JRuby on Grizzly module is now shipping and will soon be part of the Grizzly official distribution.

werixc 080.jpg

You can now start testing it and eventually replace your Mongrel or WEBrick native WebServer with the pure Java Ruby Bear :-). You can download the JRuby on Grizzly ready server here. Then just do:

% unzip jruby-on-grizzly-1.5-SNAPSHOT.jar
% cd jruby-on-grizzly
% java -jar ruby-1.5-SNAPSHOT.jar [port] [jruby applications] [number of runtime] \
[asyncExecution=true|false]

But wait, this release also have new features other JRuby server doesn't have :-)! It support asynchronous request processing(ARP). The server ship with a default AsyncFilter that park the request for 10 seconds. Nothing fancy, but it give a good start for people interested about JRuby + ARP. And wrinting an AsyncFilter is quite easy so I suspect we should see asynchronous JRuby web application soon.

To enable APR, just do:

% java -jar ruby-1.5-SNAPSHOT.jar 8888 /jruby-apps/ 1 true

On the server console, you should see the parking/resume message every time you sent a request:

$ java -jar jruby-1.5-SNAPSHOT.jar 8080 /jruby-examples/ 1 true
May 30, 2007 3:06:00 PM com.sun.grizzly.standalone.StaticResourcesAdapter 
INFO: Servicing page from: /ruby-examples/bs/public
May 30, 2007 3:06:00 PM com.sun.grizzly.http.SelectorThread displayConfiguration
INFO:
 Grizzly configuration for port 8080
         maxThreads: 20
         minThreads: 5
         ByteBuffer size: 8192
         useDirectByteBuffer: false
         useByteBufferView: false
         maxHttpHeaderSize: 8192
         maxKeepAliveRequests: 256
         keepAliveTimeoutInSeconds: 30
         Static File Cache enabled: false
         Stream Algorithm : com.sun.grizzly.standalone.StaticStreamAlgorithm
         Pipeline : com.sun.grizzly.http.LinkedListPipeline
         Round Robin Selector Algorithm enabled: false
         Round Robin Selector pool size: 0
         recycleTasks: true
         Asynchronous Request Processing enabled: true

Parking the request for 10 seconds
Resuming the request
May 30, 2007 3:06:13 PM sun.reflect.NativeMethodAccessorImpl invoke0
INFO:

Processing SayController#hello (for 192.168.0.105 at 2007-05-30 15:06:13) [GET]

May 30, 2007 3:06:13 PM sun.reflect.NativeMethodAccessorImpl invoke0
INFO:   Session ID: 0f21bd287851f72e1b0db90180053c7d

May 30, 2007 3:06:13 PM sun.reflect.NativeMethodAccessorImpl invoke0
INFO:   Parameters: {"action"=>"hello", "controller"=>"say"}
May 30, 2007 3:06:13 PM sun.reflect.NativeMethodAccessorImpl invoke0
INFO: Rendering say/hello
May 30, 2007 3:06:13 PM sun.reflect.NativeMethodAccessorImpl invoke0
INFO: Completed in 0.02100 (47 reqs/sec) | Rendering: 0.01500 (71%) 
| 200 OK [http://localhost/say/hello]

It doesn't yet support Comet, but its only because I don't have enough time to learn JRuby. But from this page, I suspect the Grizzly Comet API can be called from a JRuby application. What needs to be done is to write a re-usable JRuby based CometHandler JRuby applications can reuse for doing Comet based request. I think I need to start pinging the JRuby community for help as I really think JRuby + Comet will be popular.

When will be the official release? The Grizzly community will vote this week about the next release (1.5.1) and the good news is JRuby will be part of it. Also, Grizzly 1.5.1 will soon make its way to GlassFish v3, so you will get extra functionalities when deploying JRuby web application. As usual, feedback are welcome...by sending emails to users@grizzly.dev.java.net!

technorati:


Bookmark blog post: del.icio.us del.icio.us Digg Digg DZone DZone Furl Furl Reddit Reddit
Comments
Comments are listed in date ascending order (oldest first) | Post Comment

  • That sounds cool. One thing that's deterred me from pursuing Rails seriously is the lack of a decent server. I'll have to try this out.

    Posted by: erickson on May 31, 2007 at 01:38 PM

  • This is indeed pretty cool. One thing, though, When you say JRuby, you're really talking about Rails running on JRuby, right? JRuby is the language implementation (like Java), Rails is just a web framework that runs on top of JRuby (like Struts). I've noticed a tendency in the Glassfish v3 and Grizzly communities to confuse the two, and I'd hate to see that confusion spread further. There's a lot more to Java than Struts, and there's a lot more to JRuby than just Rails.

    Posted by: dudleyf on June 02, 2007 at 12:33 PM

  • Hi dudleyf, good point. I will make sure to not confuse more users :-) Thanks!

    Posted by: jfarcand on June 04, 2007 at 07:57 AM

  • just took grizzy on a ride. I find too slow. I have bin trying to run cookbook rial app on it but there some issues. Is there any detailed tutorial on run rails on jruby against grizzly. wld b grateful if i find one. i run jdk 1.6.
    this is d ouput i have got, am a kinda new to dis tngs.

    C:\ruby-dev\jruby-on-grizzly>java -jar jruby-1.5-SNAPSHOT.jar 8080 /C:/ruby-dev/
    jruby-on-grizzly/mephisto 1 true
    Jun 6, 2006 1:26:44 AM com.sun.grizzly.standalone.StaticResourcesAdapter
    INFO: Servicing page from: C:\ruby-dev\jruby-on-grizzly\mephisto\public
    C:/ruby-dev/jruby-1.0.0RC2/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:
    in `require': no such file to load -- initializer (LoadError)
    from C:/ruby-dev/jruby-1.0.0RC2/lib/ruby/site_ruby/1.8/rubygems/custom_r
    equire.rb:27:in `require'
    from /C:/ruby-dev/jruby-on-grizzly/mephisto/config/boot.rb:16
    from /C:/ruby-dev/jruby-on-grizzly/mephisto/config/environment.rb:13:in
    `require'
    from /C:/ruby-dev/jruby-on-grizzly/mephisto/config/environment.rb:13
    from :-1
    ...internal jruby stack elided...
    from org.jruby.Ruby.loadScript(Ruby.java:1163)
    from org.jruby.runtime.load.ExternalScript.load(ExternalScript.java:53)
    from org.jruby.runtime.load.LoadService.smartLoad(LoadService.java:307)
    from org.jruby.runtime.load.LoadService.require(LoadService.java:333)
    from com.sun.grizzly.jruby.RubyObjectPool.loadRubyLibraries(RubyObjectPo
    ol.java:146)
    from com.sun.grizzly.jruby.RubyObjectPool.start(RubyObjectPool.java:117)

    from com.sun.grizzly.jruby.RailsSelectorThread.initializeRubyRuntime(Rai
    lsSelectorThread.java:89)
    from com.sun.grizzly.jruby.RailsSelectorThread.initEndpoint(RailsSelecto
    rThread.java:54)
    from com.sun.grizzly.standalone.JRuby.main(JRuby.java:122)
    Jun 6, 2006 1:26:46 AM com.sun.grizzly.jruby.RailsSelectorThread initializeRubyR
    untime
    WARNING: null
    Jun 6, 2006 1:26:46 AM com.sun.grizzly.standalone.StaticResourcesAdapter
    INFO: Servicing page from: C:\ruby-dev\jruby-on-grizzly\mephisto\public
    Jun 6, 2006 1:26:46 AM com.sun.grizzly.http.SelectorThread displayConfiguration
    INFO:
    Grizzly configuration for port 8080
    maxThreads: 20
    minThreads: 5
    ByteBuffer size: 8192
    useDirectByteBuffer: false
    useByteBufferView: false
    maxHttpHeaderSize: 8192
    maxKeepAliveRequests: 256
    keepAliveTimeoutInSeconds: 30
    Static File Cache enabled: false
    Stream Algorithm : com.sun.grizzly.standalone.StaticStreamAlgorithm
    Pipeline : com.sun.grizzly.http.LinkedListPipeline
    Round Robin Selector Algorithm enabled: false
    Round Robin Selector pool size: 0
    recycleTasks: true
    Asynchronous Request Processing enabled: true

    Posted by: deenick007 on June 05, 2007 at 12:06 PM

  • I am not able to test drive this grizzly. It starts up fine but then it errors as below:

    java -cp C:\drivers\postgresql-8.2-505.jdbc3.jar -jar jruby-o
    n-grizzly\jruby-1.5-SNAPSHOT.jar 8080 C:/jruby/myapp/ 1 true


    Jun 12, 2007 2:52:02 PM com.sun.grizzly.standalone.StaticResourcesAdapter
    INFO: Servicing page from: C:\jruby\myapp\public
    .....
    The driver encountered an error: cannot load Java class org.postgresql.Driver
    ----------
    I tried copying the driver jar into $jruby_home/lib, $myapp/lib, myapp/lib/java, it didn't help.

    Posted by: sakthivelg on June 12, 2007 at 03:19 PM

  • deenick007:


    Try setting the GEM_HOME environment variable or ENV['GEM_HOME']
    within the rails app to the gems installation dir ie j/ruby-home/lib/ruby/gems/1.8

    Posted by: ahshishs on June 14, 2007 at 02:51 PM

  • sakthivelg:


    See https://grizzly.dev.java.net/issues/show_bug.cgi?id=6
    As a workaround you could try something like this (which is what I did for mysql jdbc driver)


    ## run this script as my-script 8888

    #!/bin/bash

    MYSQL_JAR=/abc/mysql-connector-java-5.0.4/mysql-connector-java-5.0.4-bin.jar
    GRIZZLY_JRUBY_HOME=/abc/tmp/grizzly/modules/jruby/
    GRIZZLY_CLASSES=`ls $GRIZZLY_JRUBY_HOME/*.jar`
    GRIZZLY_CLASSES=$GRIZZLY_CLASSES:`ls $GRIZZLY_JRUBY_HOME/lib/*.jar`
    GRIZZLY_CLASSES=`echo $GRIZZLY_CLASSES | tr -s ' ' ':'`
    GRIZZLY_CLASSES=$GRIZZLY_CLASSES:$GRIZZLY_JRUBY_HOME/target/classes

    CP=$MYSQL_JAR:$GRIZZLY_CLASSES
    java -classpath $CP com.sun.grizzly.standalone.JRuby $*
    ##EOF

    Posted by: ahshishs on June 14, 2007 at 02:52 PM



Only logged in users may post comments. Login Here.


Powered by
Movable Type 3.01D
 Feed java.net RSS Feeds