News for hackers. Stuff that matters.
Re:Fast JVM launching without the hassle of persistent JVMs by 6ren on Saturday November 17, 2012 @10:45AM (#4798279)
So obvious, trade-off space for time, yet I wouldn't have thought of it... I mean, I've thought about this problem, written a persistent JVM solution, and didn't think of it. Memory is cheaper than my intuition realises.

I wonder how many other "obvious" solutions I'm missing like this?

EDIT for the code I tried, user time is almost 3 times faster, but real time is only around 10% better... I don't understand linux well enough to know why - anyone care to explain please? EDIT Yes, drip had already run. (I picked typical times from about 10 runs each).

   $ time java...
  real	0m1.466s
  user	0m1.216s
  sys	0m0.180s

   $ time drip...
  real	0m1.378s
  user	0m0.412s
  sys	0m0.260s
BTW: For server-like workloads, an advantage of a persistent JVM is that it gets dramatically faster over repeated runs of the same code, as it improves its hotspot-style adaptive optimisations.

I really like his quickstart "standalone" installation.

WARNING "drip kill" crashed my system. The kill functions are kill_jvms and kill_jvm (https://github.com/flatland/drip/blob/develop/bin/drip). I'm using an older ubuntu 10.04 LTS.

Re:Fast JVM launching without the hassle of persistent JVMs by bretthoerner on Saturday November 17, 2012 @11:25AM (#4798384)
Did you do two exact same drip runs in a row? It has to hash and preload a JVM with the same classpath setup to work.

    $ time java -jar clojure-1.3.0.jar add_1_and_1.clj 
     
    real	0m0.690s
    user	0m0.827s
    sys	0m0.030s
     
    $ time drip -jar clojure-1.3.0.jar add_1_and_1.clj 
     
    real	0m0.879s
    user	0m1.020s
    sys	0m0.040s
     
    $ time drip -jar clojure-1.3.0.jar add_1_and_1.clj 
     
    real	0m0.177s
    user	0m0.033s
    sys	0m0.020s
     
    $ time drip -jar clojure-1.3.0.jar add_1_and_1.clj 
     
    real	0m0.176s
    user	0m0.050s
    sys	0m0.017s
Re:Fast JVM launching without the hassle of persistent JVMs by honr on Saturday November 17, 2012 @11:17AM (#4798365)
Interesting idea (especially, hashing based on command line options, and probably also the libraries in the classpath); I should add this to Clove (http://hovel.ca/clove : a small persistent-jvm that I wrote for *nix, with VERY fast connection time, e.g. suitable for scripts; sorry for shameless plug).
Re:Fast JVM launching without the hassle of persistent JVMs by wiradikusuma on Saturday November 17, 2012 @12:26PM (#4798524)
hey, nice project! how does this relate to drip? e.g. alternative or addition?
Re:Fast JVM launching without the hassle of persistent JVMs by honr on Saturday November 17, 2012 @02:45PM (#4798872)
They do slightly different things. I think each can benefit by incorporating the main idea of the other:

- Working on multiple projects who need different JVMs running at the same time can be a hassle in clove (you have to create a service for each), so it can be fixed by doing that the same way drip does.

- Running scripts and having a persistent JVM is still very useful, and clove (albeit I haven't cleaned up its code properly) gives a terminal into the JVM, really fast. So, drip can use the same technique (passing capabilities; a *nix feature) to let you hook into a JVM very quickly. [see the "screenshot" part at the bottom of http://hovel.ca/clove]

Re:Fast JVM launching without the hassle of persistent JVMs by mitchi on Saturday November 17, 2012 @12:01PM (#4798467)
I read his explanation but I don't have a great understanding of why a JVM would need to clean up like this. Doesn't it have a Garbage collector just for that? Why does it get slower over time? The only thing I know that gets slower over time without you doing anything special is my dad's mac os x word-only macbook pro.
Re:Fast JVM launching without the hassle of persistent JVMs by yason on Saturday November 17, 2012 @10:48AM (#4798287)
Hasn't anyone ported zygote over to desktop Linux/Windows? You just keep the preconfigured jvm process running and fork it indefinitely for each new process. You'd still suffer some overhead depending on each application but that's just expected anyway. The jvm startup overhead isn't.
Re:Fast JVM launching without the hassle of persistent JVMs by ansible on Saturday November 17, 2012 @11:34AM (#4798406)
The Dalvik VM does run on x86 now...

You'd just need to convert all your .jars and that's it. I haven't heard of any other incompatibilities with standard Java.

Edit: Is there a port of Dalvik to amd64? A cursory search did not find one.

Re:Fast JVM launching without the hassle of persistent JVMs by eropple on Saturday November 17, 2012 @04:33PM (#4799063)
I don't know if such a port exists, but I do know that I wouldn't want one. Dalvik's performance characteristics are scary-bad and there are plenty of incompatibilities with Java libraries that do any sort of weaving or code generation (so you still can't use Groovy, Rhino, etc.).
Re:Fast JVM launching without the hassle of persistent JVMs by ansible on Monday November 19, 2012 @10:17AM (#4804660)
... and there are plenty of incompatibilities with Java libraries that do any sort of weaving or code generation ...

Ah, good to know. I've mostly just had to bring in things like a database library, and in one case LuaJ. None of those did need to do bytecode generation.

Re:Fast JVM launching without the hassle of persistent JVMs by eropple on Friday November 23, 2012 @11:45PM (#4824563)
Yeah, for that you'll be fine, but take Rhino for example - Rhino offers, through LiveConnect, the ability to create JavaScript objects, at runtime, that satisfy Java interfaces. Which is cool, and useful for a lot of stuff. But the version of Rhino you can use on Dalvik has all of the bytecode generation disabled (obviously) and as a consequence, it can't emit the necessary bytecode to create the interface-fulfilling Java wrapper to make the JS object do what you want. It's generally bogus.

Also it's really hard to express how much slower Dalvik is than HotSpot in the general case, too. It seems faster with the Android 4.2 version (by about 30%, in my highly unofficial testing) but it's still pretty agonizingly slow.

Re:Fast JVM launching without the hassle of persistent JVMs by bdonlan on Saturday November 17, 2012 @04:42PM (#4799078)
forking tends not to work very well if you're running multiple threads, as Java tends to do.
Re:Fast JVM launching without the hassle of persistent JVMs by sandGorgon on Saturday November 17, 2012 @09:10AM (#4798085)
time ./drip -jar /home/user/research/jruby-complete-1.6.0.RC3.jar --1.9 -e 'a=1;puts a' 1 ./drip -jar /home/user/research/jruby-complete-1.6.0.RC3.jar --1.9 -e 0.03s user 0.03s system 4% cpu 1.282 total

time java -jar /home/user/research/jruby-complete-1.6.0.RC3.jar --1.9 -e 'a=1;puts a' 1 java -jar /home/user/research/jruby-complete-1.6.0.RC3.jar --1.9 -e 3.65s user 0.12s system 183% cpu 2.056 total

Interesting!! if it runs rails effectively, this could be awesome for jruby.

Re:Fast JVM launching without the hassle of persistent JVMs by riffraff on Saturday November 17, 2012 @09:50AM (#4798168)
I wonder, have you tried `-noverify`and `-client` ? (I am not sure if `-noverify` is compatible with jruby but I seem to remember so)
Re:Fast JVM launching without the hassle of persistent JVMs by mickeyben on Saturday November 17, 2012 @09:16AM (#4798101)
exactly what I was thinking!

I recently moved one of my project to jruby and the startup time is the only thing I'm complaining about.

Re:Fast JVM launching without the hassle of persistent JVMs by tlogan on Saturday November 17, 2012 @04:37PM (#4799069)
Was anybody able to run jruby on rails with drip?
Re:Fast JVM launching without the hassle of persistent JVMs by dcolgan on Saturday November 17, 2012 @09:57AM (#4798187)
This seems like a really clever solution. I remember trying to set up nailgun a while ago back when I was experimenting with Clojure because the startup time for running a program was so long, but I could never quite get it to work. I missed being able to run python myprog.py and getting instant feedback.
Re:Fast JVM launching without the hassle of persistent JVMs by briggers on Saturday November 17, 2012 @12:03PM (#4798470)
Persevere! Dynamic programming is wonderful.

I prefer swank over nailgun, even with Vim.

Re:Fast JVM launching without the hassle of persistent JVMs by zmmmmm on Saturday November 17, 2012 @06:41PM (#4799337)
> It keeps a fresh JVM spun up in reserve with the correct classpath and other JVM options so you can quickly connect and use it when needed

So I assume it doesn't help if you are launching JVMs very rapidly (like, scripting stuff in a tight loop). Slow JVM launching has pretty much killed languages such as Groovy for scripting for me, because once I start using them in loops things get horribly slow.

Re:Fast JVM launching without the hassle of persistent JVMs by jrockway on Saturday November 17, 2012 @09:10PM (#4799611)
Why not move the loop to your script?
Re:Fast JVM launching without the hassle of persistent JVMs by thomaslee on Saturday November 17, 2012 @10:06PM (#4799692)
Because unix? :)
Re:Fast JVM launching without the hassle of persistent JVMs by pretoriusB on Sunday November 18, 2012 @05:00AM (#4800313)
The Unix philosophy has nothing to do with this.

It's not like the stuff inside the script can't be standalone classes of the "do one thing and do it well" variety --they just don't get to be processes.

Re:Fast JVM launching without the hassle of persistent JVMs by mercurial on Sunday November 18, 2012 @10:05AM (#4800667)
On the other hand, you may not want to reimplement sed, grep, etc in your scripting language of choice. There are times where a good "perl -e" can be very useful in a shell script.
Re:Fast JVM launching without the hassle of persistent JVMs by isbadawi on Saturday November 17, 2012 @06:24PM (#4799303)
Re:Fast JVM launching without the hassle of persistent JVMs by georgeorwell on Saturday November 17, 2012 @05:29PM (#4799161)
As a further optimization, why not memcpy an uncorrupted JVM to some backup place in memory and then when you want to 'reboot' just memcpy the image back again?
Re:Fast JVM launching without the hassle of persistent JVMs by olaf on Saturday November 17, 2012 @11:30AM (#4798396)
My experiences with drip were very mixed (on Ubuntu 10.04), it did not make a stable, reliable impression on me. I wouldn't recommend it for professional use.
Re:Fast JVM launching without the hassle of persistent JVMs by ninjudd on Saturday November 17, 2012 @12:06PM (#4798478)
I'd be interested in what issues you've had. Did you open Github issues for them? Thanks
Re:Fast JVM launching without the hassle of persistent JVMs by olaf on Saturday November 17, 2012 @01:49PM (#4798730)
A github issue (#34) was opened, and you released a changed version soon after, but it remained unusable for me (in the meantime I upgraded to 12.04 and did not test drip since then).
Re:Fast JVM launching without the hassle of persistent JVMs by pbiggar on Saturday November 17, 2012 @11:37AM (#4798411)
Does anyone know how to use with with lein?
Re:Fast JVM launching without the hassle of persistent JVMs by aaroniba on Saturday November 17, 2012 @09:31PM (#4799645)
It looks like drip does not automatically work with lein:

https://github.com/flatland/drip/issues/36

Here's my workaround to use drip to start up lein repls instantly:

https://gist.github.com/4103370

Should work with lein1 & lein2.

Re:Fast JVM launching without the hassle of persistent JVMs by welp on Saturday November 17, 2012 @11:55AM (#4798456)
Using lein2, you can run the following:

  $ JAVA_CMD=drip lein ...
Re:Fast JVM launching without the hassle of persistent JVMs by airlocksoftware on Saturday November 17, 2012 @01:46PM (#4798725)
What does this do exactly? Will it permanently change lein to use drip? Or only temporarily for whichever command replaced the "...". Also, do you know if the advice here: https://github.com/flatland/drip/wiki/Clojure works with lein2?
Re:Fast JVM launching without the hassle of persistent JVMs by mcav on Saturday November 17, 2012 @02:03PM (#4798766)
That command runs drip only for that particular invocation of the command. You can put the following:

    export JAVA_CMD=drip
into your ~/.profile (etc) file to have it affect all future Java launches from leiningen.
Re:Fast JVM launching without the hassle of persistent JVMs by pbiggar on Saturday November 17, 2012 @12:16PM (#4798503)
Still using lein1 :(
Re:Fast JVM launching without the hassle of persistent JVMs by azth on Sunday November 18, 2012 @08:09AM (#4800526)
> The main problem is that the state of the persistent JVM gets dirty over time, producing strange errors...

Does anyone know what kind of errors the author is referring to? Does any long running JVM instance run into these issues?

Re:Fast JVM launching without the hassle of persistent JVMs by wiradikusuma on Saturday November 17, 2012 @10:19AM (#4798232)
Sweet! I immediately updated runner script for Scala and Groovy to use it!

EDIT: Hmm, I encountered this: "Could not connect to compilation daemon after 300 attempts." but re-running it ("scala") works.

Re:Fast JVM launching without the hassle of persistent JVMs by pjmlp on Saturday November 17, 2012 @10:03AM (#4798202)
What about just using AOT compilation?
Re:Fast JVM launching without the hassle of persistent JVMs by gtrak on Saturday November 17, 2012 @10:27AM (#4798244)
JVM startup overhead, not clojure runtime overhead. That's still there.
Re:Fast JVM launching without the hassle of persistent JVMs by pjmlp on Saturday November 17, 2012 @10:44AM (#4798277)
What startup overhead?

I meant AOT to native code.

Re:Fast JVM launching without the hassle of persistent JVMs by MichaelGG on Saturday November 17, 2012 @04:37PM (#4799068)
AOT to Native code just removes the JIT time. Any overhead of actually running the Java runtime and running initialization code is still there.
Re:Fast JVM launching without the hassle of persistent JVMs by gtrak on Tuesday November 20, 2012 @05:43PM (#4811775)
AOT already means something to clojurists. It means removing the extra runtime compilation phase of .clj into classfiles. The JIT is what the JVM does, which still occurs just like before.
Re:Fast JVM launching without the hassle of persistent JVMs by pjmlp on Wednesday November 21, 2012 @07:58AM (#4814040)
Unless the bytecode gets translated to native code ahead of time (AOT).

Although OpenJDK/Oracle JVM don't offer this option, other vendors do.

Re:Fast JVM launching without the hassle of persistent JVMs by pjmlp on Sunday November 18, 2012 @01:12AM (#4800022)
What?!
Re:Fast JVM launching without the hassle of persistent JVMs by bickfordb on Saturday November 17, 2012 @12:36PM (#4798548)
Most of the Clojure app startup time (~1.2s on my machine) is the Clojure runtime, not the JVM (usually less than 100ms).
Re:Fast JVM launching without the hassle of persistent JVMs by z3phyr on Saturday November 17, 2012 @09:37AM (#4798141)
Happier Clojure hacking days ahead :)