Forum: JRuby Hello, Nailgun; Goodbye, JVM Startup Delays

Posted by Keith B. (keith_b)
on 2012-09-15 18:14
(Received via mailing list)
All -

I wrote a blog article, " Hello, Nailgun; Goodbye, JVM Startup Delays",
which suggests a strategy for easily using Nailgun with gem, rspec, etc.
The article is at
http://www.bbs-software.com/blog/2012/09/15/hello-....

In it I mention some problems specifying certain options on the command
line or in the JRUBY_OPTS environment variable, and some Jira issues
about that.

I would greatly appreciate any feedback, including corrections, which I
would incorporate into the article.

Thanks,
Keith
Posted by Msan Msan (msan)
on 2012-09-22 15:54
(Received via mailing list)
On 15 September 2012 18:13, Keith Bennett <keithrbennett@gmail.com> 
wrote:
> I would greatly appreciate any feedback, including corrections, which I
> would incorporate into the article.

I've installed nailgun then jruby --ng-server but I don't understand
how to launch rails webserver, rails s.
Posted by Keith B. (keith_b)
on 2012-09-22 16:32
(Received via mailing list)
If you're running on a Unix variant (Mac OS, Linux), try including
"--ng" in the value of the environment variable JRUBY_OPTS.  One way to
do this would be on the command line itself:

JRUBY_OPTS=--ng rails ...

You'd need to add any additional stuff to JRUBY_OPTS that you were
already using, so you could do:

JRUBY_OPTS="--ng --1.9" rails ...

There are other ways too, such as:

export JRUBY_OPTS="$JRUBY_OPTS --ng"
rails ...

Did you try the strategy suggested in the article and have a problem?
What have you tried, and what happened?  What OS are you using?  What
version of JRuby?

- Keith

--
Keith R. Bennett
http://about.me/keithrbennett
Posted by Msan Msan (msan)
on 2012-09-22 18:21
(Received via mailing list)
On 22 September 2012 16:31, Keith Bennett <keithrbennett@gmail.com> 
wrote:
>
> There are other ways too, such as:
>
> export JRUBY_OPTS="$JRUBY_OPTS --ng"
> rails ...
>
> Did you try the strategy suggested in the article and have a problem?  What
> have you tried, and what happened?  What OS are you using?  What version of
> JRuby?


I'm using linux debian.
jruby -v
jruby 1.6.8 (ruby-1.9.2-p312) (2012-09-18 1772b40) (OpenJDK 64-Bit
Server VM 1.6.0_24) [linux-amd64-java]

I've run jruby --ng-server and the server starts.
First to set bash profiles I've tried to run from command line.
rails s starts but it seems not to use nailgun.
jruby --ng rails s says:
ng executable not found.
How to run rails s from command line to use nailgun?
Posted by Robin McKay (robin2)
on 2012-09-22 20:26
I've had exactly the same result as MSAN when I tried jruby --ng
myprog.rb

Without Nailgun jruby myprog.rb works perfectly. (Xubuntu 12.04)

Perhaps someone could explain what adding --ng to JRUBY_OPTS does.
Normally I don't do anything with that variable and 'echo $JRUBY_OPTS'
returns a blank line.

Does it matter to Nailgun where the JRuby interpreter is located?
Posted by Keith B. (keith_b)
on 2012-09-23 00:34
(Received via mailing list)
Mauro -

Rails is an executable command, like rake and rspec, that itself
starts up jruby.

Thus, there is no need to specify jruby on the rails command line.

When calling jruby itself, you can specify an option on the command
line, or in the JRUBY_OPTS environment variable.

When calling a JRuby executable like rails, I doubt that the command
line approach will work, so we need to use the JRUBY_OPTS approach.

Try issuing this command on your command line:

JRUBY_OPTS=--ng rails -v

My article explained how to easily set up some scripts that would make
this even more painless.  If you have the time to explore that, it
would simplify this for you.

- Keith
Posted by Keith B. (keith_b)
on 2012-09-23 00:44
(Received via mailing list)
Robin -


