tags:

views:

26

answers:

2

I am setting up a Neo4j based system in jRuby running on glassfish. Glassfish as with most rails systems allows for some mechanism to run multiple instances. In glassfish case there is an internal setting for the thread pool size.

My issue is that I am having problems with the Neo4j database being opened more than once and this is causing an error. I am in the process of upgrading to Rails3 to pull in the latest Neo4j.rb but in the mean time wanted to assure I had the right server setup.

Below is my setup:

#
# GlassFish configuration.
#
# Please read the comments for each configuration settings before modifying.
#
# application environment. Default value development

environment: staging
# HTTP configuration
  http:
    # port
    port: 3000

    #address
    address: 0.0.0.0

    # context root. The default value is '/'
    contextroot: /

    # Grizzly is NIO based HTTP libraries used by GlassFish gem
    grizzly:
        chunking-enabled: true
        request-timeout: 30
        send-buffer-size: 8192
        max-keepalive-connextions: 256
        keepalive-timeout: 30
        thread-pool:
            idle-thread-timeout-seconds: 900
            max-queue-size: 4096
            max-thread-pool-size: 5
            min-thread-pool-size: 2                
#Logging configuration
log:
    log-level: all
jruby-runtime-pool:
    initial: 1
    min: 1
    max: 5
daemon:
    enable: true

jvm-options: -server -Xmx1024m -XX:PermSize=256m -XX:MaxPermSize=256m -XX:NewRatio=2 -XX:+DisableExplicitGC -Dhk2.file.directory.changeIntervalTimer=6000

A: 

The method Neo4j.start takes an optional Neo database instance. I haven't tried it but if you can experiment with ensuring that only one Neo instance gets created and make sure that each runtime looks for that shared instance first, your multiple runtime approach might work.

Where to put the shared instance? If you were running in a servlet context you could put it in a servlet context attribute. Since you're not, the best way would probably be to write a small Java wrapper class for starting and storing the single instance, and importing that Java class into each runtime.

Nick Sieger
+1  A: 

You can try setting the jruby-runtime-pool max value to 1 instead (have not tested this). If you are running a multithreaded application (like rails 3 and Neo4j) I think there is no need to use more then one jruby-runtime, right ?

Andreas Ronge
Yes, I had set my configuration to multiple servers as I would have done with native ruby implementation. I did some followup reading on multi-threaded rails as well. Rails starting in Rails 2.2 or 2.3 introduced better threading support, but you have to enable it by uncommenting the threading line in your production.rb environment file. As a note, I got 3x the throughput by changing this setting and using just the 1 instance as noted in the response above. I did bump up my default thread count as well, but there are open file implications to that, so I am still tinkering with that value.
Bill Leeper