Friday, May 30, 2008

Loss of internet connection...

When you have to write something like this (on mac), things are bad mmmmkay?

[sourcecode language="ruby"]
loop do
if system('curl -m 2')
system("say \"Mike! Cox Communications has finally fixed the lines, we're back in business!\"")

Tuesday, May 27, 2008

Syntactic Sugar...

Was reading this post about Groovy syntactic sugar... closures and ++ operator are nice... but you could open up Hash and Array to get the other stuff.

[sourcecode language="ruby"]
# working with hashes
class Hash
def method_missing(name, *args)
fetch(name) if has_key?(name) or nil
user = {:save => true, :destroy => false}
puts "--hashes"
puts "save? : #{}"
puts "destroy? : #{user.destroy}"

# working with arrays
class Array
def method_missing(name, *args)
collect {|i| i.send(name)}
puts "--upcase"
puts ["Mike", "McKinney"].upcase

# fetching attributes of arrays
name1 = {:first_name => "Mike", :last_name => "McKinney"}
name2 = {:first_name => "Bo", :last_name => "Diddley"}
names = [name1, name2]

puts "--first names "
puts names.first_name
puts "--last names "
puts names.last_name
puts "--middle names "
puts names.middle_name

Of course you would want to look a little closer at the implications this type of patch would have on your code, but it's sure nice how flexible ruby can be.

Tuesday, May 13, 2008

JavaOne '08 - Script Bowl apps for JRuby released

This year's JavaOne had an interesting competition... the Script Bowl.  Pitting 4 different languages (Groovy, Scala, Jython & JRuby) on the JVM against each other in three different categories.  (Rich Client Application, Web Application and an Open event)  Check the results here on Rags' blog.

Headius just posted the JRuby Script Bowl artifacts for your viewing pleasure.  Anyone know if the other languages have posted their apps/code?

Monday, May 5, 2008

Re: RSS Feeds for Subversion

I was reading a friend's blog post about RSS feeds for Subversion repositories earlier... he couldn't find anything that was not written in a scripting language which he has no access to in his environment... he needed a Java based solution.  He solved his problem with a war.  I came back to this after dinner (and a few glasses of wine) and decided to show him another way to solve this problem on the JVM... (you knew it was coming Matt.)

Assuming you already have JRuby setup (of course you do), we'll do the following to get the one gem we'll need:
[sourcecode language="css"]
> jruby -S gem install rscm

The RSCM (Ruby Source Code Management) gem provides a nice interface to SVN, CVS, ClearCase, StarTeam, etc. and since it's written in pure Ruby, it runs just fine on the JVM.

Then download this file. Not much to it, 106 lines and 45 of that is the template for creating the rss xml doc.

Command line has a few options, here's an example:
[sourcecode language="css"]
> jruby -J-server server.rb -p 8080 -m svnlog
or just get help
> jruby server --help

-p, --port=3003 Which port do you want the server to listen on.
-m, --mount-point=svnrss http:///
-h, --help Show help (this).

Point your RSS reader @ the following: http://localhost:8080/svnlog?url= and here's what you get:


(Firefox 3 beta)

Nice, think I'll actually use this.

Thursday, May 1, 2008

Some Rails perf numbers on JRuby 1.1.1 part 2 (Linux, JDK 6)

After this post, I got a lot of suggestions to re-run the benchmarks using JDK 6. I'll let you read the previous post to see what exactly I did... here's what the runtime looks like for this run:

  • Ubuntu 7.10 / Dell Latitude D830

  • Ruby 1.8.6

  • JRuby 1.1.1

  • JDK 1.6.0_03

*NOTE: could not run benchmarks without jdbc drivers (jdbcmysql adapter) due to JRUBY-2303

First the Rails console benchmark numbers:

Rails console numbers

[sourcecode language="css"]
5.15 seconds - Ruby console
2.41 seconds - JRuby console (jdbc)

(side-note: re-running the console test with JDK 5 on same machine, best out of 6 runs: 3.31 seconds)

Next the Web Server numbers: (numbers in parens are the number of benchmark runs)

Rails ab numbers

[sourcecode language="css"]
272.84 Mongrel (6)
257.02 GlassFish (40)
235.17 Mongrel (jruby/jdbc) (20)
188.12 Glassfish (-n 2, 20)
179.76 Mongrel (jruby/jdbc) (10)
168.52 Glassfish (6)
161.12 Mongrel (jruby/jdbc) (6)
151.04 Glassfish (-n 2, 6)
131.89 Tomcat 6 (30)
105.72 Tomcat 6 (6)

The console numbers show JDK 6 really kicking in... contrast that with the numbers for actually serving the Rails app and you can see there is still some work to be done to make Ruby on Rails serve faster on the JVM.

Again, not very scientific, just something to show where things stand for now. If you have better benchmarks, please link to them from the comments section below.