On Sat, Sep 22, 2012 at 2:26 PM, Robin McKay <lists@ruby-forum.com> 
wrote:
> I've had exactly the same result as MSAN when I tried jruby --ng
> myprog.rb

You said that you had exactly the same result as Mauro, but I don't
see the similarity in what you and he were trying to do, since he was
running an executable that itself calls jruby, and you're running a
Ruby script.

Could you post here the exact command you're using, and the resulting 
output?


>
> Without Nailgun jruby myprog.rb works perfectly. (Xubuntu 12.04)
>
> Perhaps someone could explain what adding --ng to JRUBY_OPTS does.
> Normally I don't do anything with that variable and 'echo $JRUBY_OPTS'
> returns a blank line.


Please see the reply I just sent to Mauro for more on this.  When you
add --ng to JRUBY_OPTS , JRuby sees that you want to run it in a
Nailgun server, and does so.  This is pretty amazing, because you can
be running dozens of tasks in a Nailgun server, and only one JVM is
doing it.  You can verify this by running jvisualvm (comes with the
JDK), and noting the JVM's it finds (displayed on the left side)
(anyone know a way to display all running JVM's on the command line?).
 If you run irb without Nailgun, you'll see a new JVM there; but if
you run irb with Nailgun, you'll see that no new JVM shows up.


> Does it matter to Nailgun where the JRuby interpreter is located?

No.  The JRuby installation *includes* Nailgun, and when you ask JRuby
to use Nailgun, it knows where to find it.

- Keith
Posted by Msan Msan (msan)
on 2012-09-23 11:54
(Received via mailing list)
JRUBY_OPTS=--ng rails -v
error: ng executable not found;
Posted by Robin McKay (robin2)
on 2012-09-23 12:48
I'm no further on.

If I do "jruby --ng-server" in a terminal it then says "NGServer started
on all interfaces, port 2113."

If I do "jruby --ng test1.rb" in the same terminal nothing happens.

If I open a new terminal and do "jruby --ng test1.rb" in it I get
"error: ng executable not found"

Which is exactly the same result as MSAN is getting.

The file test1.rb contains the following:

   #  this is just to demo that jruby works

   x = 5
   y = 7
   b = x * y
   puts
   puts "test1.rb"
   puts
   puts "X #{x}   Y #{y}   B #{b}"
   puts
Posted by Keith B. (keith_b)
on 2012-09-23 17:12
(Received via mailing list)
Robin and Mauro -

Thanks for the additional information.

I searched through the JRuby source code, and found this in 
bin/jruby.sh:

   if [ -f $JRUBY_HOME/tool/nailgun/ng ]; then
     exec $JRUBY_HOME/tool/nailgun/ng org.jruby.util.NailMain
$JRUBY_OPTS "$@"
   else
     echo "error: ng executable not found; run 'make' in
${JRUBY_HOME}/tool/nailgun"
     exit 1
   fi

Could you try running make in the appropriate directory and see if it
succeeds in building ng?

I installed JRuby using rvm, and I think I remember seeing it build
Nailgun as part of the installation.  If you're not using rvm, I'd
highly recommend it, though of course this should not be necessary to
get Nailgun to work.  Installation instructions are at
https://rvm.io/rvm/install/.  After it's installed, install JRuby with
'rvm install jruby'.

A brief Google search for "JRuby Nailgun bug" didn't turn up anything
that looked relevant to your situation, so having to build Nailgun
manually may be the intended behavior, I don't know.

Robin, when you start the server in a terminal, the server receives any
keyboard input; that input is not being interpreted by the shell.  If
you add "&" to the command line when starting the server, the server
will start and go to the background so that the terminal can accept
input normally.  You can bring it back to the foreground with the 'fg'
command. Personally, I leave it alone and don't use that terminal for
anything else; that makes it easier for me to find when I want to kill
it, since I typically have many shells running.

- Keith


Keith R. Bennett
http://about.me/keithrbennett
Posted by Msan Msan (msan)
on 2012-09-23 21:51
(Received via mailing list)
I have a debian on amd-64.
When I run make it says:
make: *** No targets specified and no makefile found.  Stop.
Posted by Keith B. (keith_b)
on 2012-09-24 02:39
(Received via mailing list)
What directory are you in when you run make?

You need to be in $JRUBY_HOME/tool/nailgun.

- Keith
Posted by Msan Msan (msan)
on 2012-09-24 08:28
(Received via mailing list)
On 24 September 2012 02:38, Keith Bennett <keithrbennett@gmail.com> 
wrote:
> What directory are you in when you run make?
>
> You need to be in $JRUBY_HOME/tool/nailgun.

Yes I'm in that directory.
Posted by Robin McKay (robin2)
on 2012-09-24 10:19
There is a shell script called configure in my /tools/nailgun directory.
When I did "./configure" it created some files and then I could do
"make" and it worked. After that  "jruby --ng test1.rb" worked, and it
does load faster.

Thank you Keith_b for taking the trouble to explore jruby.sh, but it
shouldn't have been necessary.

This is typical of the poor documentation in open-source software - the
amount of time that users waste trying to figure out this sort of thing
would probably pay for two or three copies of Windows. Heresy, I know,
but probably true.

Also, why couldn't the Nailgun developers make a product that doesn't
need these steps?
Posted by James Abley (Guest)
on 2012-09-24 10:29
(Received via mailing list)
On 24 September 2012 09:19, Robin McKay <lists@ruby-forum.com> wrote:

> There is a shell script called configure in my /tools/nailgun directory.
> When I did "./configure" it created some files and then I could do
> "make" and it worked. After that  "jruby --ng test1.rb" worked, and it
> does load faster.
>

This is a standard UNIX dance.

http://en.wikipedia.org/wiki/Configure_script


>
> Thank you Keith_b for taking the trouble to explore jruby.sh, but it
> shouldn't have been necessary.
>
> This is typical of the poor documentation in open-source software - the
> amount of time that users waste trying to figure out this sort of thing
> would probably pay for two or three copies of Windows. Heresy, I know,
> not probably true.
>
>
A benefit of open-source software is that you contribute, if you feel 
that
something could be improved.

http://jruby.org/contribute

You then get to experience the internal glow of knowing that you helped
make something a little bit better for people around the world!

Cheers,

James


> Also, why couldn't the Nailgun developers make a product that doesn't
> need these steps?
Posted by Msan Msan (msan)
on 2012-09-24 10:45
(Received via mailing list)
On 24 September 2012 10:19, Robin McKay <lists@ruby-forum.com> wrote:
> There is a shell script called configure in my /tools/nailgun directory.
> When I did "./configure" it created some files and then I could do
> "make" and it worked. After that  "jruby --ng test1.rb" worked, and it
> does load faster.

Damn, my wrong.
Of course.....I've to run configure first.
Posted by Msan Msan (msan)
on 2012-09-24 10:51
(Received via mailing list)
Other problem:

JRUBY_OPTS=--ng rails s
Gemfile syntax error:

gem 'formtastic', :git =>
'git://github.com/justinfrench/formtastic.git', branch: '2.1-stable'

with rails s I don't have this error.
Posted by Robin McKay (robin2)
on 2012-09-24 11:16
I have now tried using Nailgun with a "proper" program - a photoviewer I
am developing for my own use that uses Swing to display stuff - and it
doesn't work properly. Strange things seem to happen to the menus and it
stops with no warning after 6 or 7 navigation button clicks.

I might try Nailgun again in a few years when it is fixed!

I disagree with James Abley's "A benefit of open-source software is that
you contribute ... You then get to experience the internal glow ..."

If I want to contribute to Open Source software it should be on a
voluntary basis "because I want to" rather than "because I have to".

I quite understand that people may develop "incomplete" software and
make it available "as is" and it may or may not be useful to me. I hope,
however, that if I did so I would provide enough documentation so that
users could understand the limitations or the product would be small
enough that a user could read through it and figure out what changes
might be needed.

I don't see Ruby, JRuby or Java in this category. These products are far
too complex for the "ordinary" user to figure out and correct problems.
Posted by Tim Uckun (Guest)
on 2012-09-24 11:43
(Received via mailing list)
>
> I don't see Ruby, JRuby or Java in this category. These products are far
> too complex for the "ordinary" user to figure out and correct problems.
>


Not sure if you are trolling or not but...

Your experiences with ng have nothing to do with ruby or java or even
jruby. Besides none of these things are meant to be used by "ordinary"
users, they are programming languages meant to be used by programmers.

If ng is broke feel free to file a ticket. Without bug reports how are
they going to know what to fix?
Posted by Keith B. (keith_b)
on 2012-09-24 15:19
(Received via mailing list)
Robin -

Bravo for figuring that out.

I agree with you that this looks like an issue that needs addressing.

However:

* We must never forget that open source software is a gift, provided
mostly by people who donate their free time.  We are not "entitled" to
anything. We should feel humbled by, and grateful for, their generosity,
and hopefully even be motivated to give of ourselves as well.

* We beneficiaries of this are responsible to do our part -- in this
case, as was suggested, to file a bug report.  This will take a little
time, especially if done right -- that is, expressed precisely, clearly,
and with examples, and with a search first to see if the issue has
already been reported. That is one small but helpful thing we can do to
assist the authors.  Even better would be to write up the documentation
you wish would have been there, and include a link to it in the bug 
report.

* Nailgun is a tool, and is not suitable for all purposes.  Its strength
is running large numbers of short-lived jobs, and is not really
appropriate in my opinion for a Swing app. Why don't the JRuby docs say
that? It is a Java tool that was adapted to JRuby by the JRuby
developers.  Nailgun has its own home page, at
http://www.martiansoftware.com/nailgun/.

* Despite the occasional rough edge, JRuby is an awesome product. The
.Net world lost their Ruby implementation (Iron Ruby) a while back.  I'm
grateful that we have JRuby for the JVM. The Nailgun integration is not
a strictly necessary part of the JRuby project, but is a very handy
addition.  And, using rvm, it works out of the box.

- Keith

Keith R. Bennett
http://about.me/keithrbennett
Posted by James Abley (Guest)
on 2012-09-24 15:56
(Received via mailing list)
On 24 September 2012 14:16, Keith Bennett <keithrbennett@gmail.com> 
wrote:

> anything. We should feel humbled by, and grateful for, their generosity,
> and hopefully even be motivated to give of ourselves as well.
>

> * We beneficiaries of this are responsible to do our part -- in this case,
> as was suggested, to file a bug report.  This will take a little time,
> especially if done right -- that is, expressed precisely, clearly, and with
> examples, and with a search first to see if the issue has already been
> reported. That is one small but helpful thing we can do to assist the
> authors.  Even better would be to write up the documentation you wish would
> have been there, and include a link to it in the bug report.
>

Nicely put Keith. There was a minor typo in my email. I meant to say 
"you
can contribute, if you feel...". Obviously, it's not mandatory, and not
everyone has the time, motivation or skills necessary to do so.
Posted by Keith B. (keith_b)
on 2012-09-24 15:59
(Received via mailing list)
James -

Agreed.

- Keith
Posted by Hassan Schroeder (Guest)
on 2012-09-24 17:18
(Received via mailing list)
On Mon, Sep 24, 2012 at 6:16 AM, Keith Bennett <keithrbennett@gmail.com> 
wrote:

> using rvm, it works out of the box.

Not sure I'd go that far :-)

Out of curiousity fiddled with this a little yesterday. On my Mac OS X
(10.7.5) running various JRuby versions included 1.7.0.preview2, I
can start the ng server fine, and starting e.g. irb is quick -- but 
that's
as far as it goes. Even something as simple as `puts 'foo'` simply
hangs. (def hangs = till my patience runs out and I CTRL-C it).

I no longer have a client using JRuby so I'm not eager to put a lot of
time into figuring it out, but "works out of the box" certainly doesn't
apply to my experience...

FWIW,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Posted by Robin McKay (robin2)
on 2012-09-24 18:45
I've had a look at the nailgun website now and it makes no pretence to
being a "solid" product --
  "In other words, consider this a platform for experiments."

Its probably my fault but I didn't get that impression from the original 
post here or from the link on it.

I am a very strong believer in JRuby - but I am rather disappointed that
it continues to live in the shadow of MRI Ruby even though it has many
additional strengths and can be so much simpler to use. I will happily 
put up with the startup delay.
Posted by Keith B. (keith_b)
on 2012-09-24 23:42
(Received via mailing list)
Hassan -

I wish we could get more data points...it seems like you and I are the 
only ones in this discussion who have used Nailgun with rvm.

It would be interesting if you could at least revisit your problem 
enough to show me a command line that hangs.  (You didn't type it in the 
same terminal in which you ran the server, did you?)

And the puts foo didn't really have backticks, did it?  How about if you 
try something like this?:

jruby --ng -e "puts(123)"

If it's at all possible that it wasn't a Nailgun bug, then we may be 
unfairly condemning Nailgun.

To Robin and Mauro, if you have the curiosity and the time (it only 
takes a few minutes), it would be interesting to see if you have those 
problems with JRuby installed with rvm.

- Keith
Posted by Hassan Schroeder (Guest)
on 2012-09-25 00:05
(Received via mailing list)
On Mon, Sep 24, 2012 at 2:29 PM, Keith Bennett <keithrbennett@gmail.com> 
wrote:

> I wish we could get more data points...it seems like you and I are the only ones 
in this discussion who have used Nailgun with rvm.

14:55 ~ $ cd projects/testcases/jruby/pogo
Using /Users/hassan/.rvm/gems/jruby-1.7.0.preview2 with gemset pogo
14:55 ~/projects/testcases/jruby/pogo $ jruby --ng-server
NGServer started on all interfaces, port 2113.


// Open another terminal tab:

14:56 ~ $ cd projects/testcases/jruby/pogo
Using /Users/hassan/.rvm/gems/jruby-1.7.0.preview2 with gemset pogo
14:56 ~/projects/testcases/jruby/pogo $ jruby --ng -S irb
jruby-1.7.0.preview2 :001 > puts "123"

Over 2 minutes later, nothing further has happened...

Let me know if there's something I can do to expand on that :-)

And for the record:

rvm 1.10.3

java version "1.6.0_35"
Java(TM) SE Runtime Environment (build 1.6.0_35-b10-428-11M3811)
Java HotSpot(TM) 64-Bit Server VM (build 20.10-b01-428, mixed mode)

H*
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Posted by Msan Msan (msan)
on 2012-09-25 08:41
(Received via mailing list)
On 24 September 2012 23:29, Keith Bennett <keithrbennett@gmail.com> 
wrote:
> If it's at all possible that it wasn't a Nailgun bug, then we may be unfairly 
condemning Nailgun.
>
> To Robin and Mauro, if you have the curiosity and the time (it only takes a few 
minutes), it would be interesting to see if you have those problems with JRuby 
installed with rvm.

I don't use rvm.
Posted by Robin McKay (robin2)
on 2012-09-26 09:22
Msan Msan wrote in post #1077405:

> To Robin and Mauro, if you have the curiosity and the time (it only takes a few
> minutes), it would be interesting to see if you have those problems with
> JRuby
> installed with rvm.

Sorry, I don't use RVM - its not necessary with JRuby though it was
essential back in the day when I used MRI Ruby and had not discovered
the delights of JRuby.

And (to return to a different theme) RVM has great documentation.
Posted by Hassan Schroeder (Guest)
on 2012-09-26 16:40
(Received via mailing list)
On Wed, Sep 26, 2012 at 12:22 AM, Robin McKay <lists@ruby-forum.com> 
wrote:

> Sorry, I don't use RVM - its not necessary with JRuby though it was
> essential back in the day when I used MRI Ruby and had not discovered
> the delights of JRuby.

Apologies for the thread semi-hijacking :-) but --

