Skip to main content

GlassFish/JRuby and NetBeans/Ruby Q&A - San Francisco

Posted by arungupta on January 8, 2008 at 6:14 AM PST

Pramod
and I presented on href="http://wiki.glassfish.java.net/Wiki.jsp?page=JRuby">GlassFish/JRuby
and NetBeans/Ruby
to a partner in San Francisco a few days ago. Here are the questions
asked during the session:

  1. How does
    running the Ruby tests show the green/red status bar ?




    The
    status bar is shown if the test is run as a test, not as a file. (for
    example, using Ctrl+F6, not Shift+F6). Ctrl+F6 can also be invoked on
    the tested class
    and it will run the associated tests for the class. This is the same
    behavior when rake "test" target is invoked.
  2. How fast is
    it to find Ruby arbitrary types in particularly large projects ?




    It's
    almost instantaneous and can be achieved using Ctrl+O. It looks at
    project's classes, all the Ruby classes for the built-in libraries, all
    of Ruby-on-Rails, RSpec and all other gems.
  3. Is it
    possible to navigate between Ruby class and tests ?




    Yes, this can be achieved by using Ctrl+Shift+T keyboard shortcut.
  4. Is it
    possible to fix shadowing of variables inside a block of code ?




    Ruby shadows block variables by default.  If you have the
    following code:

     

    foo = 5

    [1,2,3].each { |foo|  puts foo }

    puts foo

     

    Then
    the block variable "foo" shadows the outer local variable and after
    running this code the local variable foo is equal to 3.



    If you enter this code in NetBeans it will pinpoint this problem
    and offer a quickfix to resolve it as shown below:



    alt="NetBeans 6 Ruby Shadow Variable"
    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6-ruby-shadow-variable.png">
  5. Are comments
    added on a new class seen in the context-sensitive help option ?




    Yes, new methods and comments are all shown in the popup rdocs.
  6. How easy is
    it rename method across main, test and other referring classes ?




    Method
    rename, just like variable rename, can be invoked by selecting the
    method name and invoking Ctrl+R or right-clicking and selecting
    "Rename" as shown below.



    alt="Ruby Method rename"
    src="http://blogs.sun.com/arungupta/resource/netbeans/nb6-ruby-method-rename.png">
  7. Can Ruby code
    templates be loaded from an external file on the file system ?




    href="http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=1157">Install
    href="http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=1616">NetBeans
    Plugin Portal Update Center first and then install href="http://plugins.netbeans.org/PluginPortal/faces/PluginDetailPage.jsp?pluginid=1157">Code
    Template Tools Module. This module allows to import templates
    from an XML-based configuration file.   
  8. Would NB pick
    up dynamic code that is being generated during project execution ?




    Yes and No.  This problem cannot be solved in general as is an
    NP hard
    problem and reduces to the href="http://en.wikipedia.org/wiki/Halting_problem">Halting
    problem.  However, since Rails follows
    many conventions, we can solve it for those typical
    conventions. Thus, lots of dynamic classes created by Rails, such as
    active record classes, are included in code completion - see
    for example href="http://blogs.sun.com/tor/entry/ruby_screenshot_of_the_week20">Ruby
    Screenshot of Week 20. The
    finder  methods included in completion (find_by_price etc.)
    shown in the blog entry are examples of these dynamic things.



    Support for has_many and other similar attributes can be easily added
    as well. Please file an href="http://www.netbeans.org/issues/enter_bug.cgi?component=ruby">RFE.
  9. What are the
    plans for JRuby based
    debugger in NB ?




    The
    Ruby debugger currently only works well with C
    Ruby.   It
    does work with JRuby as well, but it's extremely slow (because
    there isn't a "fast debugger hooks" implementation available
    yet),
    so it's not practical for debugging large apps like Rails -
    but
    it's fine for smaller Ruby script> etc. With C Ruby it's
    blazingly
    fast.



    Work is underway to make the fast hooks work with JRuby as well and
    it's href="http://mysterycoder.blogspot.com/2007/10/debugging-jruby-on-rails-app-with-jruby.html">available
    with some duct tape.
  10. How can
    concurrency across multiple machines be achieved ?




    GlassFish can be front-ended with a Load Balancer to achieve concurrent
    applications. Read more details href="https://glassfish.dev.java.net/javaee5/lb-admin/">here.
  11. Can
    GlassFish support multiple Rails versions ?




    Yes, href="http://blogs.sun.com/arungupta/entry/screencast_web_9_jruby_on">JRuby
    module on GlassFish Update Center allows to create style="font-style: italic;">stand-alone or style="font-style: italic;">shared WAR. A
    stand-alone WAR is self-contained and has all the libraries, gems
    & plugins required by the application. A shared WAR has only
    application specific libraries and all other classes are loaded from
    the classpath of GlassFish Application Server instance.



    Mutiple stand-alone WARs can be deployed on the same instance of
    GlassFsh. Alternatively, multiple GlassFish instances, each configured
    with a different Rails version, can be configured on one/multiple
    machines. These instances can be front-ended by a Load Balancer.
  12. In the
    GlassFish case, will the threads supporting the Rails instances share
    the variables or
    is it standalone ?




    Every
    request would happen inside its own Rails instance, and there would be
    no sharing during requests. The deployment model is largely the same as
    with mongrels, but without the mongrels.
  13. During record
    migration the associated Active Records need
    to be refreshed. How is this done as part
    of the hot deployment cycle ?




    A shim can be written that run the migrations upon deploy of the WAR
    file. There's a precedence for this
    sort of thing, with products like JIRA that do a database scan at
    startup to make sure you're running the correct version of the tables.
    It's not going to be for everybody, but if you have full control of
    your deployment it's a nice convenience.
  14. What
    advantages does JRuby-on-GlassFish offer to smaller enterprises ?




    GlassFish offers several advantages to enterprises:

    • Allows RoR and Java EE applications to
      co-exist on the same container.
    • Simpler/Similar development/deployment model
    • Database connection pooling
    • Hot deployment of WAR (no need to restart the container)



    And then of course, all the advantages of Load Balancing, Clustering,
    High Availability are available for further scalability as well.

  15. What are the
    benchmark numbers on JRuby ?




    Here are some of the pointers:



    http://blog.nicksieger.com/articles/2007/10/25/jruby-on-rails-fast-enough

    http://blog.nicksieger.com/articles/2007/10/25/jruby-performance-tweaks

    http://shootout.alioth.debian.org/gp4sandbox/benchmark.php?test=all&lang...

    http://antoniocangiano.com/2007/12/03/the-great-ruby-shootout/



    And
    around 1.1 there will be consolidated numbers for all the benchmarks.
    Performance has improved again since all these sets were
    published.
  16. When
    would 1.8.6 support be introduced in JRuby ?




    There are plans to update stdlib in JRuby 1.1 - that's really all is
    meant by 1.8.5 support, since largely that's all that's changed.
  17. How is load
    balancing configured in GlassFish ?




    A cluster of GlassFish instances can be load-balanced using any of the
    following approaches:


    • href="https://glassfish.dev.java.net/javaee5/build/GlassFish_LB_Cluster.html#config_lb">Sun
      LB plug-in on Sun Web Server, Apache and IIS
    • href="http://weblogs.java.net/blog/jfarcand/archive/2006/03/running_glassfi_1.html">Apache
      (mod_jk)
    • href="http://www.sun.com/bigadmin/features/articles/configure_big_ip.html">F5
    • href="http://www.sun.com/products/neworking/switches">Sun
      Secure Application Switch



    Read more about how to href="https://glassfish.dev.java.net/javaee5/build/GlassFish_LB_Cluster.html">setup/configure
    load balancer with GlasFish v2.

  18. How does
    GlassFish deal with
    caching of pages ?




    The file cache in Grizzly provides caching where static pages are
    served without talking to the Web server. 
  19. What is the
    state
    of Rubinius support in JRuby ?




    The state of Rubinius (and other Ruby implementations) is described at
    http://headius.blogspot.com/2007/11/top-five-questions-i-get-asked.html.
    Also read a more recent update href="http://on-ruby.blogspot.com/2007/12/rubinius-on-jruby.html">here.



    There are no further updates on Rubinius bytecode support since
    Rubinius bytecode seems to be still changing. We've also managed to
    improve normal interpreted performance, so we're happy enough that
    installing a new bytecode engine hasn't been a priority.



    The JRuby team occasionally plays with getting Rubinius's
    implementations of various
    core classes to run in JRuby, and they usually work well but with about
    a 2x performance hit.
  20. Are there any
    benchmarks on the speed of static pages between GlassFish (Grizzly) and
    Apache ?




    Yes, the benchmarks are available href="http://weblogs.java.net/blog/sdo/archive/2007/05/how_to_test_con.html">here.

Thanks to Tor,
Sandip, href="http://headius.blogspot.com/">Charles, href="http://blog.nicksieger.com/">Nick, href="http://weblogs.java.net/blog/jfarcand/">Jean-Francois
and Jan
for helping with the answers. And href="http://blogs.sun.com/pramodg">Pramod to help
me with noting the questions.

Technorati: href="http://technorati.com/tag/conf">conf href="http://technorati.com/tag/glassfish">glassfish
ruby href="http://technorati.com/tag/jruby">jruby href="http://technorati.com/tag/neteans">netbeans href="http://technorati.com/tag/rubyonrails">rubyonrails
q&a

Related Topics >>