Saturday, September 8, 2007

The Future of Ruby is JRuby?




While fighting with ActiveRecord-JDBC (I thought Derby was built in JDK 1.6, but I still have to copy the derby .jar's into jruby/lib ???) this morning I ran across Ola Bini'a Blog and an a great prezo on JRuby. If you read between the lines (I obviously didn't see/hear the prezo) but Ola seems to be suggesting the future of Ruby is indeed JRuby. Slide after slide there are aspects of C-Ruby that are broken (and will not be fixed in 1.9) but where Java is superior : GC, performance (maybe), multi-core, internationalization, etc.

Monday, September 3, 2007

Ruby Only Netbeans Builds: Nothing to Be Angry About


I've never used IDEs that much (with the exception of Visual C# a while back} but I downloaded the latest build of the the Netbeans Ruby IDE. and it was amazing how fast it loaded without all that useless Java crap that causes the progress bar to take soooo long on the full-featured Netbeans 6.0 preview releases.

Sunday, September 2, 2007

Absolutely Worthless JRoR Benchmark: Tomcat 5.5 vs. Glassfish v3

So for grins (not worth much else, was looking for something to pass the time before my kids went to sleep) I decided to compare initial page load times for the hello world between Tomcat and Glassfishv3 using the Arun Gupta's tutorial app

Tomcat 5.5.23
Initial Load: 3.229s
Subsequent Loads: 0.115 0.323 0.323s

Glassfish v3
Inital Load: 9.671s
Subsequent Loads: 3.005 0.554 0.594s

Webrick
Initial Load: 1.278s
Subsequent Loads: 0.559s 0.623

For Webrick is the time to boot it was about 3-4 times as long as it took to start Tomcat and deploy app through the manager (no more than 10 seconds) but for Glassfish, deployments took anywhere from 29-52 seconds.

Not like it really matters, but the hardware/software: VMWare Debian 4.0 JRE1.6 running on aging AMD K7-1.5 with 1.2GB RAM.


franz-g4:~ mdfranz$ time wget http://192.168.100.91:8080/hello/say/hello
--19:30:56-- http://192.168.100.91:8080/hello/say/hello
=> `hello.4'
Connecting to 192.168.100.91:8080... connected.
HTTP request sent, awaiting response... 200 OK
Length: 86 [text/html]

19:30:59 (1.61 MB/s) - `hello.4' saved [86/86]


real 0m3.229s
user 0m0.002s
sys 0m0.009s

JRuby and Embedded Derby: First Steps

Before tackling ActiveRecord-JDBC I thought I'd play around with the embedded version of Apache Derby with JRuby. This actually took me a lot longer that it should of, mostly because its been months since I've done anything with JRuby and years since I've touched JDBC. But here are the basic steps, which probably aren't that much difference from any other JDBC in JRuby:

require 'java'
include_class "java.sql.Connection"
include_class "java.sql.DriverManager"
include_class "java.sql.ResultSet"
include_class "java.sql.Statement"
driver = org.apache.derby.jdbc.EmbeddedDriver.new()
conn = DriverManager.getConnection("jdbc:derby:derbyDB;create=true")
conn.setAutoCommit(false)
s = conn.createStatement()

Some of the things that tripped me up, as I was trying to convert the simple Java example to JRuby:
  • The Class.forName(driver).newInstance() nonsense, I guess I've never run across this convention before but probably not surprising since I'm not a Java developer
  • org.apache.derby.impl.jdbc.EmbedSQLException: Derby system shutdown - yes you should do a DriverManager.getConnection("jdbc:derby:;shutdown=true") and yes it apparently always throws an exception
  • Getting useful results sets back is where I spent most of my time. Fortunately Derby documentation (like most Apache projects) are among of the best of any, whether commercial or Open Source APIs.

Since Blogger mangles source code so badly, see the code over on my wiki. Next I'm going to try HSQLDB because it supports a larger set of rails migrations using ActiveRecord-JDBC than Derby, but the Hypersonic gem definitely had problems on OSX due to issues with YAJB. But me sneaking suspicions is that that library is for C-Ruby and not JRuby. Doh!