MRI vs. JRuby seems totally orthogonal to using RVM (or not).
Can you explain?

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
http://about.me/hassanschroeder
twitter: @hassan
Posted by Robin McKay (robin2)
on 2012-09-26 20:06
> Hassan Schroeder wrote in post #1077631:
>
> MRI vs. JRuby seems totally orthogonal to using RVM (or not).
> Can you explain?

Very simple.

I have a copy of the downloaded the JRuby .zip (or tar.gz) file. If I
want to start a new JRuby project I just create a new directory for it
and extract the .zip into it. If I have a few versions downloaded I can
extract whichever version I want. I have a short shell script which I
double-click to open a terminal at the project directory with the JRuby
/bin directory in the path. Then everything just works - jruby -v and
gem install xxx for example. Each project is completely self contained.
If I want to run the project on another computer (including on Windows)
I can just copy the whole project directory. The other computer just
needs the JVM.

As far as I know you can't install MRI Ruby like that - hence the need
for RVM which makes managing MRI Ruby pretty painless.

And you certainly can't easily copy an MRI Ruby project to another
computer.
Posted by Tim Uckun (Guest)
on 2012-09-27 03:51
(Received via mailing list)
>
> As far as I know you can't install MRI Ruby like that - hence the need
> for RVM which makes managing MRI Ruby pretty painless.

Actually I once did that with ruby on windows. I copied everything
over except the RI, docs etc as well as some libs I didn't need and it
worked great. I think it was about 10 megs or so but there was a lot
of gems in there too.

I am sure the same thing can be done on linux but I haven't tried it.
I am pretty sure it's possible to have a completely isolated ruby and
gem env if you want to waste the disk space.


>
> And you certainly can't easily copy an MRI Ruby project to another
> computer.

You can fudge it if it's the same architecture especially with bundler
but it's not the same level of ease as the JVM provides.
Posted by Robin McKay (robin2)
on 2012-09-27 11:01
> Tim Uckun wrote in post #1077701:

> ... if you want to waste the disk space.
>

If you can buy a 500GB drive for £50 then 20Mb of disk space costs less
than a penny. How much of your time should you waste trying to save a
penny?

>
>>
>> And you certainly can't easily copy an MRI Ruby project to another
>> computer.
>
> You can fudge it if it's the same architecture especially with bundler
> but it's not the same level of ease as the JVM provides.

My ideal is to have something you can give to Aunt Bertha on a USB stick
which she sticks in her laptop and double-clicks and "it just works".
You can do that with JRuby (including with a Swing GUI program) but I 
have never heard anyone suggest you can do it with MRI Ruby.

[Ok you may have to talk Aunt Bertha through downloading the JVM - but
that's easy-peasy compared to RVM, MRI Ruby, Bundler etc.]
Posted by Tim Uckun (Guest)
on 2012-09-27 12:42
(Received via mailing list)
>
> My ideal is to have something you can give to Aunt Bertha on a USB stick
> which she sticks in her laptop and double-clicks and "it just works".
> You can do that with JRuby (including with a Swing GUI program) but I
> have never heard anyone suggest you can do it with MRI Ruby.

That's exactly what I did on windows. It was a self contained
directory which contained the app, ruby, all the gems you needed to
run your app.  I think the same thing might be possible in linux if
the architecture is the same.

>
> [Ok you may have to talk Aunt Bertha through downloading the JVM - but
> that's easy-peasy compared to RVM, MRI Ruby, Bundler etc.]
>

The JVM erases all the architecture problems and makes it a lot easier.
Posted by Robin McKay (robin2)
on 2012-09-27 20:33
> Tim Uckun wrote in post #1077749:

>
> That's exactly what I did on windows. It was a self contained
> directory which contained the app, ruby, all the gems you needed to
> run your app.  I think the same thing might be possible in linux if
> the architecture is the same.
>

I presume you were using JRuby.

The JRuby test (or demo) app that I created ran on Windows (both XP and
7) unchanged from the Ubuntu version. The only thing I needed to do was
to create a Windows batch file that was equivalent to the Ubuntu shell
script.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.